void read_file(std::string input1,std::string input2,std::string input3){ std::ifstream ifs1(input1.c_str()); std::ifstream ifs2(input2.c_str()); std::ifstream ifs3(input3.c_str()); float label1; ifs1 >> input1; ifs1 >> label1; ifs1 >> label1; ifs2 >> input2; ifs2 >> label1; ifs2 >> label1; ifs3 >> input3; ifs3 >> label1; ifs3 >> label1; int num=0; int pos[3]={0}; int neg[3]={0}; int other; float label2,label3; while(!ifs1.eof()){ ifs1 >> label1; ifs2 >> label2; ifs3 >> label3; ifs1 >> label1; ifs2 >> label2; ifs3 >> label3; if(label1 < OTHER && label2 < OTHER && label3 <OTHER) other++; if(label1>label2){ if(label1>label3) pos[0]++; else pos[2]++; } else if(label1<label2){ if(label2>label3) pos[1]++; else pos[2]++; } ifs1 >> label1; ifs2 >> label2; ifs3 >> label3; num++; } for(int i=1;i<=3;i++){ std::cout << i << ":" << (float)pos[i-1]/num*100 << " "; } std::cout << other << ":" <<(float)other/num*100 << " "; std::cout << "\n"; }
int UHD_SAFE_MAIN(int argc, char *argv[]){ //Seting priority in the processor to run faster -> run with sudo if (uhd::set_thread_priority_safe(1,true)) { std::cout << "set priority went well " << std::endl; }; //variables to be set by po -> Set when initializing the tx program std::string args; double seconds_in_future; size_t total_num_samps; double tx_rate, freq, LOoffset; float gain; bool forever, use_8bits; bool use_external_10MHz, trigger_with_pps; bool readFile; std::string filename; uhd::tx_streamer::sptr tx_stream; uhd::device_addr_t dev_addr; uhd::usrp::multi_usrp::sptr dev; uhd::stream_args_t stream_args; //setup the program options -> Passing it from terminal with boost library po::options_description desc("Allowed options"); desc.add_options() ("help", "help message") ("args", po::value<std::string>(&args)->default_value(""), "simple uhd device address args") ("secs", po::value<double>(&seconds_in_future)->default_value(3), "number of seconds in the future to transmit") ("nsamps", po::value<size_t>(&total_num_samps)->default_value(1000), "total number of samples to transmit") ("txrate", po::value<double>(&tx_rate)->default_value(100e6/16), "rate of outgoing samples") ("freq", po::value<double>(&freq)->default_value(0), "rf center frequency in Hz") ("LOoffset", po::value<double>(&LOoffset)->default_value(0), "Offset between main LO and center frequency") ("forever",po::value<bool>(&forever)->default_value(false), "run indefinetly") ("10MHz",po::value<bool>(&use_external_10MHz)->default_value(false), "external 10MHz on 'REF CLOCK' connector (true=1=yes)") ("PPS",po::value<bool>(&trigger_with_pps)->default_value(false), "trigger reception with 'PPS IN' connector (true=1=yes)") ("filename",po::value<std::string>(&filename)->default_value("data_to_usrp.dat"), "input filename") ("gain",po::value<float>(&gain)->default_value(0), "gain of transmitter") ("8bits",po::value<bool>(&use_8bits)->default_value(false), "Use eight bits/sample to increase bandwidth") //////////////////////////////// ("readFile",po::value<bool>(&readFile)->default_value(false), "defines if program reads data from file or generate data itself") ; //Variables stored in boost objects po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); //print the help message if (vm.count("help")){ std::cout << boost::format("tx %s") % desc << std::endl; return ~0; } //////// Create buffer storage to pass to USRP -> complex short always std::complex<short> *buffer; buffer = new std::complex<short>[total_num_samps]; ////////////////// Create data to be transmitted /////////////////////// if(readFile==true){ /* Read input from disc -> data previous generated by MATLAB*/ /* FILE *fp = 0; fp = fopen(filename.c_str(), "rb"); if (fp == 0){ perror(filename.c_str()); return 1; } int r=fread(buffer, sizeof(uint32_t),total_num_samps, fp); printf("r=%d \n",r); fclose(fp); */ // Read data from file std::ifstream ifs3( "sent.dat" , std::ifstream::in ); ifs3.read((char * )buffer,total_num_samps*sizeof(short)); ifs3.close(); printf("USING MATLAB DATA!\n"); }else{ /*Creates data to be transmitted->Call functions to generate data*/ //Process data in double or complex<double> //Continuous waveform test: double amp=5000; double cw_freq=3e6; double *seq; seq = new double[2*total_num_samps+1]; create_data_CW ( seq, 2*total_num_samps, cw_freq/tx_rate, amp ); complex<double> * seq_c=(complex<double> *) seq; //Test casting when necessary: //for(int ii=0;ii<12;ii++){ // std::cout << seq[ii]/amp<< "->value \n"; // }; //std::cout << "\n casting \n"; //ATENTION:Always convert to complex<short> to send to the USRP transmitter compDoubleToCompShort(seq_c, total_num_samps, buffer); FILE * xFile; xFile = fopen("sent2.bin","wb"); fwrite(buffer, 2*sizeof(short),total_num_samps/2,xFile); fclose(xFile); printf("USING CPP IMPLEMENTATION!\n"); }; ///////////////////////////////////////////////////////////////////////// //create a USRP device and streamer dev_addr["addr0"]="192.168.10.2"; dev = uhd::usrp::multi_usrp::make(dev_addr); ///////////// Internal variables of USRP (Not important now, set as default) uhd::clock_config_t my_clock_config; if (!forever) { //my_clock_config.ref_source=uhd::clock_config_t::REF_SMA; dev->set_time_source("external"); }; if (use_external_10MHz) { //my_clock_config.pps_source=uhd::clock_config_t::PPS_SMA; dev->set_clock_source("external"); } else { //my_clock_config.pps_source=uhd::clock_config_t::PPS_SMA; dev->set_clock_source("internal"); }; //dev->set_tx_bandwidth(36e6); std::cout << "freq=" << freq << "\n"; std::cout << "LOoffset=" << LOoffset << "\n"; uhd::tune_result_t tr; uhd::tune_request_t trq(freq,LOoffset); //std::min(tx_rate,10e6)); tr=dev->set_tx_freq(trq,0); bool is_xcvr2450=false; uhd::dict<std::string, std::string> tx_info; tx_info=dev->get_usrp_tx_info(0); if (tx_info.has_key("tx_subdev_name")) { std::string str=tx_info.get("tx_subdev_name"); uint temp=str.find("XCVR2450"); if (temp<str.length()) { is_xcvr2450=true; }; }; if (is_xcvr2450) { dev->set_tx_antenna("J2"); dev->set_rx_antenna("J1"); //uhd::meta_range_t range=dev->get_tx_bandwidth_range(); if (abs(LOoffset)>=6e6) { //dev->set_tx_bandwidth(28e6); dev->set_tx_bandwidth(3.96e+07); }; }; dev->set_tx_gain(gain); std::cout << tr.to_pp_string() << "\n"; //dev->set_clock_config(my_clock_config); // PZ stream_args.cpu_format="sc16"; if (use_8bits) stream_args.otw_format="sc8"; else stream_args.otw_format="sc16"; tx_stream=dev->get_tx_stream(stream_args); //set properties on the device std::cout << boost::format("Setting TX Rate: %f Msps...") % (tx_rate/1e6) << std::endl; dev->set_tx_rate(tx_rate); std::cout << boost::format("Actual TX Rate: %f Msps...") % (dev->get_tx_rate()/1e6) << std::endl; std::cout << boost::format("Setting device timestamp to 0...") << std::endl; //Check what is being sent // for(int ii=0;ii<11;ii++){ // std::cout << real(buffer[ii])<< "->value \n"; // std::cout << imag(buffer[ii])<< "->value\n \n"; // }; ///////////////Transmission of data/////////////////////////////////// /*----> send data in loop ----> send data once and let receiver handle it */ uhd::tx_metadata_t md; if (forever) { std::cout << "Stop the transmitter by pressing ctrl-c \n"; md.start_of_burst = true; md.end_of_burst = false; md.has_time_spec = false; //send the entire buffer, let the driver handle fragmentation /* num_tx_samps = dev->send( buffer, total_num_samps, md, uhd::io_type_t::COMPLEX_INT16, uhd::device::SEND_MODE_FULL_BUFF); */ tx_stream->send(buffer,total_num_samps,md,60); md.start_of_burst = false; while (1) { /* num_tx_samps = dev->send( buffer, total_num_samps, md, uhd::io_type_t::COMPLEX_INT16, uhd::device::SEND_MODE_FULL_BUFF ); */ tx_stream->send(buffer,total_num_samps,md,3); md.start_of_burst = false; md.end_of_burst = false; md.has_time_spec = false; std::cout << "Sending data in loop... \n"; } } else { //Transmit data once and let receiver handle it dev->set_time_now(uhd::time_spec_t(0.0)); md.start_of_burst = true; md.end_of_burst = true; md.has_time_spec = true; md.time_spec = uhd::time_spec_t(seconds_in_future); //send the entire buffer, let the driver handle fragmentation /* num_tx_samps = dev->send( buffer, total_num_samps, md, //&buff.front(), buff.size(), md, uhd::io_type_t::COMPLEX_FLOAT32, uhd::device::SEND_MODE_FULL_BUFF); */ tx_stream->send(buffer,total_num_samps,md,60); std::cout << "\nData only sent once \n"; }; //finished std::cout << std::endl << "Done! Transmission completed" << std::endl << std::endl; return 0; }
int main() { ColoredGraph<GraphVertex,TriColor> gr; set<GraphVertex,less<GraphVertex> > groupsall, filesall,functionsall; set<GraphVertex,less<GraphVertex> > groupssome, filessome,functionssome,S; set<GraphVertex,less<GraphVertex> > groupsnot, filesnot,functionsnot; ifstream ifs1("groups.txt"); ifstream ifs2("files.txt"); ifstream ifs3("files.txt"); ifstream ifs4("choices.txt"); cerr << "reading groups"; readDoubleColumnGraph(ifs1,groupsall,gr,true); cerr << ", files"; readDoubleColumnGraph(ifs2,filesall,gr,true); cerr << ", functions\n"; readDoubleColumnGraph(ifs3,functionsall,gr,false); readSingleColumn(ifs4,gr); #if 1 ifstream ifs5("depends.txt"); list<list<string> > dbllist; readMultiColumns(ifs5,dbllist); #endif bool todo = true; while(todo) { todo = false; gr.ColorChildComponents(TriColor::s_one,TriColor::s_two); list<GraphVertex> L(gr.getColored(TriColor::s_two)); copy(L.begin(),L.end(),inserter(S,S.begin())); #if 1 todo = addElements(gr,TriColor::s_one,S,dbllist); cerr << "addelements give " << todo << '\n'; #endif }; cerr << "Here is the set after the loop:\n"; printset(cerr,S,","); set_intersection(S.begin(),S.end(),groupsall.begin(),groupsall.end(), inserter(groupssome,groupssome.begin())); set_intersection(S.begin(),S.end(),filesall.begin(),filesall.end(), inserter(filessome,filessome.begin())); set_intersection(functionsall.begin(),functionsall.end(),S.begin(),S.end(), inserter(functionssome,functionssome.begin())); set_difference(groupsall.begin(),groupsall.end(),S.begin(),S.end(), inserter(groupsnot,groupsnot.begin())); set_difference(filesall.begin(),filesall.end(),S.begin(),S.end(), inserter(filesnot,filesnot.begin())); set_difference(functionsall.begin(),functionsall.end(),S.begin(),S.end(), inserter(functionsnot,functionsnot.begin())); cerr << "all groups:\n"; printset(cerr,groupsall,", "); cerr << "\nall files:\n"; printset(cerr,filesall,", "); cerr << "\nall functions:\n"; printset(cerr,functionsall,", "); cerr << "\n\n\n"; cerr << "groups (not):\n"; printset(cerr,groupsnot,", "); cerr << "\nfiles (not):\n"; printset(cerr,filesnot,", "); cerr << "\nfunctions(not):\n"; printset(cerr,functionsnot,", "); cerr << "\n\n\n"; cerr << "groups:\n"; printset(cerr,groupssome,", "); cerr << "\nfiles:\n"; printset(cerr,filessome,", "); cerr << "\nfunctions:\n"; printset(cerr,functionssome,", "); cerr << "Staring creation of the file Makefile.mark\n"; ofstream ofs("Makefile.mark"); ofs << "p9clist = "; printset(ofs,filessome,".o \\\n",".o \n"); ofs.close(); cerr << "Ended creation of the file Makefile.mark\n"; cerr << "Staring creation of the file Makefile.cp\n"; ofstream ofs2("Makefile.cp"); ofs2 << "cp "; printset(ofs2,filessome,".[hc]pp copyplace/ \n cp ",".[hc]pp copyplace/ \n"); ofs2.close(); cerr << "Ended creation of the file Makefile.cp\n"; };
void XMLScannerTest::run() { //create a dummy map with a fakie f*****g modulewhateverinfo.... std::vector<std::pair<std::string, std::string> > outs(1); std::vector<std::pair<std::string, std::string> > ins(0); std::pair<std::string, std::string> outpair("typ_string", "String"); outs[0] = outpair; //Xpm dummy(dummyXpm, strlen(dummyXpm)+1); ModuleInfo* mi = new ModuleInfo("mod_stringModule", "String", ins, outs, true); std::vector<std::pair<std::string, std::string> > outs2(0); std::vector<std::pair<std::string, std::string> > ins2(1); std::pair<std::string, std::string> inpair("typ_framebuffer", "Bild"); ins2[0] = inpair; ModuleInfo* mi2 = new ModuleInfo("mod_glOutputModule", "GLoutput" , ins, outs, false); std::vector<std::pair<std::string, std::string> > outs3(1); std::vector<std::pair<std::string, std::string> > ins3(3); std::pair<std::string, std::string> inpair2("typ_number","Zahl"); ins3[0] = inpair2; ins3[1] = inpair2; ins3[2] = inpair; outs3[0] = inpair; ModuleInfo* mi3 = new ModuleInfo("mod_tunnelModule", "Tunnel" , ins, outs, false); std::map<int, ModuleInfo*> mi_map; mi_map[0] = mi; mi_map[1] = mi2; mi_map[2] = mi3; //create storage room for the listener std::map<std::string, int> infos; std::map<std::string, std::pair<int,int> > nodes; std::map<int, std::string> nodeIDs; std::map<std::string, std::pair<int,int> > controls; std::map<int, std::string> controlIDs; std::map<std::pair<int,int>, std::pair<int,int> > conns; std::map<std::pair<int,int>, std::pair<int,int> > ctrlconns; //create an xmlListener with that dummyinfo XMLTokenListener horcher(mi_map, infos, nodes, nodeIDs, controls, controlIDs, conns, ctrlconns); XMLFileScanner gucker(horcher); std::ifstream ifs("testCorrect.graph"); if(ifs==0) std::cout<<"File not found \n"; std::string testTextCorrect; char tmp; while(ifs.get(tmp)) { testTextCorrect += tmp; } gucker.scan(testTextCorrect); //eine datei ohne <model> //std::cout<<"Processing incorrect file 1...\n"; std::ifstream ifs1("testInCorrect1.graph"); if(ifs1==0) std::cout<<"File not found \n"; std::string testTextInCorrect1; while(ifs.get(tmp)) { testTextInCorrect1 += tmp; } try { gucker.scan(testTextInCorrect1); } catch(std::runtime_error err) { //if(err.what() != "This is no Ge-Phex Graph file...go f**k your dog!!!") // throw std::runtime_error(err.what()); //std::cout<<err.what()<<std::endl; } //eine datei ohne </model>, ja, ich weiss, kreativ... //std::cout<<"Processing incorrect file 2...\n"; std::ifstream ifs2("testInCorrect2.graph"); if(ifs2==0) std::cout<<"File not found \n"; std::string testTextInCorrect2; while(ifs2.get(tmp)) { testTextInCorrect2 += tmp; } try { gucker.scan(testTextInCorrect2); } catch(std::runtime_error err) { //if(err.what() != "File has a wrong finishing tag...wrong format") // throw std::runtime_error(err.what()); //std::cout<<err.what()<<std::endl; } //eine datei mit fehlender node section //std::cout<<"Processing incorrect file 3...\n"; std::ifstream ifs3("testInCorrect3.graph"); if(ifs3==0) std::cout<<"File not found \n"; std::string testTextInCorrect3; while(ifs3.get(tmp)) { testTextInCorrect3 += tmp; } try { gucker.scan(testTextInCorrect3); } catch(std::runtime_error err) { //if(err.what() != "File has wrong format...section nodes") // throw std::runtime_error(err.what()); //std::cout<<err.what()<<std::endl; } }