VOID Fini(INT32 code, VOID *v) { PRINT_SCN ("All applications are at the end" << "..."); #ifdef LOG_ASSEM TraceFile.close(); #endif MemFile.close(); }
void createWalletFile(std::fstream& walletFile, const std::string& filename) { walletFile.open(filename.c_str(), std::fstream::in | std::fstream::out | std::fstream::binary); if (walletFile) { walletFile.close(); throw std::runtime_error("Wallet file already exists"); } walletFile.open(filename.c_str(), std::fstream::out); walletFile.close(); walletFile.open(filename.c_str(), std::fstream::in | std::fstream::out | std::fstream::binary); }
void ScientificProcessor::saveAllCellsToCsv(std::fstream &filestr) { std::map<int, std::vector<double> > firstTime = allCells.begin()->second; std::vector<double> firstCell = firstTime.begin()->second; std::cout << firstCell.size() << std::endl; int nfl = (firstCell.size() - 9)/2; /* Header */ filestr << "t, label, tp, parent, cx, cy, h, w, area, angle, "; for(unsigned int i = 0; i < nfl; i++) filestr << "flav" << i << ", flsd" << i << ", "; filestr << std::endl; /* Data */ for(std::map<int, std::map<int, std::vector<double> > >::iterator it = allCells.begin(); it != allCells.end(); ++it) { int t = it->first; std::map<int, std::vector<double> > currentTime = it->second; for(std::map<int, std::vector<double> >::iterator itm = currentTime.begin(); itm != currentTime.end(); ++itm) { std::vector<double> features = itm->second; filestr << t << ","; for(std::vector<double>::iterator itv = features.begin(); itv != features.end(); ++itv) { filestr << *itv << ","; } filestr << std::endl; } } filestr.close(); }
void open() { // // open file in out mode, close and open again in out/in mode // for (int ilayer=0; ilayer<4; ++ilayer) { vname[ilayer] << "temporary_file_v" << ilayer << "file-" << std::setfill('0') << std::setw(3) << angle << ".dat"; tname[ilayer] << "temporary_file_t" << ilayer << "file-" << std::setfill('0') << std::setw(3) << angle << ".dat"; uname[ilayer] << "temporary_file_u" << ilayer << "file-" << std::setfill('0') << std::setw(3) << angle << ".dat"; vfile[ilayer] = new fstream(vname[ilayer].str().c_str(), std::ios::binary | std::ios::out); vfile[ilayer]->close(); vfile[ilayer]->open(vname[ilayer].str().c_str(), std::ios::binary | std::ios::in | std::ios::out); tfile[ilayer] = new fstream(tname[ilayer].str().c_str(), std::ios::binary | std::ios::out); tfile[ilayer]->close(); tfile[ilayer]->open(tname[ilayer].str().c_str(), std::ios::binary | std::ios::in | std::ios::out); ufile[ilayer] = new fstream(uname[ilayer].str().c_str(), std::ios::binary | std::ios::out); ufile[ilayer]->close(); ufile[ilayer]->open(uname[ilayer].str().c_str(), std::ios::binary | std::ios::in | std::ios::out); } wname << "temporary_file_wfile-" << std::setfill('0') << std::setw(3) << angle << ".dat"; wfile = new fstream(wname.str().c_str(), std::ios::binary | std::ios::out); wfile->close(); wfile->open(wname.str().c_str(), std::ios::binary | std::ios::in | std::ios::out); }
// getFILE is a wrapper for getting files bool getFILE(std::fstream &fp, const char* fname, const char* mode) { int writeFile = 0; if (strcmp(mode, "out") == 0) { writeFile = 1; if(writeFile && fexists(fname)) { fprintf(stderr,"File already exists: %s\n",fname); return false; } fp.open(fname, std::ios::out); } else if (strcmp(mode, "app") == 0) fp.open(fname, std::ios::app); else if (strcmp(mode, "in") == 0) fp.open(fname, std::ios::in); if( !fp ) { fprintf(stderr,"Error opening FILE handle for file: %s\n",fname); fp.close(); return false; } return true; }
void getstat(const std::string& pid,std::fstream& tsdbfile,std::string metric)//Get memmemory information (in one block right now) { std::string dummy,minflt,mjflt,utime,s_time,nthreads,vsize,rss,iodelay; char state; std::string path="/proc/"+pid+"/stat"; std::ifstream file(path,std::ifstream::binary); file>>dummy>>dummy>>state>>dummy>>dummy>>dummy>>dummy>>dummy>>dummy>>minflt>>dummy>>mjflt>>dummy>>utime>>s_time>>dummy>>dummy>>dummy>>dummy>>nthreads>>dummy>>dummy>>vsize>>rss; metric+=".stat"; std::string st_int; switch(state){ case 'R': st_int="1";break; case 'S': st_int="2"; break; case 'D': st_int="3"; break; case 'T': st_int="4"; break; default: st_int="0"; } tsdbfile.open ("tcollector_proc.out",std::fstream::app); tsdb_stdout(tsdbfile,metric+".state",st_int); tsdb_stdout(tsdbfile,metric+".minflt",minflt); tsdb_stdout(tsdbfile,metric+".mjrflt",mjflt); tsdb_stdout(tsdbfile,metric+".utime",utime); tsdb_stdout(tsdbfile,metric+".stime",s_time); tsdb_stdout(tsdbfile,metric+".nthreads",nthreads); tsdbfile.close(); return; }
exp bool Close() { // Update FS info before unmounting the disk WriteFSInfo(); f.close(); return true; }
// Ensures the file is opened/closed properly and retries 5 times. // if choice is false, the file is closed and if it is 1, the file is opened. bool verifiedOC ( std::fstream& file, std::string fileDir, bool choice, std::ios::openmode io ) { unsigned int i = 0; // Declaring a counter variable. // Choice determines if we are opening or closing the file. (True to open, False to close) if ( choice ) { do { file.open ( fileDir.c_str(), io ); // Open file as user selection. if ( file.is_open() ) { return true; } else { // Prints that the attempt to change the file state has failed. std::cout << "The file " << fileDir.c_str() << " failed to open... Retrying " << ++i << "\n"; } // Will exit the loop after the the number of attempts FILE_OPEN_RETRIES specifies. if ( i >= FILE_OPEN_RETRIES ) { std::cout << "The file " << fileDir.c_str() << " failed to change open." << std::endl; return false; } } while ( !file.is_open() ); } else { file.close(); } return true; }
void StoreCurrentFitnessInPopulation(Fitnesses& fitness, std::fstream& fitnessEachGeneration) { fitnessEachGeneration.open("FitnessEachGeneration.txt", std::fstream::in | std::fstream::out | std::fstream::app); int populationSize = fitness.size(); for(int i=0;i<populationSize;i++) { fitnessEachGeneration << fitness[i] <<'\n'; } fitnessEachGeneration.close(); }
void close() { for (int ilayer=0; ilayer<4; ++ilayer) { vfile[ilayer]->close(); tfile[ilayer]->close(); ufile[ilayer]->close(); } wfile->close(); }
void PcieAccessInterfaceTest::write_file(char* data, const std::string& path, uint32_t size, uint32_t offset) { memory_file.open(path, std::ios::out |std::ios::binary | std::ios::trunc); if (memory_file.is_open()) { memory_file.seekg(offset, std::ios::beg); memory_file.write(data, size); memory_file.close(); } }
void createAndOpen(std::fstream& file, std::string name){ if (!exists(name.c_str())){ file.open(name.c_str(), std::fstream::out | std::fstream::binary); file.close(); } file.open(name.c_str(), std::fstream::in | std::fstream::out | std::fstream::binary); }
/*! \brief Close and truncate the file, and update digest * Truncation is needed to remove any detritus from previously-saved states. */ void resultsfile::finishwithfile(std::fstream& file) { std::streampos length = file.tellp(); // close and truncate file file.close(); truncate(length); // re-open and update digest file.open(fname.c_str(), std::ios::in); filedigest.process(file); }
NMPRKC_API nmprk_status_t NMPRK_StopDebugLogging() { if(si_fsDebugLog.is_open() == true) { SI_DEBUG_INFO(SI_THIS_MODULE, "Debug Logging Stopped"); si_fsDebugLog.close(); } return NMPRK_SUCCESS; }
/** * Initializes the hash function, with a file stream value. * * @param fileStream The stream value to be used for computation. * @param closeStream If the file stream should be closed at end, if false * the file stream is positioned at the initial position. */ void HashFunction::init(std::fstream &fileStream, bool closeStream) { // calls the stream init method this->init((std::istream &) fileStream); // in case the file stream should be closed if(closeStream) { // closes the file stream fileStream.close(); } }
void closeLogFile(std::fstream& logFile) { logFile.close(); if (logFile.fail()) { std::cout << "ERROR while closing the log file" << std::endl; exit(EXIT_FAILURE); } }
bool LevelReaderWriter::LoadAsBinaryV0(std::fstream& _file, b2World* _world, Player& _player, std::vector<Box>& _boxes) { { //raed the player glm::vec2 pos; glm::vec2 ddims; glm::vec2 cdims; GameEngine::ColorRGBA8 color; _file.read((char*)&pos, sizeof(glm::vec2)); _file.read((char*)&ddims, sizeof(glm::vec2)); _file.read((char*)&cdims, sizeof(glm::vec2)); _file.read((char*)&color, sizeof(GameEngine::ColorRGBA8)); _player.Init(_world, pos, ddims, cdims, color); } { //read the boxes glm::vec2 pos; glm::vec2 dims; glm::vec4 uvRect; GameEngine::ColorRGBA8 color; bool fixedRotation; bool isDynamic; bool isSensor; float angle; GameEngine::GLTexture texture; std::string texturePath; size_t numBoxes; _file.read((char*)&numBoxes, sizeof(size_t)); for (size_t i = 0; i < numBoxes; i++) { _file.read((char*)&pos, sizeof(glm::vec2)); _file.read((char*)&dims, sizeof(glm::vec2)); _file.read((char*)&color, sizeof(GameEngine::ColorRGBA8)); _file.read((char*)&uvRect, sizeof(glm::vec4)); _file.read((char*)&angle, sizeof(float)); _file.read((char*)&texturePath, sizeof(std::string)); _file.read((char*)&fixedRotation, sizeof(bool)); _file.read((char*)&isDynamic, sizeof(bool)); _file.read((char*)&isSensor, sizeof(bool)); texture = GameEngine::ResourceManager::GetTexture(texturePath); _boxes.emplace_back(); _boxes.back().Init(_world, pos, dims, texture, color, fixedRotation, isDynamic, isSensor, angle, uvRect); } } _file.close(); return true; }
int main() { static std::string filename {R"(/tmp/record.txt)"}; static std::string sorted_filename {R"(/tmp/sorted_record.txt)"}; std::remove(sorted_filename.c_str()); static std::fstream fs{filename, std::ios::in}; static std::fstream sorted_fs{sorted_filename, std::ios::out}; auto writer = [](const auto& val) { sorted_fs << std::setfill('0') << std::setw(7) << val << std::endl; }; sort_to(writer, fs); fs.close(); sorted_fs.close(); }
void Game::deinit() { //Free things here (be clean!!) logFile << "Deinitializing" << std::endl; SDL_GL_DeleteContext(glcontext); SDL_DestroyWindow(window); SDL_Quit(); logFile.close(); }
int main(int argc, char **argv){ ros::init(argc, argv, "sum_pointcloud"); ros::NodeHandle n; //ROS_INFO("Start get pointcloud."); fout.open("/home/lixin/pointcloudxyz"); sub = n.subscribe("laser_cloud_surround",1,readCallback); ros::spin(); fout.close(); return 0; }
void CFileManager::FileLoader(std::fstream& i_stream,std::string i_filepath) { i_stream.clear(); //i_stream.open(i_filepath.c_str()); i_stream.open("TestData.txt"); if(i_stream.is_open()) { //i_stream << "opened this file"; i_stream >> token; if(token == "gobblin") { //characters.push_back( CHARACTER() ); //LoadGoblin( file, characters.back() ); } i_stream.close(); }
int main (int argc, char** argv) { // Initialize ROS ros::init (argc, argv, "local_mapping_node"); ros::NodeHandle nh; // Create a ROS subscriber for the input point cloud ros::Subscriber sub = nh.subscribe ("/velodyne_points", 1, cloud_cb); // Create a ROS subscriber for the input point cloud #ifdef USE_QUATS ros::Subscriber imu_sub = nh.subscribe ("/imu/data", 1, imu_cb_quats); #else ros::Subscriber imu_sub = nh.subscribe ("/imu/imu_3dm_gx3", 1, imu_cb); #endif // Create a ROS publisher for the output point cloud pub = nh.advertise<sensor_msgs::PointCloud2> ("mapping/velodyne_obs", 1); pubGnd = nh.advertise<sensor_msgs::PointCloud2> ("mapping/velodyne_gnd", 1); pubDrv = nh.advertise<sensor_msgs::PointCloud2> ("mapping/velodyne_drv", 1); //ros publisher for map occupancyGridPub = nh.advertise<nav_msgs::OccupancyGrid> ("mapping/local_occupancy", 1); //resize the binning vector ptBins.resize(NUMABINS*NUMLBINS); occGrid.data.resize(NUMABINS*NUMLBINS); fill(occGrid.data.begin(), occGrid.data.end(),-1); //timeOut.open("/home/jdservos/timeOutLocal.csv", fstream::out); //Init rotation tf::Quaternion q; tf::Matrix3x3 mat; mat.setEulerYPR(0, 0, 0); mat.getRotation(q); tf::quaternionTFToEigen(q, curQuat); // Spin ros::spin (); timeOut.close(); }
void getio(const std::string& path,std::fstream& tsdbfile,std::string metric) { std::ifstream file(path); std::string readchars,dummy,wrchars,syscw,syscr,read_bytes,write_bytes; file>>dummy>> readchars>>dummy>>wrchars>>dummy>>syscr>>dummy>>syscw>>dummy>>read_bytes>>dummy>>write_bytes; metric+=".io"; tsdbfile.open ("tcollector_proc.out",std::fstream::app); tsdb_stdout(tsdbfile,metric+".rchar",readchars); tsdb_stdout(tsdbfile,metric+".wchar",wrchars); tsdb_stdout(tsdbfile,metric+".syscr",syscr); tsdb_stdout(tsdbfile,metric+".syscw",syscw); tsdb_stdout(tsdbfile,metric+".read_b",read_bytes); tsdb_stdout(tsdbfile,metric+".write_b",write_bytes); tsdbfile.close(); return; }
bool Request::send_batch_file_data_to_server_once(){ if( !is_batch_file_open ) return false; if( !is_server_connect ) return false; std::string command; if( std::getline(batch_file_stream, command) ){ command += "\n"; int w_size = write_all(server_fd, command.c_str(), command.length()); if( w_size < 0 ){ perror_and_exit("write error"); } nl2br(command); print_html_content(id, "<b>" + command + "</b>"); return true; } batch_file_stream.close(); is_batch_file_open = false; return false; }
void StoreCurrentPopulationInFile(Population& population, std::fstream& populationEachGeneration, std::vector<std::vector<double>>& rangeAllVariables) { populationEachGeneration.open("PopulationEachGeneration.txt", std::fstream::in | std::fstream::out | std::fstream::app); int populationSize = population.size(); for(int i=0;i<populationSize;i++) { Individual tempIndividual = population[i]; // Choose one individual int numberOfUnits = tempIndividual.size(); for(int i=0;i<numberOfUnits;i++) { UnitGene tempUnit = tempIndividual[i]; // Choose one unit int numberOfGeneSets = tempUnit.size(); for(int j=0;j<numberOfGeneSets;j++) { Genes tempGeneSet = tempUnit[j]; int numberOfGenes = tempGeneSet.size(); // Choose one gene set for(int k=0;k<numberOfGenes;k++) { populationEachGeneration << tempGeneSet[k]; } // All genes in current gene set have been stored } // All gene sets in current unit have been stored } // All units in current individual have been stored populationEachGeneration << '\n'; } populationEachGeneration.close(); }
void getmem(const std::string& pid,std::fstream& tsdbfile,std::string metric)//Get memory information (in one block right now) { metric+=".mem"; std::string path="/proc/"+pid+"/statm"; std::ifstream file(path,std::ifstream::binary); std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); size_t pos = 0; std::string token; std::string delim=" "; std::string metrics[]={"VmSize","VMRSS","shr-pgs","code","NA","Data_and_stack"}; int met_pos=0; tsdbfile.open ("tcollector_proc.out",std::fstream::app); while ((pos = content.find(delim)) != std::string::npos) { token = content.substr(0, pos); content.erase(0, pos + delim.length()); tsdb_stdout(tsdbfile,metric+"."+metrics[met_pos],token); met_pos+=1; } tsdbfile.close(); return ; }
~MyFileReadStream() { if (_stream) _stream->close(); delete _stream; }
void stop_execution(bool b_show_plots = true) { // Write Execution Summary into the output file output_file << model_info << std::endl; if(output_file.is_open()) { output_file.close(); } if(b_show_plots) { std::string output_filename_quotes = "'" + prefix + "_gentlemans_battle.dat'"; std::string gnuplot_reaction_script = prefix + "_gentlemans_battle_result.gnu"; std::string gnuplot_phase_plane_script = prefix + "_gentlemans_battle_phase_plane.gnu"; std::string gnuplot_diffusion_script = prefix + "_gentlemans_battle_diffusion.gnu"; const int title_font_size = 15; { std::fstream gnuplot_script_file(gnuplot_reaction_script, std::ios::out); gnuplot_script_file << "set terminal 'wxt'" << std::endl; gnuplot_script_file << "set xlabel 'Tempo'" << std::endl; gnuplot_script_file << "set ylabel 'Número de Soldados'" << std::endl; gnuplot_script_file << "set zeroaxis" << std::endl; gnuplot_script_file << "set yrange [0:550]" << std::endl; gnuplot_script_file << "set title 'Evolução do Número de Soldados no Campo de Batalha' font 'Arial, " << title_font_size << "'" << std::endl; gnuplot_script_file << "plot " << output_filename_quotes << " using 1:2 with lines title 'Soldados'," << output_filename_quotes << " using 1:3 with lines title 'Inimigos' linetype rgb '#6f99c8'" << std::endl; gnuplot_script_file << "set output 'report/figs/battle_reaction.png'" << std::endl; gnuplot_script_file << "set terminal pngcairo enhanced font 'arial,10' fontscale 1.0" << std::endl; gnuplot_script_file << "replot" << std::endl; } { std::fstream gnuplot_script_file(gnuplot_diffusion_script, std::ios::out); gnuplot_script_file << "set terminal 'wxt'" << std::endl; gnuplot_script_file << "set xlabel 'Tempo'" << std::endl; gnuplot_script_file << "set ylabel 'Concentração de Munição'" << std::endl; gnuplot_script_file << "set zeroaxis" << std::endl; gnuplot_script_file << "set title 'Munição nas linhas de frente e retarguarda' font 'Arial, " << title_font_size << "'" << std::endl; gnuplot_script_file << "plot " << output_filename_quotes << " using 1:4 with lines title 'Retarguarda'," << output_filename_quotes << " using 1:5 with lines title 'Linha de frente' linetype rgb '#6f99c8'" << std::endl; gnuplot_script_file << "set output 'report/figs/battle_ammo_diffusion.png'" << std::endl; gnuplot_script_file << "set terminal pngcairo enhanced font 'arial,10' fontscale 1.0" << std::endl; gnuplot_script_file << "replot" << std::endl; } { const ModelInput& input = model_info.model_input; std::fstream gnuplot_script_file(gnuplot_phase_plane_script, std::ios::out); gnuplot_script_file << "set terminal 'wxt'" << std::endl; gnuplot_script_file << "k1 = " << input.enemy_skill << std::endl; gnuplot_script_file << "k2 = " << input.army_skill << std::endl; gnuplot_script_file << "alpha = " << input.front_line_fraction << std::endl; gnuplot_script_file << "beta = " << input.enemy_front_line_fraction << std::endl; gnuplot_script_file << "vec_scale = 0.5" << std::endl; gnuplot_script_file << "dEdt(I,E) = -k1 * alpha * E * beta * I" << std::endl; gnuplot_script_file << "dIdt(I,E) = -k2 * alpha * E * beta * I" << std::endl; gnuplot_script_file << "vx(x,y) = dEdt(x,y) * vec_scale # * (1 / sqrt(dEdt(x,y)**2 + dIdt(x,y)**2))" << std::endl; gnuplot_script_file << "vy(x,y) = dIdt(x,y) * vec_scale # * (1 / sqrt(dEdt(x,y)**2 + dIdt(x,y)**2))" << std::endl; gnuplot_script_file << "set samples 20" << std::endl; gnuplot_script_file << "set zeroaxis" << std::endl; gnuplot_script_file << "set xlabel 'Número de Soldados - E(t)'" << std::endl; gnuplot_script_file << "set ylabel 'Número de Inimigos - I(t)'" << std::endl; gnuplot_script_file << "set title 'Plano de Fase' font 'Arial, " << title_font_size << "'" << std::endl; gnuplot_script_file << "plot '_gentlemans_battle.dat' using 2:3 with lines title 'Número de Soldados x Inimigos'," << " '++' u 1:2:(vx($1,$2)):(vy($1,$2)) with vectors notitle linetype rgb '#6f99c8'" << std::endl; gnuplot_script_file << "set output 'report/figs/battle_phase_plane.png'" << std::endl; gnuplot_script_file << "set terminal pngcairo enhanced font 'Arial,10' fontscale 1.0" << std::endl; gnuplot_script_file << "replot" << std::endl; } // show reaction plot std::string plot_command = "gnuplot -p " + gnuplot_reaction_script + " > battle_reaction.png"; std::cout << plot_command << std::endl; system(plot_command.data()); // show diffusion plot plot_command = "gnuplot -p " + gnuplot_diffusion_script + " > battle_ammo_diffusion.png"; std::cout << plot_command << std::endl; system(plot_command.data()); // show phase plane plot plot_command = "gnuplot -p " + gnuplot_phase_plane_script + " > battle_phase_plane.png"; std::cout << plot_command << std::endl; system(plot_command.data()); } }
int main() { f1.open("/Users/robinmalhotra2/Desktop/csl201check.txt",std::ios::in|std::ios::out); f1.getline(s, 80, ' '); while (f1.good()) { std::cout<<"addasd"; if ((strlen(s)==1) && (s[0])<'9' && (s[0])>'0') { switch ((s[0])) { case '1': createandprintlist(); break; case '2': sortlist(); break; case '3': nextinsert(); break; case '4': searchlist(); break; case '5': deletenext(); break; case '6': deduplicate(); break; case '7': mergesortthing(); break; case '8': credits(); break; default: break; } } } f1.close(); }
//C++ file i/o version of the above. void LCSCloseFileCPP(std::fstream &file) { if(file.is_open()) //Check if the file even is open so that we don't bother closing a file that isn't open. file.close(); }