HG-MD
1
|
Here are the rounties to use a counter file to store run numbers. More...
#include <STD_save.h>
Public Member Functions | |
STD_save () | |
Default constructor: sets the counter to 0 (i.e. no number will be included). | |
STD_save (STD_save &other) | |
Copy constructor. | |
void | constructor () |
void | inc_counter_in_file () |
Increament the counter value stored in the file_counter by 1 and store the new value. | |
int | read_run_num_from_file () |
Read rom the counter file the counter. | |
void | set_counter_from_file () |
Sets the counter based on the current number stored in the counter file. | |
void | save_info_to_disk () |
Saves the information generated by info to disk in a file. | |
void | set_counter (int new_counter) |
This set the counter, overriding the defaults. | |
int | get_counter () |
This returns the current value of the counter. | |
virtual void | info () |
Set up a virtual info this will be provided from the inhertiance. | |
bool | FileExists (std::string strFilename) |
Function to check if a file exists, is used to check if a run has already need done. | |
void | auto_number () |
std::vector< int > | get_numbers (int size_x, int size_y) |
This turns a counter into two indexs for doing parmater studies. The indexs run from 1:size_x and 1:size_y where as the study number starts at 0. | |
int | launch_new (const char *name, bool quick=false) |
This launch a code from within this code. Please pass the name of the code to run. | |
void | set_name (const char *name) |
Sets the name of the problem, used for the same data files. | |
string | get_name () |
Allows the problem_name to be accessed. | |
fstream & | get_data_file () |
Allows the problem_name to be accessed. | |
fstream & | get_stat_file () |
Allows the problem_name to be accessed. | |
fstream & | get_fstat_file () |
Allows the problem_name to be accessed. | |
fstream & | get_ene_file () |
Allows the problem_name to be accessed. | |
void | set_fstat_filename (string filename) |
void | set_data_filename (string filename) |
void | set_stat_filename (string filename) |
void | set_ene_filename (string filename) |
void | set_fstat_filename () |
void | set_data_filename () |
void | set_stat_filename () |
void | set_ene_filename () |
string | get_fstat_filename () |
string | get_data_filename () |
string | get_stat_filename () |
string | get_ene_filename () |
void | set_step_size (unsigned int new_) |
unsigned int | get_step_size () |
void | set_options_fstat (unsigned int new_) |
set and get for file options | |
unsigned int | get_options_fstat (void) |
void | set_options_data (unsigned int new_) |
unsigned int | get_options_data (void) |
void | set_options_stat (unsigned int new_) |
unsigned int | get_options_stat (void) |
void | set_options_restart (unsigned int new_) |
unsigned int | get_options_restart (void) |
void | set_options_ene (unsigned int new_) |
unsigned int | get_options_ene (void) |
bool | open_file (fstream &file, string filename, unsigned int options, fstream::openmode mode) |
bool | open_fstat_file (fstream::openmode mode=fstream::out) |
bool | open_data_file (fstream::openmode mode=fstream::out) |
bool | open_stat_file (fstream::openmode mode=fstream::out) |
bool | open_ene_file (fstream::openmode mode=fstream::out) |
bool | open_counted_file (fstream &file, string filenameNoCount, fstream::openmode mode) |
opens file needed if data is written in multiple files | |
bool | increase_counter_fstat (fstream::openmode mode) |
bool | increase_counter_data (fstream::openmode mode) |
bool | increase_counter_stat (fstream::openmode mode) |
bool | increase_counter_ene (fstream::openmode mode) |
void | set_file_counter (int new_) |
int | get_file_counter () |
Protected Attributes | |
stringstream | problem_name |
Stores the problem_name. | |
stringstream | data_filename |
These store the save file names, by default they are derived from problem_name. | |
stringstream | stat_filename |
stringstream | fstat_filename |
stringstream | ene_filename |
fstream | data_file |
Stream used for data files. | |
fstream | stat_file |
fstream | fstat_file |
fstream | ene_file |
unsigned int | options_fstat |
Indicators if files are created or not 0: file will not be created 1: file will be written in one file 2: file will be written in multiple files. | |
unsigned int | options_data |
unsigned int | options_stat |
unsigned int | options_ene |
unsigned int | options_restart |
unsigned int | file_counter |
Counter needed if file will be written in multiple files. | |
unsigned int | step_size |
Private Attributes | |
int | counter |
The stores the run number for saving. |
Here are the rounties to use a counter file to store run numbers.
All my codes do this so I expect this rounties will be used often. So this saves my coping the same routine over and over again
STD_save::STD_save | ( | ) | [inline] |
Default constructor: sets the counter to 0 (i.e. no number will be included).
{ constructor(); #ifdef CONSTUCTOR_OUTPUT cerr << "STD_save() finished"<<endl; #endif }
STD_save::STD_save | ( | STD_save & | other | ) | [inline] |
Copy constructor.
References get_counter(), get_name(), get_options_data(), get_options_ene(), get_options_fstat(), get_options_restart(), and get_options_stat().
{ constructor(); counter = other.get_counter(); problem_name.str(other.get_name()); set_options_fstat(other.get_options_fstat()); set_options_data(other.get_options_data()); set_options_ene(other.get_options_ene()); set_options_stat(other.get_options_stat()); set_options_restart(other.get_options_restart()); #ifdef CONSTUCTOR_OUTPUT cerr << "STD_save(STD_save& other) finished"<<endl; #endif };
void STD_save::auto_number | ( | ) | [inline] |
{ set_counter_from_file(); inc_counter_in_file();}
void STD_save::constructor | ( | ) | [inline] |
Reimplemented in HGRID_base, ChuteWithHopper, Chute, HGRID_3D, MD, HGRID_2D, StatisticsVector< T >, and ChuteBottom.
{ counter=0; set_options_restart(1); set_options_fstat(1); set_options_ene(1); set_options_data(1); set_options_stat(1); file_counter = 0; step_size = 1; data_file.precision(13); fstat_file.precision(13); ene_file.precision(13); stat_file.precision(5); stat_file.setf(ios::left); }
bool STD_save::FileExists | ( | std::string | strFilename | ) |
Function to check if a file exists, is used to check if a run has already need done.
This is a FileExist routine, which is used to test if a run have already need preformed, allows me to plug holes in parm studies.
{ struct stat stFileInfo; bool blnReturn; int intStat; // Attempt to get the file attributes intStat = stat(strFilename.c_str(),&stFileInfo); if(intStat == 0) { // We were able to get the file attributes // so the file obviously exists. blnReturn = true; } else { // We were not able to get the file attributes. // This may mean that we don't have permission to // access the folder which contains this file. If you // need to do that level of checking, lookup the // return values of stat which will give you // more details on why stat failed. blnReturn = false; } return(blnReturn); }
int STD_save::get_counter | ( | ) |
This returns the current value of the counter.
Referenced by MD::solve(), and STD_save().
{ return(counter); }
fstream& STD_save::get_data_file | ( | ) | [inline] |
Allows the problem_name to be accessed.
{return data_file;}
string STD_save::get_data_filename | ( | ) | [inline] |
Referenced by MD::find_next_data_file().
{return data_filename.str();}
fstream& STD_save::get_ene_file | ( | ) | [inline] |
Allows the problem_name to be accessed.
{return ene_file;}
string STD_save::get_ene_filename | ( | ) | [inline] |
{return ene_filename.str();}
int STD_save::get_file_counter | ( | ) | [inline] |
Referenced by MD::find_next_data_file().
{return file_counter;}
fstream& STD_save::get_fstat_file | ( | ) | [inline] |
Allows the problem_name to be accessed.
{return fstat_file;}
string STD_save::get_fstat_filename | ( | ) | [inline] |
{return fstat_filename.str();}
string STD_save::get_name | ( | ) | [inline] |
Allows the problem_name to be accessed.
Referenced by MD::readNextArgument(), and STD_save().
{return problem_name.str();}
vector< int > STD_save::get_numbers | ( | int | size_x, |
int | size_y | ||
) |
This turns a counter into two indexs for doing parmater studies. The indexs run from 1:size_x and 1:size_y where as the study number starts at 0.
This turns the counter into a two index numbers for doing parmeter studies///.
{ vector<int> temp(3); int counter=get_counter(); int study_size = size_x*size_y; int study_num=(counter-1)/study_size; counter=counter-study_size*study_num; int i=((counter-1)%size_x)+1; int j=(counter-i)/size_x+1; temp[0]=study_num; temp[1]=i; temp[2]=j; return(temp); }
unsigned int STD_save::get_options_data | ( | void | ) | [inline] |
Referenced by MD::find_next_data_file(), MD::load_from_data_file(), MD::read_next_from_data_file(), MD::solve(), and STD_save().
{return options_data;}
unsigned int STD_save::get_options_ene | ( | void | ) | [inline] |
Referenced by MD::solve(), and STD_save().
{return options_ene;}
unsigned int STD_save::get_options_fstat | ( | void | ) | [inline] |
Referenced by MD::solve(), and STD_save().
{return options_fstat;}
unsigned int STD_save::get_options_restart | ( | void | ) | [inline] |
Referenced by MD::solve(), and STD_save().
{return options_restart;}
unsigned int STD_save::get_options_stat | ( | void | ) | [inline] |
Referenced by MD::solve(), and STD_save().
{return options_stat;}
fstream& STD_save::get_stat_file | ( | ) | [inline] |
Allows the problem_name to be accessed.
{return stat_file;}
string STD_save::get_stat_filename | ( | ) | [inline] |
{return stat_filename.str();}
unsigned int STD_save::get_step_size | ( | ) | [inline] |
{return step_size;}
void STD_save::inc_counter_in_file | ( | ) |
Increament the counter value stored in the file_counter by 1 and store the new value.
{ fstream counter_file, counter_file2; int temp_counter; counter_file.open("COUNTER_DONOTDEL",ios::in); if (counter_file.fail()) { fprintf(stderr, "\n\n\tERROR :: Counter File NOT found, please re-create\n\n"); counter_file.close(); exit(0); } counter_file >> temp_counter; counter_file.close(); temp_counter++; counter_file2.open("COUNTER_DONOTDEL",ios::out); if (counter_file2.fail()) { fprintf(stderr, "\n\n\tERROR :: Counter File NOT found, please re-create2\n\n"); counter_file2.close(); exit(0); } counter_file2 << temp_counter; counter_file2.close(); }
bool STD_save::increase_counter_data | ( | fstream::openmode | mode | ) | [inline] |
Referenced by MD::find_next_data_file(), MD::read_next_from_data_file(), and MD::solve().
{ return open_counted_file(data_file, data_filename.str(), mode); }
bool STD_save::increase_counter_ene | ( | fstream::openmode | mode | ) | [inline] |
Referenced by MD::solve().
{ file_counter -= step_size; return open_counted_file(ene_file, ene_filename.str(), mode); }
bool STD_save::increase_counter_fstat | ( | fstream::openmode | mode | ) | [inline] |
Referenced by MD::solve().
{ file_counter -= step_size; return open_counted_file(fstat_file, fstat_filename.str(), mode); }
bool STD_save::increase_counter_stat | ( | fstream::openmode | mode | ) | [inline] |
Referenced by MD::solve().
{ file_counter -= step_size; return open_counted_file(stat_file, stat_filename.str(), mode); }
virtual void STD_save::info | ( | ) | [inline, virtual] |
int STD_save::launch_new | ( | const char * | name, |
bool | quick = false |
||
) |
This launch a code from within this code. Please pass the name of the code to run.
This launch a new program with the name passed///.
todo{Do something with the resulting integer (to remove compilation warning)}
{ stringstream com(""); if (quick) { com << "../sc/run " << name << " dsilent&"; } else { com << "../sc/run " << name << " delay&"; } return system(com.str().c_str()); }
bool STD_save::open_counted_file | ( | fstream & | file, |
string | filenameNoCount, | ||
fstream::openmode | mode | ||
) | [inline] |
opens file needed if data is written in multiple files
{ //create filename stringstream filename; filename << filenameNoCount << "."; if (file_counter<1000) filename << "0"; if (file_counter<100) filename << "0"; if (file_counter<10) filename << "0"; filename << file_counter; //close old file if (file.is_open()) file.close(); //open new file file.open(filename.str().c_str(), mode); if (!file.is_open()) {cerr << "Error in opening " << filename.str() << endl; return false;} //else cout << "open(" << mode << ") " << filename.str() << endl; //increase counter file_counter += step_size; return true; }
bool STD_save::open_data_file | ( | fstream::openmode | mode = fstream::out | ) | [inline] |
Referenced by MD::solve().
{ return open_file (data_file, data_filename.str(), get_options_data(), mode); }
bool STD_save::open_ene_file | ( | fstream::openmode | mode = fstream::out | ) | [inline] |
Referenced by MD::solve().
{ return open_file (ene_file, ene_filename.str(), get_options_ene(), mode); }
bool STD_save::open_file | ( | fstream & | file, |
string | filename, | ||
unsigned int | options, | ||
fstream::openmode | mode | ||
) | [inline] |
{ if (options==1) { //cout << "open " << filename << endl; file.open( filename.c_str(), mode); if (file.fail()) return false; } return true; }
bool STD_save::open_fstat_file | ( | fstream::openmode | mode = fstream::out | ) | [inline] |
Referenced by MD::solve().
{ return open_file (fstat_file, fstat_filename.str(), get_options_fstat(), mode); }
bool STD_save::open_stat_file | ( | fstream::openmode | mode = fstream::out | ) | [inline] |
{ return open_file (stat_file, stat_filename.str(), get_options_stat(), mode); }
int STD_save::read_run_num_from_file | ( | ) |
Read rom the counter file the counter.
{ int counter; FILE *counter_file; if ((counter_file=fopen("COUNTER_DONOTDEL", "r+"))==NULL) { //counter file not found if ((counter_file=fopen("COUNTER_DONOTDEL", "w"))==NULL) { //counter file could not be created fprintf(stderr, "\n\n\tERROR :: Counter File NOT found, please re-create\n\n"); fclose(counter_file); exit(-1); } else { //counter file sucessfully created fprintf(counter_file, "1"); fprintf(stderr, "Counter File created\n"); fclose(counter_file); return 1; } } else { //counter file sucessfully opened if (fscanf(counter_file,"%d",&counter)!=1) { //Something with reading went wrong fprintf(stderr, "\n\n\tERROR :: Counter File found, but something went wrong with reading it\n\n"); fclose(counter_file); exit(-1); } else { fclose(counter_file); return counter; } } }
void STD_save::save_info_to_disk | ( | ) |
Saves the information generated by info to disk in a file.
This save the information file to disk my redirection the cout stream and calling the normal info call///.
{ fstream file; //set up a string stream stringstream filename; //Write info.counter to this stream filename << "info." << counter; //open a file with this name. This has to be a c string, hence the rahter convoluted syntax. file.open((filename.str()).c_str(),ios::out); //Make a copy of where the current output buffer is pointing streambuf *temp = cout.rdbuf(); cout.rdbuf(file.rdbuf()); info(); file.close(); //Return the output buffer back to were it was before. cout.rdbuf(temp); }
void STD_save::set_counter | ( | int | new_counter | ) |
This set the counter, overriding the defaults.
Referenced by MD::readNextArgument().
{ counter=new_counter; }
void STD_save::set_counter_from_file | ( | ) |
Sets the counter based on the current number stored in the counter file.
{ set_counter(read_run_num_from_file()); }
void STD_save::set_data_filename | ( | string | filename | ) | [inline] |
{data_filename.str(""); data_filename << filename;}
void STD_save::set_data_filename | ( | ) | [inline] |
Referenced by MD::solve().
{data_filename.str(""); data_filename << problem_name.str().c_str() << ".data";}
void STD_save::set_ene_filename | ( | string | filename | ) | [inline] |
{ene_filename.str(""); ene_filename << filename;}
void STD_save::set_ene_filename | ( | ) | [inline] |
Referenced by MD::solve().
{ene_filename.str(""); ene_filename << problem_name.str().c_str() << ".ene";}
void STD_save::set_file_counter | ( | int | new_ | ) | [inline] |
Referenced by MD::find_next_data_file().
{file_counter = new_;}
void STD_save::set_fstat_filename | ( | string | filename | ) | [inline] |
{fstat_filename.str(""); fstat_filename << filename;}
void STD_save::set_fstat_filename | ( | ) | [inline] |
Referenced by MD::solve().
{fstat_filename.str(""); fstat_filename << problem_name.str().c_str() << ".fstat";}
void STD_save::set_name | ( | const char * | name | ) | [inline] |
Sets the name of the problem, used for the same data files.
Reimplemented in MD.
{problem_name.str(""); problem_name << name;}
void STD_save::set_options_data | ( | unsigned int | new_ | ) | [inline] |
Referenced by ChuteBottom::constructor(), MD::load_from_data_file(), and MD::readNextArgument().
{options_data = new_;}
void STD_save::set_options_ene | ( | unsigned int | new_ | ) | [inline] |
Referenced by MD::readNextArgument().
{options_ene = new_;}
void STD_save::set_options_fstat | ( | unsigned int | new_ | ) | [inline] |
set and get for file options
Referenced by ChuteBottom::constructor(), and MD::readNextArgument().
{options_fstat = new_;}
void STD_save::set_options_restart | ( | unsigned int | new_ | ) | [inline] |
Referenced by ChuteBottom::constructor(), and MD::readNextArgument().
{options_restart = new_;}
void STD_save::set_options_stat | ( | unsigned int | new_ | ) | [inline] |
Referenced by MD::readNextArgument().
{options_stat = new_;}
void STD_save::set_stat_filename | ( | string | filename | ) | [inline] |
{stat_filename.str(""); stat_filename << filename;}
void STD_save::set_stat_filename | ( | ) | [inline] |
{stat_filename.str(""); stat_filename << problem_name.str().c_str() << ".stat";}
void STD_save::set_step_size | ( | unsigned int | new_ | ) | [inline] |
{step_size= new_;}
int STD_save::counter [private] |
The stores the run number for saving.
fstream STD_save::data_file [protected] |
Stream used for data files.
Referenced by MD::find_next_data_file(), MD::load_from_data_file(), MD::output_xballs_data(), MD::read_dim_from_data_file(), MD::read_next_from_data_file(), MD::solve(), and MD::statistics_from_restart_data().
stringstream STD_save::data_filename [protected] |
These store the save file names, by default they are derived from problem_name.
Referenced by MD::read_dim_from_data_file(), and MD::statistics_from_restart_data().
fstream STD_save::ene_file [protected] |
Referenced by MD::output_ene(), MD::solve(), and MD::start_ene().
stringstream STD_save::ene_filename [protected] |
unsigned int STD_save::file_counter [protected] |
Counter needed if file will be written in multiple files.
fstream STD_save::fstat_file [protected] |
stringstream STD_save::fstat_filename [protected] |
unsigned int STD_save::options_data [protected] |
Referenced by MD::load_from_data_file(), MD::print(), MD::read(), MD::read_v1(), MD::read_v2(), MD::write(), and MD::write_v1().
unsigned int STD_save::options_ene [protected] |
Referenced by MD::print(), MD::read(), MD::read_v1(), MD::read_v2(), MD::write(), and MD::write_v1().
unsigned int STD_save::options_fstat [protected] |
Indicators if files are created or not 0: file will not be created 1: file will be written in one file 2: file will be written in multiple files.
Referenced by MD::print(), MD::read(), MD::read_v1(), MD::read_v2(), MD::write(), and MD::write_v1().
unsigned int STD_save::options_restart [protected] |
Referenced by MD::print(), MD::read(), MD::read_v2(), MD::save_restart_data(), and MD::write().
unsigned int STD_save::options_stat [protected] |
stringstream STD_save::problem_name [protected] |
Stores the problem_name.
Referenced by MD::constructor(), MD::load_restart_data(), MD::print(), MD::read(), MD::read_v1(), MD::save_restart_data(), MD::solve(), MD::write(), and MD::write_v1().
fstream STD_save::stat_file [protected] |
Referenced by MD::statistics_from_restart_data().
stringstream STD_save::stat_filename [protected] |
Referenced by MD::statistics_from_restart_data().
unsigned int STD_save::step_size [protected] |