/** * constructor * ConfigManager is a singleton and hence the constructor is protected. * @return ConfigManager: an instance of the ConfigManager * */ ConfigManager::ConfigManager(void) { mapConfig = new map<string, string>; configFile = "..\\Control\\config.dat"; // Fillup Map of Config values string line; ifstream iFile(configFile.c_str(),ios::in); mapConfig->clear(); if (iFile.is_open()) { while (! iFile.eof() ) { getline (iFile, line); size_t cutAt = 0; cutAt = line.find_first_of("="); if (cutAt < line.size()) mapConfig->insert(pair<string,string> (line.substr(0,cutAt), line.substr(cutAt+1))); } iFile.close(); } }
int main(int argc, char* argv[]) { if(argc != 4) { std::cout<<"ERROR: missing parameters."<<std::endl; system("PAUSE"); return 0; } gInputFile = std::string(argv[1]); gFontFile = std::string(argv[2]); gSize = atoi(argv[3]); SDL_Init(SDL_INIT_EVERYTHING); TTF_Init(); pFont = LoadFont(gFontFile,gSize); std::string line; std::ifstream iFile (gInputFile); if (iFile.is_open()) { while ( getline (iFile,line) ) { SDL_Surface *pSurface = GetSurface(line); SDL_SaveBMP(pSurface,(std::string(line)+".bmp").c_str()); SDL_FreeSurface(pSurface); } iFile.close(); } TTF_CloseFont(pFont); return 0; }
bool MainWindow::checkUserGroup() { QString loginName = getlogin(); QString groupName = "wheel"; // group to check QStringList gNames; if ( loginName == "root" ) return true; QString tmp; QFile iFile("/etc/group"); if ( ! iFile.open(QIODevice::ReadOnly | QIODevice::Text)) return true; //or FALSE? while ( !iFile.atEnd() ) { tmp = iFile.readLine().simplified(); if ( tmp.indexOf(groupName) == 0 ) { gNames = tmp.section(":", 3, 3).split(","); break; } } iFile.close(); if ( gNames.isEmpty() ) return false; for ( int i = 0; i < gNames.size(); ++i ) if ( gNames.at(i).indexOf(loginName) == 0 ) return true; return false; }
int main() { std::cout << std::fixed << std::setprecision(2); std::string str; std::shared_ptr<CCalculator> calc = std::make_shared<CCalculator>(); CParser parser(calc); std::ifstream iFile("code.txt"); if (iFile.is_open()) { while (getline(iFile, str) && !str.empty()) { std::cout << str << std::endl; parser.ProcessCode(str); } } while (getline(std::cin, str) && !str.empty()) { parser.ProcessCode(str); } return EXIT_SUCCESS; }
void CompressionProgram::createCompressedFile(string codefile, string &ptrF, vector<vector<bool> > table, vector<int> symbolRating) { ifstream iFile(ptrF.c_str(), ios::binary); // Open the file for reading ofstream oFile(codefile.c_str(), ios::binary); // Open the file for writing setlocale(LC_ALL, "Russian"); // understand the Cyrillic int tableSize = (int) symbolRating.size(); oFile.write((char *) &tableSize, sizeof(tableSize)); for (int j = 0; j < tableSize; ++j) { oFile.write((char *) &symbolRating[j], sizeof(symbolRating[j])); } int count = 0; unsigned char buf; while (!iFile.eof()) { unsigned char ch = iFile.get(); vector<bool> tmp = table[ch]; // Put in a vector is considered a symbol code for (int i = 0; i < tmp.size(); i++) { buf = buf | tmp[i] << (7 - count); count++; if (count == 8) { count = 0; oFile << buf; buf = 0; } } } oFile.close(); // Close the file that is writing iFile.close(); // Close the file that is read }
int main() { CGAL::Geomview_stream gv(CGAL::Bbox_3(-100, -100, -100, 600, 600, 600)); gv.set_line_width(4); // gv.set_trace(true); gv.set_bg_color(CGAL::Color(0, 200, 200)); // gv.clear(); Delaunay D; Delaunay3d D3d; Terrain T; std::ifstream iFile("data/points3", std::ios::in); Point3 p; while ( iFile >> p ) { D.insert( Point2(p.x(), p.y()) ); D3d.insert( p ); T.insert( p ); } // use different colors, and put a few sleeps/clear. gv << CGAL::BLUE; std::cout << "Drawing 2D Delaunay triangulation in wired mode.\n"; gv.set_wired(true); gv << D; #if 1 // It's too slow ! Needs to use OFF for that. gv << CGAL::RED; std::cout << "Drawing its Voronoi diagram.\n"; gv.set_wired(true); D.draw_dual(gv); #endif sleep(5); gv.clear(); std::cout << "Drawing 2D Delaunay triangulation in non-wired mode.\n"; gv.set_wired(false); gv << D; sleep(5); gv.clear(); std::cout << "Drawing 3D Delaunay triangulation in wired mode.\n"; gv.set_wired(true); gv << D3d; sleep(5); gv.clear(); std::cout << "Drawing 3D Delaunay triangulation in non-wired mode.\n"; gv.set_wired(false); gv << D3d; sleep(5); gv.clear(); std::cout << "Drawing Terrain in wired mode.\n"; gv.set_wired(true); gv << T; sleep(5); gv.clear(); std::cout << "Drawing Terrain in non-wired mode.\n"; gv.set_wired(false); gv << T; std::cout << "Enter a key to finish" << std::endl; char ch; //std::cin >> ch; std::cin.get(); return 0; }
int main(int argc, const char * argv[]) { if(argc<2){ show_usage(); cerr << "not enought parameters!" << endl; exit(1); } clock_t curr_time; curr_time = clock(); // read from file Trie* trie = new Trie(); cout << "Read from File" << endl; string path = argv[1]; ifstream iFile(path); if(!iFile) { cerr << "unable to open file" << endl; exit(1); } string line; while (getline(iFile, line)) { if (!line.empty() && line[line.size() - 1] == '\r') line.erase(line.size() - 1); trie->addWord(line); } curr_time = clock() - curr_time; cout << "Read File and Build Trie Done! Time: " << ((float)curr_time)/CLOCKS_PER_SEC << " seconds" << endl; // sortedSet stores all the compound words in decresing order in terms of string length set<string, cmpStruct> sortedSet; while(!trie->suffix_queue.empty()) { StringPair sp = trie->suffix_queue.front(); trie->suffix_queue.pop(); if(trie->searchWord(sp.first, sp.second)) { sortedSet.insert(sp.first); } } curr_time = clock() - curr_time; cout << "Search For Compound Words Done! Time: " << ((float)curr_time)/CLOCKS_PER_SEC << " seconds" << endl; std::set<string>::iterator it; int i = 0; for (it = sortedSet.begin(); i < 2 && it != sortedSet.end(); ++it, ++i) cout << "The " << i+1 << " Longest Compound Word:" << *it << endl; cout << "Number of Total Compound Words: " << sortedSet.size() << endl; //write all compound words to file std::ofstream out("compoundWords.txt"); for (it = sortedSet.begin(); it != sortedSet.end(); ++it) { out << *it << endl; } out.close(); delete trie; return 0; }
KMeans::KMeans(unsigned int dim, unsigned int k, std::string filename, unsigned int maxIter) : __dimensionality(dim), __k(k), __iFileName(filename), __maxIter(maxIter) { if (k == 0) throw ZeroClustersEx(); std::ifstream iFile(filename.c_str()); if (iFile.fail()) throw DataFileOpenEx(filename); iFile.close(); }
int main(int argc, char* argv[]) { cout.setf(ios::left, ios::adjustfield); cout.precision(OUTPUT_PRECISION); string iFile("optimized"); // Default input VTK filename string oFile("cartesian"); // Default output VTK filename // Parse command line int i = 1; while (i < argc) { if (!strcmp("-if", argv[i])) iFile.assign(argv[i + 1]); else if (!strcmp("-of", argv[i])) oFile.assign(argv[i + 1]); else { cout << "Unrecognized command line argument: " << argv[i] << endl; cout << endl; cout << "Supported options [defaults in square brackets]:" << endl; cout << endl; cout << "Input filename: -if [\"" << iFile << "\"]" << endl; cout << "Output filename: -of [\"" << oFile << "\"]" << endl; cout << flush; exit(1); } i += 2; } // Initialize lattice TP2CLattice lattice; // Load initial data cout << "Reading input file \"" << iFile << ".vtk\"" << endl << flush; string title = ""; lattice.read_vtk(iFile + ".vtk", title); cout << "Done loading." << endl << flush; cout << "nSide: " << lattice.get_nSide() << endl; // Create output file cout << "Writing output file \"" << oFile << ".vtk\"" << endl << flush; lattice.writeCartesianVTK(oFile + ".vtk", title); return(0); }
bool IsFileExist(const char* pszFileName) { bool bExist = false; ifstream iFile(pszFileName, ios::in); if(iFile.is_open()) { bExist = true; iFile.close(); } return bExist; }
std::pair <std::string, int> ECPManager::topicData(int index){ std::string topic; std::string hostname(""); int port = 0; std::ifstream iFile(_topicsFile); int i = 1; while((iFile >> topic)){ if(index == i){ iFile >> hostname; iFile >> port; break; } i++; iFile >> topic; //Read hostname iFile >> topic; //Read port }
//////////////////////////////////////////////////////////////////////////////// /// CChanceTreeGraph::load /// /// @description This function loads data from the indicated file. /// @pre None /// @post The data is loaded from the file, if it is a valid file. /// /// @param fileName: This is the filename to load the data from. If no /// filename is specified, the name stored in the class will /// be used. /// /// @limitations None /// //////////////////////////////////////////////////////////////////////////////// void CChanceTreeGraph::load( const QString &fileName ) { //Check that either the given filename or the one stored within the class //are valid. If both are NULL, return without loading a file. if ( fileName.isNull() && m_fileName.isNull() ) return; //Check if the given filename is not NULL. As long as it's not NULL, //set the name stored in the class to the given name. if ( fileName.isNull() == false ) setFileName( fileName ); //Open the indicated file in read only mode. QFile iFile( m_fileName ); iFile.open( QIODevice::ReadOnly ); if ( !iFile.isOpen() ) { QMessageBox::critical( NULL, "File Error!", "There was an error " "opening the requested file, so the operation " "has been terminated.", QMessageBox::Ok, QMessageBox::NoButton ); return; } QDataStream iStream(&iFile); //These variables are used for reading in the program magic number and the //program mode, respectively. quint32 magicNum; int i; //Read the magic number of program mode from the data stream to get to the //data stored in the file. These values were checked previously before //this load function was called. iStream >> magicNum; iStream >> i; //Check if there is currently a tree loaded in the program. If there is, //delete it. if ( m_rootNode != NULL ) delete m_rootNode; //Create a new root node and load the data from the save file. m_rootNode = new SChanceTreeNode; loadHelper( m_rootNode, iStream ); }
const std::vector<uint8_t> FileToU8Vec(const std::string inFile) { std::ifstream iFile(inFile.c_str(), std::ios::in | std::ios::binary); if(iFile.is_open() == false) { std::cout << "File not found" << std::endl; exit(0); } std::ostringstream contents; contents << iFile.rdbuf(); iFile.close(); const std::string contentStr = contents.str(); const std::vector<uint8_t> contentVec(contentStr.begin(), contentStr.end()); return contentVec; }
bool cBaseIo::readTextFile(const string& textFile, string& text) { ifstream iFile(textFile.c_str(), std::ios::in); text = ""; if (!iFile.is_open()) { return false; } string strTemp; while (!iFile.eof()) { getline(iFile,strTemp); text += strTemp; text += "\n"; } iFile.close(); return true; }
void CompressionProgram::decompressionFile(string &ptrF) { string filename = renameF(ptrF); ifstream iFile(ptrF.c_str(), ios::binary); // Open the file for reading ofstream oFile(filename.c_str(), ios::binary); // Open the file for writing /* Create a vector of characters ranking */ vector<int> symbolRating(256); int tableSize; iFile.read((char *) &tableSize, sizeof(tableSize)); for (int i = 0; i < tableSize; i++) { iFile.read((char *) &symbolRating[i], sizeof(symbolRating[i])); } list<Node *> listNodesOfSymbolFrequencies = createListOfNodesWithRatingsSymbols(symbolRating); /* Create the root of the binary tree Huffman */ Node *root = createHuffmanBinaryTree(listNodesOfSymbolFrequencies); Node *p = root; unsigned char byte; int count = 0; byte = iFile.get(); while (!iFile.eof()) { bool b = byte & (1 << (7 - count)); p = (b) ? p->right : p->left; if (p->symbol) { unsigned char k = p->symbol; oFile.put(k); p = root; } count++; if (count == 8) { count = 0; byte = iFile.get(); } } iFile.close(); oFile.close(); }
bool IlluminaAnnotationFile::populateGeneticData( string &filename, GeneticData *gd, char delim ) { if( filename.empty() ) { gd->setCaseControlSet( NULL, NULL ); return true; } bool success = true; ifstream iFile( filename.c_str() ); set<string> cases, controls; string id; while( !iFile.eof() ) { getline( iFile, line ); parser.str( line ); parser.clear(); getline( parser, id, delim ); getline( parser, tok, delim); switch( tok[0] ) { case '1': cases.insert( id ); break; case '0': controls.insert( id ); break; default: break; } } gd->setCaseControlSet( &cases, &controls ); cases.clear(); controls.clear(); iFile.close(); return success; }
void CRecordManager::ReadRecordDoc() { ifstream iFile("Record.data",ios_base::binary | ios_base::in); if (!iFile) return; SQR_TRY uint32 uVersion = 0; iFile.read((char*)&uVersion,sizeof(uint32)); if (uVersion != RD_VERSION) { iFile.close(); DeleteFile("Record.data"); return; } int chunkNum=0; iFile.read((char*)&chunkNum,sizeof(int)); for (int i=0;i<chunkNum;++i) { int nameNum; iFile.read((char*)&nameNum,sizeof(int)); string strChunkName; strChunkName.resize(nameNum); iFile.read((char*)strChunkName.c_str(),nameNum); m_WholeRD[strChunkName] = ChunkType(); ReadChunkSubRD(iFile,m_WholeRD[strChunkName]); } if (m_strChunk != "" && m_WholeRD.count(m_strChunk)) { m_mapRecord = m_WholeRD[m_strChunk]; } SQR_CATCH(exp) { string strMsg = "读取转换文档信息出错"; strMsg = strMsg + exp.ErrorTitle(); CleanRecordData(); iFile.close(); } SQR_TRY_END iFile.close(); }
//Perform evolution on double pole balacing, for gens generations //If velocity is false, then velocity information will be withheld from the //network population (non-Markov) Population *pole2_test(int gens,int velocity) { Population *pop; Genome *start_genome; char curword[20]; int id; ostringstream *fnamebuf; int gen; CartPole *thecart; //Stat collection variables int highscore; int record[NEAT::num_runs][1000]; double recordave[1000]; int genesrec[NEAT::num_runs][1000]; double genesave[1000]; int nodesrec[NEAT::num_runs][1000]; double nodesave[1000]; int winnergens[NEAT::num_runs]; int initcount; int champg, champn, winnernum; //Record number of genes and nodes in champ int run; int curtotal; //For averaging int samples; //For averaging ofstream oFile("statout",ios::out); champg=0; champn=0; //Initialize the stat recording arrays for (initcount=0;initcount<200;initcount++) { recordave[initcount]=0; genesave[initcount]=0; nodesave[initcount]=0; for (run=0;run<NEAT::num_runs;++run) { record[run][initcount]=0; genesrec[run][initcount]=0; nodesrec[run][initcount]=0; } } char *non_markov_starter="pole2startgenes2"; char *markov_starter="pole2startgenes1"; char *startstring; if (velocity==0) startstring=non_markov_starter; else if (velocity==1) startstring=markov_starter; ifstream iFile(startstring,ios::in); //ifstream iFile("pole2startgenes",ios::in); cout<<"START DOUBLE POLE BALANCING EVOLUTION"<<endl; if (!velocity) cout<<"NO VELOCITY INPUT"<<endl; cout<<"Reading in the start genome"<<endl; //Read in the start Genome iFile>>curword; iFile>>id; cout<<"Reading in Genome id "<<id<<endl; start_genome=new Genome(id,iFile); iFile.close(); cout<<"Start Genome: "<<start_genome<<endl; for (run=0;run<NEAT::num_runs;run++) { cout<<"RUN #"<<run<<endl; //Spawn the Population from starter gene cout<<"Spawning Population off Genome"<<endl; pop=new Population(start_genome,NEAT::pop_size); //Alternative way to start off of randomly connected genomes //pop=new Population(pop_size,7,1,10,false,0.3); cout<<"Verifying Spawned Pop"<<endl; pop->verify(); //Create the Cart thecart=new CartPole(true,velocity); for (gen=1;gen<=gens;gen++) { cout<<"Epoch "<<gen<<endl; fnamebuf=new ostringstream(); (*fnamebuf)<<"gen_"<<gen<<ends; //needs end marker #ifndef NO_SCREEN_OUT cout<<"name of fname: "<<fnamebuf->str()<<endl; #endif char temp[50]; sprintf (temp, "gen_%d", gen); highscore=pole2_epoch(pop,gen,temp,velocity, thecart,champg,champn,winnernum,oFile); //highscore=pole2_epoch(pop,gen,fnamebuf->str(),velocity, thecart,champg,champn,winnernum,oFile); //cout<<"GOT HIGHSCORE FOR GEN "<<gen<<": "<<highscore-1<<endl; record[run][gen-1]=highscore-1; genesrec[run][gen-1]=champg; nodesrec[run][gen-1]=champn; fnamebuf->clear(); delete fnamebuf; //Stop right at the winnergen if (((pop->winnergen)!=0)&&(gen==(pop->winnergen))) { winnergens[run]=NEAT::pop_size*(gen-1)+winnernum; gen=gens+1; } //In non-MARKOV, stop right at winning (could go beyond if desired) if ((!(thecart->MARKOV))&&((pop->winnergen)!=0)) gen=gens+1; #ifndef NO_SCREEN_OUT cout<<"gen = "<<gen<<" gens = "<<gens<<endl; #endif if (gen==(gens-1)) oFile<<"FAIL: Last gen on run "<<run<<endl; } if (run<NEAT::num_runs-1) delete pop; delete thecart; } cout<<"Generation highs: "<<endl; oFile<<"Generation highs: "<<endl; for(gen=0;gen<=gens-1;gen++) { curtotal=0; for (run=0;run<NEAT::num_runs;++run) { if (record[run][gen]>0) { cout<<setw(8)<<record[run][gen]<<" "; oFile<<setw(8)<<record[run][gen]<<" "; curtotal+=record[run][gen]; } else { cout<<" "; oFile<<" "; curtotal+=100000; } recordave[gen]=(double) curtotal/NEAT::num_runs; } cout<<endl; oFile<<endl; } cout<<"Generation genes in champ: "<<endl; for(gen=0;gen<=gens-1;gen++) { curtotal=0; samples=0; for (run=0;run<NEAT::num_runs;++run) { if (genesrec[run][gen]>0) { cout<<setw(4)<<genesrec[run][gen]<<" "; oFile<<setw(4)<<genesrec[run][gen]<<" "; curtotal+=genesrec[run][gen]; samples++; } else { cout<<setw(4)<<" "; oFile<<setw(4)<<" "; } } genesave[gen]=(double) curtotal/samples; cout<<endl; oFile<<endl; } cout<<"Generation nodes in champ: "<<endl; oFile<<"Generation nodes in champ: "<<endl; for(gen=0;gen<=gens-1;gen++) { curtotal=0; samples=0; for (run=0;run<NEAT::num_runs;++run) { if (nodesrec[run][gen]>0) { cout<<setw(4)<<nodesrec[run][gen]<<" "; oFile<<setw(4)<<nodesrec[run][gen]<<" "; curtotal+=nodesrec[run][gen]; samples++; } else { cout<<setw(4)<<" "; oFile<<setw(4)<<" "; } } nodesave[gen]=(double) curtotal/samples; cout<<endl; oFile<<endl; } cout<<"Generational record fitness averages: "<<endl; oFile<<"Generational record fitness averages: "<<endl; for(gen=0;gen<gens-1;gen++) { cout<<recordave[gen]<<endl; oFile<<recordave[gen]<<endl; } cout<<"Generational number of genes in champ averages: "<<endl; oFile<<"Generational number of genes in champ averages: "<<endl; for(gen=0;gen<gens-1;gen++) { cout<<genesave[gen]<<endl; oFile<<genesave[gen]<<endl; } cout<<"Generational number of nodes in champ averages: "<<endl; oFile<<"Generational number of nodes in champ averages: "<<endl; for(gen=0;gen<gens-1;gen++) { cout<<nodesave[gen]<<endl; oFile<<nodesave[gen]<<endl; } cout<<"Winner evals: "<<endl; oFile<<"Winner evals: "<<endl; curtotal=0; samples=0; for (run=0;run<NEAT::num_runs;++run) { cout<<winnergens[run]<<endl; oFile<<winnergens[run]<<endl; curtotal+=winnergens[run]; samples++; } cout<<"Average # evals: "<<((double) curtotal/samples)<<endl; oFile<<"Average # evals: "<<((double) curtotal/samples)<<endl; oFile.close(); return pop; }
//Perform evolution on XOR, for gens generations Population *xor_test(int gens) { Population *pop; Genome *start_genome; char curword[20]; int id; ostringstream *fnamebuf; int gen; int evals[NEAT::num_runs]; //Hold records for each run int genes[NEAT::num_runs]; int nodes[NEAT::num_runs]; int winnernum; int winnergenes; int winnernodes; //For averaging int totalevals=0; int totalgenes=0; int totalnodes=0; int expcount; ifstream iFile("xorstartgenes",ios::in); cout<<"START XOR TEST"<<endl; cout<<"Reading in the start genome"<<endl; //Read in the start Genome iFile>>curword; iFile>>id; cout<<"Reading in Genome id "<<id<<endl; start_genome=new Genome(id,iFile); iFile.close(); for(expcount=0;expcount<NEAT::num_runs;expcount++) { //Spawn the Population cout<<"Spawning Population off Genome2"<<endl; pop=new Population(start_genome,NEAT::pop_size); cout<<"Verifying Spawned Pop"<<endl; pop->verify(); for (gen=1;gen<=gens;gen++) { cout<<"Epoch "<<gen<<endl; //This is how to make a custom filename fnamebuf=new ostringstream(); (*fnamebuf)<<"gen_"<<gen<<ends; //needs end marker #ifndef NO_SCREEN_OUT cout<<"name of fname: "<<fnamebuf->str()<<endl; #endif char temp[50]; sprintf (temp, "gen_%d", gen); //Check for success if (xor_epoch(pop,gen,temp,winnernum,winnergenes,winnernodes)) { // if (xor_epoch(pop,gen,fnamebuf->str(),winnernum,winnergenes,winnernodes)) { //Collect Stats on end of experiment evals[expcount]=NEAT::pop_size*(gen-1)+winnernum; genes[expcount]=winnergenes; nodes[expcount]=winnernodes; gen=gens; } //Clear output filename fnamebuf->clear(); delete fnamebuf; } if (expcount<NEAT::num_runs-1) delete pop; } //Average and print stats cout<<"Nodes: "<<endl; for(expcount=0;expcount<NEAT::num_runs;expcount++) { cout<<nodes[expcount]<<endl; totalnodes+=nodes[expcount]; } cout<<"Genes: "<<endl; for(expcount=0;expcount<NEAT::num_runs;expcount++) { cout<<genes[expcount]<<endl; totalgenes+=genes[expcount]; } cout<<"Evals "<<endl; for(expcount=0;expcount<NEAT::num_runs;expcount++) { cout<<evals[expcount]<<endl; totalevals+=evals[expcount]; } cout<<"Average Nodes: "<<((double) totalnodes/NEAT::num_runs)<<endl; cout<<"Average Genes: "<<((double) totalgenes/NEAT::num_runs)<<endl; cout<<"Average Evals: "<<((double) totalevals/NEAT::num_runs)<<endl; return pop; }
void ccg::load_V1(string filename, int start_year, int end_year, vector<string> &site_codes, string gas, string method, vector<ccgdata> &data, vector<sitedata> &sites, vector<float> &area) { ifstream iFile(filename.c_str()); char method_ch = ' '; if (method.length() > 0) { method_ch = toupper(method.c_str()[0]); } string str; while (!iFile.eof()) { getline(iFile, str); if (str != "") { if ((str.substr(0,1)=="#") || (str.length() < 137)) { continue; } string site_code = str.substr(0,3); int year = atoi(str.substr(4,4).c_str()); int month = atoi(str.substr(9,2).c_str()); int day = atoi(str.substr(12,2).c_str()); int hour = atoi(str.substr(15,2).c_str()); int min = atoi(str.substr(18,2).c_str()); int sec = atoi(str.substr(21,2).c_str()); string flask_ID = trim_string(str.substr(24,8)); string measurement_method = str.substr(33,1); string trace_gas_name = trim_string(str.substr(35,8)); string measurement_group = trim_string(str.substr(44,7)); float measured_value = atof(str.substr(53,9).c_str()); float estimated_uncertainty = atof(str.substr(63,9).c_str()); string qc_flag = trim_string(str.substr(73,3)); string instrument = trim_string(str.substr(77,3)); int measurement_year = atoi(str.substr(81,4).c_str()); int measurement_month = atoi(str.substr(86,2).c_str()); int measurement_day = atoi(str.substr(89,2).c_str()); int measurement_hour = atoi(str.substr(92,2).c_str()); int measurement_min = atoi(str.substr(95,2).c_str()); int measurement_sec = atoi(str.substr(98,2).c_str()); float latitude = atof(str.substr(101,8).c_str()); float longitude = atof(str.substr(110,9).c_str()); float altitude = atof(str.substr(120,8).c_str()); unsigned long event_number = atoi(str.substr(129,8).c_str()); /* the desired gas type */ if ((measured_value < -998) || (trace_gas_name != gas)) { continue; } /* the desired measurement method */ if ((method != "any") && (method != "all") && (method != "")) { if (measurement_method.length()>0) { if (measurement_method.c_str()[0] != method_ch) { continue; } } else { continue; } } /* check that the sample is within the desired area */ if (area.size()==4) { if (!site_within_area(latitude, -longitude, area)) { continue; } } if (site_code_in_data(site_code, sites)) { if ((year >= start_year) && (year <= end_year)) { for (int m = 0; m < 12; m++) { ccgdata data_point; strncpy(data_point.site_code, site_code.c_str(), SITE_CODE_LENGTH); data_point.year = year; data_point.month = month; data_point.day = day; data_point.hour = hour; data_point.minute = min; data_point.second = sec; strcpy(data_point.flask_ID, flask_ID.c_str()); data_point.method = measurement_method.c_str()[0]; strcpy(data_point.gas_identifier, trace_gas_name.c_str()); strcpy(data_point.measurement_group, measurement_group.c_str()); data_point.measured_value = measured_value; data_point.estimated_uncertainty = estimated_uncertainty; strncpy(data_point.qc_flag, qc_flag.c_str(), 3); strncpy(data_point.instrument, instrument.c_str(), 2); data_point.measurement_year = measurement_year; data_point.measurement_month = measurement_month; data_point.measurement_day = measurement_day; data_point.measurement_hour = measurement_hour; data_point.measurement_minute = measurement_min; data_point.measurement_second = measurement_sec; data_point.latitude = latitude; data_point.longitude = longitude; data_point.altitude = altitude; data_point.event_number = event_number; data.push_back(data_point); } } } } } iFile.close(); }
//Perform evolution on single pole balacing, for gens generations Population *pole1_test(int gens) { Population *pop; Genome *start_genome; char curword[20]; int id; ostringstream *fnamebuf; int gen; int expcount; int status; int runs[NEAT::num_runs]; int totalevals; ifstream iFile("pole1startgenes",ios::in); cout<<"START SINGLE POLE BALANCING EVOLUTION"<<endl; cout<<"Reading in the start genome"<<endl; //Read in the start Genome iFile>>curword; iFile>>id; cout<<"Reading in Genome id "<<id<<endl; start_genome=new Genome(id,iFile); iFile.close(); //Run multiple experiments for(expcount=0;expcount<NEAT::num_runs;expcount++) { cout<<"EXPERIMENT #"<<expcount<<endl; cout<<"Start Genome: "<<start_genome<<endl; //Spawn the Population cout<<"Spawning Population off Genome"<<endl; pop=new Population(start_genome,NEAT::pop_size); cout<<"Verifying Spawned Pop"<<endl; pop->verify(); for (gen=1;gen<=gens;gen++) { cout<<"Generation "<<gen<<endl; fnamebuf=new ostringstream(); (*fnamebuf)<<"gen_"<<gen<<ends; //needs end marker #ifndef NO_SCREEN_OUT cout<<"name of fname: "<<fnamebuf->str()<<endl; #endif char temp[50]; sprintf (temp, "gen_%d", gen); status=pole1_epoch(pop,gen,temp); //status=(pole1_epoch(pop,gen,fnamebuf->str())); if (status) { runs[expcount]=status; gen=gens+1; } fnamebuf->clear(); delete fnamebuf; } } totalevals=0; for(expcount=0;expcount<NEAT::num_runs;expcount++) { cout<<runs[expcount]<<endl; totalevals+=runs[expcount]; } cout<<"Average evals: "<<totalevals/NEAT::num_runs<<endl; return pop; }
//novelty maze navigation run Population *biped_novelty_realtime(char* outputdir,const char* mazefile,int par,const char* genes,bool novelty,bool evo) { Population *pop; Genome *start_genome; char curword[20]; int id; if (outputdir!=NULL) strcpy(output_dir,outputdir); if (!seed_mode) strcpy(seed_name,genes); //starter genes file ifstream iFile(seed_name,ios::in); //cout<<"START BIPED NAVIGATOR NOVELTY REAL-TIME EVOLUTION VALIDATION"<<endl; if (!seed_mode) { //cout<<"Reading in the start genome"<<endl; } else cout<<"Reading in the seed genome" <<endl; //Read in the start Genome iFile>>curword; iFile>>id; //cout<<"Reading in Genome id "<<id<<endl; start_genome=new Genome(id,iFile); iFile.close(); //cout<<"Start Genome: "<<start_genome<<endl; //Spawn the Population from starter gene // cout<<"Spawning Population off Genome"<<endl; if (!seed_mode) pop=new Population(start_genome,NEAT::pop_size); else { pop=new Population(seed_name);//start_genome,NEAT::pop_size,0.0); if (evaluate_switch) { int dist=0; double evol=0.0; cout << "Evaluating..." << endl; cout << pop->organisms.size() << endl; evolvability_biped(pop->organisms[0],"dummyfile",&dist,&evol,true); cout << endl << dist << " " << evol << endl; return 0; } } // cout<<"Verifying Spawned Pop"<<endl; pop->verify(); pop->set_evaluator(&biped_evaluate); //pop->set_compatibility(&behavioral_compatibility); //Start the evolution loop using rtNEAT method calls biped_novelty_realtime_loop(pop,novelty, evo); //clean up if (evall._world->rank()==0) return pop; else return NULL; }
int32 GoGoEncoder::Encode(BMessage* message) { PRINT(("GoGoEncoder::Encode(BMessage*)\n")); const char* inputFile; const char* outputFile; char bitrate[4]; bool vbr; char format[2]; bool psycho; BMessenger messenger; //set required fields; quit if not found or error if (message->FindString("input file", &inputFile) != B_OK) { message->AddString("error", "Error getting input path.\n"); return B_ERROR; } if (message->FindString("output file", &outputFile) != B_OK) { message->AddString("error", "Error getting output path.\n"); return B_ERROR; } if (message->FindMessenger("statusBarMessenger", &messenger) != B_OK) { message->AddString("error", "Error getting status bar messenger.\n"); return B_ERROR; } if (GetBitrate(bitrate, &vbr) != B_OK) { message->AddString("error", "Error getting bitrate setting.\n"); return B_ERROR; } if (GetFormat(format) != B_OK) { message->AddString("error", "Error getting format setting.\n"); return B_ERROR; } if (GetPsycho(&psycho) != B_OK) { message->AddString("error", "Error getting psychoacoustic setting.\n"); return B_ERROR; } //check if input file is of correct type BFile iFile(inputFile, B_READ_ONLY); if (iFile.InitCheck() != B_OK) { message->AddString("error", "Error init'ing input file.\n"); return B_ERROR; } BNodeInfo info(&iFile); if (info.InitCheck() != B_OK) { message->AddString("error", "Error getting info on input file.\n"); return B_ERROR; } char mime[B_MIME_TYPE_LENGTH]; info.GetType(mime); if ((strcmp(mime, WAV_MIME_TYPE) != 0) && (strcmp(mime, RIFF_WAV_MIME_TYPE) != 0) && (strcmp(mime, RIFF_MIME_TYPE) != 0)) { return FSS_INPUT_NOT_SUPPORTED; } //set up arg list int argc = 7; if (!psycho) { argc = 8; } const char* argv[argc+1]; argv[0] = gogoPath; argv[1] = inputFile; argv[2] = outputFile; if (vbr) { argv[3] = VBR_PREFIX; } else { argv[3] = BITRATE_PREFIX; } argv[4] = bitrate; argv[5] = FORMAT_PREFIX; argv[6] = format; if (!psycho) { argv[7] = "-nopsy"; argv[8] = NULL; } else { argv[7] = NULL; } #ifdef DEBUG int j = 0; while (argv[j] != NULL) { PRINT(("%s ", argv[j])); j++; } PRINT(("\n")); #endif FILE* out; int filedes[2]; thread_id gogo = CommandIO(filedes, argc, argv); if (gogo <= B_ERROR) { message->AddString("error", "Error running gogo.\n"); return B_ERROR; } out = fdopen(filedes[0], "r"); resume_thread(gogo); int32 status = UpdateStatus(out, &messenger); close(filedes[1]); close(filedes[0]); if (status == FSS_CANCEL_ENCODING) { status = send_signal(gogo, SIGTERM); PRINT(("status = %d\n", status)); return FSS_CANCEL_ENCODING; } status_t err; wait_for_thread(gogo, &err); WriteDetails(message); if (CheckForCancel()) { PRINT(("Cancel Requested.\n")); return FSS_CANCEL_ENCODING; } return B_OK; }
//Perform evolution on single pole balacing, for gens generations Population *biped_generational(char* outputdir,const char *genes, int gens,bool novelty) { float archive_thresh=3.0; char logname[100]; sprintf(logname,"%s_log.txt",outputdir); logfile=new ofstream(logname); maxgens=gens; noveltyarchive archive(archive_thresh,*walker_novelty_metric,true,push_back_size,minimal_criteria,true); //if doing multiobjective, turn off speciation, TODO:maybe turn off elitism if (NEAT::multiobjective) NEAT::speciation=false; Population *pop; Genome *start_genome; char curword[20]; int id; data_rec Record; ostringstream *fnamebuf; int gen; ifstream iFile(genes,ios::in); if (outputdir!=NULL) strcpy(output_dir,outputdir); cout<<"START GENERATIONAL BIPED EVOLUTION"<<endl; cout<<"Reading in the start genome"<<endl; //Read in the start Genome iFile>>curword; iFile>>id; cout<<"Reading in Genome id "<<id<<endl; start_genome=new Genome(id,iFile); iFile.close(); cout<<"Start Genome: "<<start_genome<<endl; //Spawn the Population cout<<"Spawning Population off Genome"<<endl; pop=new Population(start_genome,NEAT::pop_size); cout<<"Verifying Spawned Pop"<<endl; pop->verify(); //set evaluator pop->set_evaluator(&biped_evaluate); //pop->set_compatibility(&behavioral_compatibility); for (gen=0; gen<=maxgens; gen++) { //WAS 1000 cout<<"Generation "<<gen<<endl; bool win = biped_generational_epoch(&pop,gen,Record,archive,novelty); if (win) { char fname[100]; sprintf(fname,"%s_wingen",output_dir); ofstream winfile(fname); winfile << gen << endl; sprintf(fname,"%s_archive.dat",output_dir); archive.Serialize(fname); sprintf(fname,"%s_record.dat",output_dir); Record.serialize(fname); //break; } } delete logfile; delete pop; return pop; }
bool fio::FileINI::Load(std::string sFile) { //clear all data m_veHeaders.clear(); //even when the function fails, the default non-named header will //be there m_veHeaders.push_back(FileINIHeader()); std::vector<FileINIHeader>::iterator itHeader = m_veHeaders.begin(); //open a file to read data from std::ifstream iFile(sFile.c_str(), std::ios::in); if (!iFile.is_open()) { //could not open file return false; } std::string sLine; std::getline(iFile, sLine); while (!iFile.eof()) { //have not yet reached the end of the file, remove anything //that resembles a comment from the string const size_t nComment = sLine.find('#'); if (nComment != sLine.npos) { //remove the comment from the line sLine.substr(0, nComment); } Sanitize(sLine); if (sLine.length() != 0) { //line still contains information if (sLine[0] == '[') { //dealing with a header, create a new header FileINIHeader newHeader; const size_t nHeaderEnd = sLine.find(']'); if (nHeaderEnd == sLine.npos) { //expected to find a closing bracket as well iFile.close(); return false; } newHeader.sHeader = sLine.substr(1, nHeaderEnd - 1); //sanitize header name newHeader.sHeader = fio::RemoveLeadingWhitespace(newHeader.sHeader); newHeader.sHeader = fio::RemoveTrailingWhitespace(newHeader.sHeader); //add the the vector and update the iterator m_veHeaders.push_back(newHeader); itHeader = m_veHeaders.end() - 1; } else { //line contains data and is not a header, then it must contain //a variable and its associated value const size_t nEqual = sLine.find('='); if (nEqual == sLine.npos) { //expected to find an equal sign iFile.close(); return false; } FileINIEntry newEntry; newEntry.sName = fio::RemoveTrailingWhitespace(sLine.substr(0, nEqual)); newEntry.sValue = fio::RemoveLeadingWhitespace(sLine.substr(nEqual + 1)); //add entry to the current header itHeader->veEntries.push_back(newEntry); } } //retrieve a new line std::getline(iFile, sLine); } //if this code is reached, the file is completely loaded iFile.close(); return true; }
void naiveBayes(string naiveBayesTestVSM) { ifstream iFile(trainBayes.c_str()); //TF词典"E:\\final\\final\\myData\\myTFDic.txt"; ifstream featureFile(featureDicPath.c_str()); cout<<featureDicPath<<endl; double featureVal; string featureStr; string words; int TF; int cnt; int flag; int i,j; while(featureFile>>featureStr>>featureVal) featureDic[featureStr]++; while(iFile>>words) { iFile>>flag>>cnt; for(i = 0; i < cnt; i++) { iFile>>flag>>TF; if(featureDic.count(words)) bayesDic[words][flag] = TF; } } i = j = 0; cout<<"******"<<bayesDic.size()<<endl; for(map<string,map<int,int> >::iterator itor = bayesDic.begin(); itor != bayesDic.end();itor++) { //cout<<itor->first<<endl; for(int k = 0; k < 8; k++) bayes[j][k] = 1.0 / (1000 + bayesDic[itor->first][9]); for(map<int,int>::iterator it = itor->second.begin(); it != itor->second.end();it++) { i = it->first - 1; if(i == 8) break; bayes[j][i] = 1.0 * (1 + it->second) / (1000.0 + bayesDic[itor->first][9]); } j++; } ofstream out("mydata\\bayesOnECE.txt"); for( i = 0; i < 8; i++) { for(j = 0 ; j < 1000; j++) out<<bayes[j][i]<<" "; out<<endl; } double p[8]; int c,pos,v,b; string kk; //ifstream in("testBayesOnCross.txt"); ifstream in(naiveBayesTestVSM.c_str()); //ofstream myout("ans.txt"); int result[3117 + 3]; int reCnt = 0; while(in>>kk) { //in>>kk; in>>c; for(i = 0; i < 8; i++)p[i] = 0; for( i = 0; i < c ;i++) { in>>pos>>v; for(j = 0; j < 8; j++) { p[j] += v * log(bayes[pos][j]); //p[j] += v * log(bayes[j][pos]); } } double max = -999999999; int ans; for(i = 0; i < 8; i++) { //cout<<p[i]<<endl; if(max < p[i]) { max = p[i]; ans = i; } } //myout<<ans+1<<endl; result[reCnt++] = ans; } for(i = 0; i < reCnt; i++) { int flag = result[i]; b = i; switch(flag) { case 2: if(b >= 0 && b < 362)artNum[0]++; else P[0]++; break; case 3: if(b >= 362 && b < 753)artNum[1]++; else P[1]++; break; case 0: if(b >= 753 && b < 1166)artNum[2]++; else P[2]++; break; case 4: if(b >= 1166 && b < 1568)artNum[3]++; else P[3]++; break; case 5: if(b >= 1568 && b < 1967)artNum[4]++; else P[4]++; break; case 6: if(b >= 1967 && b < 2367)artNum[5]++; else P[5]++; break; case 7: if(b >= 2367 && b < 2768)artNum[6]++; else P[6]++; break; case 1: if(b >= 2768 && b < 3117)artNum[7]++; else P[7]++; break; } //b++; } }
bool fio::FileCSV::Load(std::string sFile, const unsigned int nSkipRows, const unsigned int nSkipColumns, const std::string sDelimiter) { //remove any data if it exists if (m_pData) { delete [] m_pData; m_pData = NULL; m_nRows = 0; m_nColumns = 0; } assert(m_nRows == 0); assert(m_nColumns == 0); //start loading the file std::ifstream iFile(sFile.c_str(), std::ios::in); if (!iFile.is_open()) { //failed to open the file return false; } //a bit inefficient this, but I suspect I will not use this library very often, If I will: //TODO: Optimize the following std::vector<std::string> veData; std::string sLine; std::getline(iFile, sLine); while (!iFile.eof()) { //sanitize the line, check how many delimiters it contains and store it const unsigned int nCurColumns = comstr::CountOccurrence(sLine, sDelimiter) + 1; if (nCurColumns > m_nColumns) { //number of columns must be increased m_nColumns = nCurColumns; } sLine = comstr::RemoveSystemCharacters(sLine); if (sLine.length() != 0) { veData.push_back(sLine); m_nRows++; } //get a new line to process std::getline(iFile, sLine); } //all data retrieved, close the file iFile.close(); //make sure everything is ready to skip the required number of rows and columns if (m_nColumns <= nSkipColumns || m_nRows <= nSkipRows) { //no data will remain if we skip the requested columns return true; } const unsigned int nOldNumColumns = m_nColumns; m_nColumns -= nSkipColumns; m_nRows -= nSkipRows; //done looping through all lines, now store them internally m_pData = new std::string[m_nColumns * m_nRows]; unsigned int iBase = 0; if (nSkipRows == 0) { //simple optimization, no temporary storage required if no rows are skipped for (std::vector<std::string>::const_iterator it = veData.begin() + nSkipRows; it != veData.end(); it++) { //this will loop through all rows comstr::SeperateString(*it, sDelimiter, m_pData + iBase, m_nColumns); iBase += m_nColumns; } } else { //we require temporary storage std::string *pTemp = new std::string[nOldNumColumns]; for (std::vector<std::string>::const_iterator it = veData.begin() + nSkipRows; it != veData.end(); it++) { //loop through all rows, disregard the skipped columns comstr::SeperateString(*it, sDelimiter, pTemp, m_nColumns); for (unsigned int i = 0; i < m_nColumns; i++) { m_pData[iBase + i] = pTemp[nSkipRows + i]; } iBase += m_nColumns; } //delete the temporary storage delete [] pTemp; } //done storing everything return true; }
int32 OggEncoder::Encode(BMessage* message) { PRINT(("OggEncoder::Encode(BMessage*)\n")); argument args; memset(&args, 0, sizeof(argument)); char bitrate[4]; if (GetArgs(&args, message) != B_OK) { message->AddString("error", "Error getting arguments.\n"); return B_ERROR; } if (GetBitrate(bitrate) != B_OK) { message->AddString("error", "Error getting bitrate setting.\n"); return B_ERROR; } //check if input file is of correct type BFile iFile(args.inputFile, B_READ_ONLY); if (iFile.InitCheck() != B_OK) { message->AddString("error", "Error init'ing input file.\n"); return B_ERROR; } BNodeInfo info(&iFile); if (info.InitCheck() != B_OK) { message->AddString("error", "Error getting info on input file.\n"); return B_ERROR; } char mime[B_MIME_TYPE_LENGTH]; info.GetType(mime); if ((strcmp(mime, WAV_MIME_TYPE) != 0) && (strcmp(mime, RIFF_WAV_MIME_TYPE) != 0) && (strcmp(mime, RIFF_MIME_TYPE) != 0) && (strcmp(mime, AIFF_MIME_TYPE) != 0)) { return FSS_INPUT_NOT_SUPPORTED; } //set up arg list int numTags = 0; if (args.artist) numTags += 2; if (args.album) numTags += 2; if (args.title) numTags += 2; if (args.year) numTags += 2; if (args.comment) numTags++; if (args.track) numTags += 2; if (args.genre) numTags++; int argc = 6 + numTags; const char* argv[argc+1]; argv[0] = oggencPath; argv[1] = OUTPUT_PREFIX; argv[2] = args.outputFile; argv[3] = BITRATE_PREFIX; argv[4] = bitrate; int i = 5; if (args.artist) { argv[i] = strdup(ARTIST_PREFIX); argv[i+1] = strdup(args.artist); i += 2; } if (args.album) { argv[i] = strdup(ALBUM_PREFIX); argv[i+1] = strdup(args.album); i += 2; } if (args.title) { argv[i] = strdup(TITLE_PREFIX); argv[i+1] = strdup(args.title); i += 2; } if (args.year) { argv[i] = strdup(YEAR_PREFIX); argv[i+1] = strdup(args.year); i += 2; } if (args.comment) { BString comment = COMMENT_PREFIX; comment << args.comment; argv[i] = strdup(comment.String()); i++; } if (args.track) { argv[i] = strdup(TRACK_PREFIX); argv[i+1] = strdup(args.track); i += 2; } if (args.genre) { BString genre = GENRE_PREFIX; genre << args.genre; argv[i] = strdup(genre.String()); i++; } argv[argc-1] = args.inputFile; argv[argc] = NULL; #ifdef DEBUG int j = 0; while (argv[j] != NULL) { PRINT(("%s ", argv[j])); j++; } PRINT(("\n")); #endif FILE* out; int filedes[2]; thread_id oggenc = CommandIO(filedes, argc, argv); if (oggenc <= B_ERROR) { PRINT(("ERROR: can't load oggenc image\n")); return B_ERROR; } out = fdopen(filedes[0], "r"); resume_thread(oggenc); int32 status = UpdateStatus(out, &messenger); fclose(out); close(filedes[1]); if (status == FSS_CANCEL_ENCODING) { status = send_signal(oggenc, SIGTERM); PRINT(("status = %d\n", status)); return FSS_CANCEL_ENCODING; } status_t err; wait_for_thread(oggenc, &err); WriteDetails(&args); return B_OK; }
int main(int narg, char** argv) { if (narg>1 && (!strcmp(argv[1],"-h") || !strcmp(argv[1],"-?")) ) { std::cout<<"Usage : voronoi_3 filename"<<std::endl <<" filename being a fine containing 3D points used to " <<" compute the Delaunay_triangulation_3."<<std::endl; return EXIT_FAILURE; } std::string filename; if ( narg==1 ) { filename=std::string("data/points_3"); std::cout<<"No filename given: use data/points_3 by default."<<std::endl; } else filename=std::string(argv[1]); // 1) Compute the Delaunay_triangulation_3. Triangulation T; std::ifstream iFile(filename.c_str()); if (!iFile) { std::cout << "Problem reading file " << filename << std::endl; return EXIT_FAILURE; } std::istream_iterator<Point> begin(iFile), end; T.insert(begin, end); CGAL_assertion(T.is_valid(false)); // 2) Convert the triangulation into a 3D lcc. LCC_3 lcc; std::map<Triangulation::Cell_handle, LCC_3::Dart_handle > vol_to_dart; Dart_handle dh=CGAL::import_from_triangulation_3<LCC_3, Triangulation> (lcc, T, &vol_to_dart); std::cout<<"Delaunay triangulation :"<<std::endl<<" "; lcc.display_characteristics(std::cout) << ", valid=" << lcc.is_valid() << std::endl; // 3) Compute the dual lcc. LCC_3 dual_lcc; Dart_handle ddh=lcc.dual(dual_lcc, dh); // Here, dual_lcc is the 3D Voronoi diagram. CGAL_assertion(dual_lcc.is_without_boundary()); // 4) We update the geometry of dual_lcc by using the std::map // face_to_dart. transform_dart_to_their_dual<LCC_3,Triangulation> (lcc, dual_lcc, vol_to_dart); set_geometry_of_dual<LCC_3,Triangulation>(dual_lcc, T, vol_to_dart); // 5) Display the dual_lcc characteristics. std::cout<<"Voronoi subdvision :"<<std::endl<<" "; dual_lcc.display_characteristics(std::cout) << ", valid=" << dual_lcc.is_valid() << std::endl; display_voronoi(dual_lcc, ddh); return EXIT_SUCCESS; }
void threadProcess( std::string iFileDir, std::string oFileDir, FIFO<int>& module_list, int threadID) { while(1) { // get next module for process or exit if done. int module_number; try { module_number = module_list.pop(); std:: stringstream report; report << "Stating module " << module_number; thread_report(report.str(),threadID); }catch(std::string i) { thread_report("Terminating",threadID); return; } std::array<FIFO<std::string>,12> asicData; //stores the data from the asic asicData[asicID][SPP] FIFO<std::string> side1, side2; for(int i(0); i < 12; i++) { std::stringstream filename; filename << iFileDir << "/timesync" << module_number*12 + i << ".txt"; std::ifstream iFile(filename.str()); std::string tempIn; while(iFile >> tempIn) { if (atoi(tempIn.c_str()) == 0) continue; asicData[i].store(tempIn); } } bool complete = false; bool next_bcid = true; int bcid = 0; while(!complete) { for (int i(0); i < 12; i++) if(!asicData[i].is_empty()){ if(get_bcid(asicData[i].peek()) == bcid){ if (i < 3 || i >= 9) side1.store(asicData[i].pop()); else side2.store(asicData[i].pop()); next_bcid = false; } } complete = true; for (auto& asic : asicData) if (!asic.is_empty()) complete = false; if (next_bcid) if (++bcid >= 512) bcid = 0; next_bcid = true; } std::stringstream outFileName1; outFileName1 << oFileDir << "/module_" << module_number << "_"; std::stringstream outFileName2; outFileName2 << outFileName1.str(); //shits and giggles outFileName1 << 1 << ".txt"; outFileName2 << 2 << ".txt"; std::ofstream oFile1(outFileName1.str()); std::ofstream oFile2(outFileName2.str()); thread_report("Writing to file",threadID); while(!side1.is_empty()) oFile1 << side1.pop() << '\n'; while(!side2.is_empty()) oFile2 << side2.pop() << '\n'; } }