MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
STD_save Class Reference

Here are the rounties to use a counter file to store run numbers. More...

#include <STD_save.h>

+ Inheritance diagram for STD_save:

Public Member Functions

 STD_save ()
 Default constructor: sets the counter to 0 (i.e. no number will be included). More...
 
 STD_save (STD_save &other)
 Copy constructor. More...
 
void constructor ()
 
void inc_counter_in_file ()
 Increament the counter value stored in the file_counter by 1 and store the new value. More...
 
int read_run_num_from_file ()
 Read rom the counter file the counter. More...
 
void set_counter_from_file ()
 Sets the counter based on the current number stored in the counter file. More...
 
void save_info_to_disk ()
 Saves the information generated by info to disk in a file. More...
 
void set_counter (int new_counter)
 This set the counter, overriding the defaults. More...
 
int get_counter ()
 This returns the current value of the counter. More...
 
virtual void info ()
 Set up a virtual info this will be provided from the inhertiance. More...
 
bool FileExists (std::string strFilename)
 Function to check if a file exists, is used to check if a run has already need done. More...
 
void auto_number ()
 
std::vector< intget_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. More...
 
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. More...
 
void set_name (const char *name)
 Sets the name of the problem, used for the same data files. More...
 
std::string get_name ()
 Allows the problem_name to be accessed. More...
 
std::fstream & get_data_file ()
 Allows the problem_name to be accessed. More...
 
std::fstream & get_stat_file ()
 Allows the problem_name to be accessed. More...
 
std::fstream & get_fstat_file ()
 Allows the problem_name to be accessed. More...
 
std::fstream & get_ene_file ()
 Allows the problem_name to be accessed. More...
 
void set_fstat_filename (std::string filename)
 
void set_data_filename (std::string filename)
 
void set_stat_filename (std::string filename)
 
void set_ene_filename (std::string filename)
 
void set_fstat_filename ()
 
void set_data_filename ()
 
void set_stat_filename ()
 
void set_ene_filename ()
 
std::string get_fstat_filename ()
 
std::string get_data_filename ()
 
std::string get_stat_filename ()
 
std::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 More...
 
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 (std::fstream &file, std::string filename, unsigned int options, std::fstream::openmode mode)
 
bool open_fstat_file (std::fstream::openmode mode=std::fstream::out)
 
bool open_data_file (std::fstream::openmode mode=std::fstream::out)
 
bool open_stat_file (std::fstream::openmode mode=std::fstream::out)
 
bool open_ene_file (std::fstream::openmode mode=std::fstream::out)
 
bool open_counted_file (std::fstream &file, std::string filenameNoCount, std::fstream::openmode mode)
 opens file needed if data is written in multiple files More...
 
bool increase_counter_fstat (std::fstream::openmode mode)
 
bool increase_counter_data (std::fstream::openmode mode)
 
bool increase_counter_stat (std::fstream::openmode mode)
 
bool increase_counter_ene (std::fstream::openmode mode)
 
void set_file_counter (int new_)
 
int get_file_counter ()
 

Protected Attributes

std::stringstream problem_name
 Stores the problem_name. More...
 
std::stringstream data_filename
 These store the save file names, by default they are derived from problem_name. More...
 
std::stringstream stat_filename
 
std::stringstream fstat_filename
 
std::stringstream ene_filename
 
std::fstream data_file
 Stream used for data files. More...
 
std::fstream stat_file
 
std::fstream fstat_file
 
std::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. More...
 
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. More...
 
unsigned int step_size
 

Private Attributes

int counter
 The stores the run number for saving. More...
 

Detailed Description

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

Definition at line 48 of file STD_save.h.

Constructor & Destructor Documentation

STD_save::STD_save ( )
inline

Default constructor: sets the counter to 0 (i.e. no number will be included).

Definition at line 53 of file STD_save.h.

References constructor().

53  {
54  constructor();
55  #ifdef CONSTUCTOR_OUTPUT
56  std::cerr << "STD_save() finished"<<std::endl;
57  #endif
58 }
void constructor()
Definition: STD_save.h:75
STD_save::STD_save ( STD_save other)
inline

Copy constructor.

Definition at line 61 of file STD_save.h.

References constructor(), counter, get_counter(), get_name(), get_options_data(), get_options_ene(), get_options_fstat(), get_options_restart(), get_options_stat(), problem_name, set_options_data(), set_options_ene(), set_options_fstat(), set_options_restart(), and set_options_stat().

61  {
62  constructor();
63  counter = other.get_counter();
64  problem_name.str(other.get_name());
70  #ifdef CONSTUCTOR_OUTPUT
71  std::cerr << "STD_save(STD_save& other) finished"<<std::endl;
72  #endif
73 };
int counter
The stores the run number for saving.
Definition: STD_save.h:238
void set_options_data(unsigned int new_)
Definition: STD_save.h:161
void set_options_restart(unsigned int new_)
Definition: STD_save.h:167
unsigned int get_options_fstat(void)
Definition: STD_save.h:159
std::stringstream problem_name
Stores the problem_name.
Definition: STD_save.h:242
void set_options_fstat(unsigned int new_)
set and get for file options
Definition: STD_save.h:158
unsigned int get_options_data(void)
Definition: STD_save.h:162
unsigned int get_options_ene(void)
Definition: STD_save.h:171
unsigned int get_options_stat(void)
Definition: STD_save.h:165
unsigned int get_options_restart(void)
Definition: STD_save.h:168
int get_counter()
This returns the current value of the counter.
Definition: STD_save.cc:85
void constructor()
Definition: STD_save.h:75
std::string get_name()
Allows the problem_name to be accessed.
Definition: STD_save.h:127
void set_options_stat(unsigned int new_)
Definition: STD_save.h:164
void set_options_ene(unsigned int new_)
Definition: STD_save.h:170

Member Function Documentation

void STD_save::auto_number ( )
inline

Definition at line 116 of file STD_save.h.

References inc_counter_in_file(), and set_counter_from_file().

Referenced by MD::readNextArgument().

void set_counter_from_file()
Sets the counter based on the current number stored in the counter file.
Definition: STD_save.cc:92
void inc_counter_in_file()
Increament the counter value stored in the file_counter by 1 and store the new value.
Definition: STD_save.cc:100
void STD_save::constructor ( )
inline

Definition at line 75 of file STD_save.h.

References counter, data_file, ene_file, file_counter, fstat_file, set_options_data(), set_options_ene(), set_options_fstat(), set_options_restart(), set_options_stat(), stat_file, and step_size.

Referenced by STD_save().

75  {
76  counter=0;
79  set_options_ene(1);
82  file_counter = 0;
83  step_size = 1;
84  data_file.precision(13);
85  fstat_file.precision(13);
86  ene_file.precision(13);
87  stat_file.precision(5);
88  stat_file.setf(std::ios::left);
89 }
unsigned int file_counter
Counter needed if file will be written in multiple files.
Definition: STD_save.h:269
std::fstream fstat_file
Definition: STD_save.h:254
std::fstream stat_file
Definition: STD_save.h:253
int counter
The stores the run number for saving.
Definition: STD_save.h:238
void set_options_data(unsigned int new_)
Definition: STD_save.h:161
void set_options_restart(unsigned int new_)
Definition: STD_save.h:167
void set_options_fstat(unsigned int new_)
set and get for file options
Definition: STD_save.h:158
std::fstream data_file
Stream used for data files.
Definition: STD_save.h:252
unsigned int step_size
Definition: STD_save.h:270
void set_options_stat(unsigned int new_)
Definition: STD_save.h:164
std::fstream ene_file
Definition: STD_save.h:255
void set_options_ene(unsigned int new_)
Definition: STD_save.h:170
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.

Definition at line 163 of file STD_save.cc.

164 {
165  struct stat stFileInfo;
166  bool blnReturn;
167  int intStat;
168 
169  // Attempt to get the file attributes
170 
171  intStat = stat(strFilename.c_str(),&stFileInfo);
172  if(intStat == 0) {
173  // We were able to get the file attributes
174  // so the file obviously exists.
175  blnReturn = true;
176  } else {
177  // We were not able to get the file attributes.
178  // This may mean that we don't have permission to
179  // access the folder which contains this file. If you
180  // need to do that level of checking, lookup the
181  // return values of stat which will give you
182  // more details on why stat failed.
183  blnReturn = false;
184  }
185 
186  return(blnReturn);
187 }
int STD_save::get_counter ( )

This returns the current value of the counter.

Definition at line 85 of file STD_save.cc.

References counter.

Referenced by get_numbers(), MD::solve(), and STD_save().

86 {
87 return(counter);
88 }
int counter
The stores the run number for saving.
Definition: STD_save.h:238
std::fstream& STD_save::get_data_file ( )
inline

Allows the problem_name to be accessed.

Definition at line 130 of file STD_save.h.

References data_file.

130 {return data_file;}
std::fstream data_file
Stream used for data files.
Definition: STD_save.h:252
std::string STD_save::get_data_filename ( )
inline

Definition at line 149 of file STD_save.h.

References data_filename.

Referenced by MD::find_next_data_file().

149 {return data_filename.str();}
std::stringstream data_filename
These store the save file names, by default they are derived from problem_name.
Definition: STD_save.h:246
std::fstream& STD_save::get_ene_file ( )
inline

Allows the problem_name to be accessed.

Definition at line 136 of file STD_save.h.

References ene_file.

136 {return ene_file;}
std::fstream ene_file
Definition: STD_save.h:255
std::string STD_save::get_ene_filename ( )
inline

Definition at line 151 of file STD_save.h.

References ene_filename.

151 {return ene_filename.str();}
std::stringstream ene_filename
Definition: STD_save.h:249
int STD_save::get_file_counter ( )
inline

Definition at line 234 of file STD_save.h.

References file_counter.

Referenced by MD::find_next_data_file().

234 {return file_counter;}
unsigned int file_counter
Counter needed if file will be written in multiple files.
Definition: STD_save.h:269
std::fstream& STD_save::get_fstat_file ( )
inline

Allows the problem_name to be accessed.

Definition at line 134 of file STD_save.h.

References fstat_file.

134 {return fstat_file;}
std::fstream fstat_file
Definition: STD_save.h:254
std::string STD_save::get_fstat_filename ( )
inline

Definition at line 148 of file STD_save.h.

References fstat_filename.

148 {return fstat_filename.str();}
std::stringstream fstat_filename
Definition: STD_save.h:248
std::string STD_save::get_name ( )
inline

Allows the problem_name to be accessed.

Definition at line 127 of file STD_save.h.

References problem_name.

Referenced by MD::readNextArgument(), and STD_save().

127 {return problem_name.str();}
std::stringstream problem_name
Stores the problem_name.
Definition: STD_save.h:242
std::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///.

Definition at line 194 of file STD_save.cc.

References counter, and get_counter().

195 {
196 std::vector<int> temp(3);
197 
198 int counter=get_counter();
199 
200 int study_size = size_x*size_y;
201 
202 int study_num=(counter-1)/study_size;
203 
204 counter=counter-study_size*study_num;
205 int i=((counter-1)%size_x)+1;
206 int j=(counter-i)/size_x+1;
207 std::cout<<"Counter: "<<counter<<" i: "<<i<<" j: "<<j<<std::endl;
208 
209 temp[0]=study_num;
210 temp[1]=i;
211 temp[2]=j;
212 
213 return(temp);
214 }
int counter
The stores the run number for saving.
Definition: STD_save.h:238
int get_counter()
This returns the current value of the counter.
Definition: STD_save.cc:85
unsigned int STD_save::get_options_data ( void  )
inline
unsigned int STD_save::get_options_ene ( void  )
inline

Definition at line 171 of file STD_save.h.

References options_ene.

Referenced by open_ene_file(), MD::solve(), and STD_save().

171 {return options_ene;}
unsigned int options_ene
Definition: STD_save.h:265
unsigned int STD_save::get_options_fstat ( void  )
inline

Definition at line 159 of file STD_save.h.

References options_fstat.

Referenced by open_fstat_file(), MD::solve(), and STD_save().

159 {return options_fstat;}
unsigned int options_fstat
Indicators if files are created or not 0: file will not be created 1: file will be written in one fil...
Definition: STD_save.h:262
unsigned int STD_save::get_options_restart ( void  )
inline

Definition at line 168 of file STD_save.h.

References options_restart.

Referenced by MD::solve(), and STD_save().

168 {return options_restart;}
unsigned int options_restart
Definition: STD_save.h:266
unsigned int STD_save::get_options_stat ( void  )
inline

Definition at line 165 of file STD_save.h.

References options_stat.

Referenced by open_stat_file(), MD::solve(), and STD_save().

165 {return options_stat;}
unsigned int options_stat
Definition: STD_save.h:264
std::fstream& STD_save::get_stat_file ( )
inline

Allows the problem_name to be accessed.

Definition at line 132 of file STD_save.h.

References stat_file.

132 {return stat_file;}
std::fstream stat_file
Definition: STD_save.h:253
std::string STD_save::get_stat_filename ( )
inline

Definition at line 150 of file STD_save.h.

References stat_filename.

150 {return stat_filename.str();}
std::stringstream stat_filename
Definition: STD_save.h:247
unsigned int STD_save::get_step_size ( )
inline

Definition at line 155 of file STD_save.h.

References step_size.

155 {return step_size;}
unsigned int step_size
Definition: STD_save.h:270
void STD_save::inc_counter_in_file ( )

Increament the counter value stored in the file_counter by 1 and store the new value.

Definition at line 100 of file STD_save.cc.

Referenced by auto_number().

101 {
102 std::fstream counter_file, counter_file2;
103 int temp_counter;
104 
105 counter_file.open("COUNTER_DONOTDEL",std::ios::in);
106 if (counter_file.fail())
107  {
108  fprintf(stderr, "\n\n\tERROR :: Counter File NOT found, please re-create\n\n");
109  counter_file.close();
110  exit(0);
111  }
112 
113 counter_file >> temp_counter;
114 counter_file.close();
115 
116 
117 temp_counter++;
118 
119 
120 counter_file2.open("COUNTER_DONOTDEL",std::ios::out);
121 if (counter_file2.fail())
122  {
123  fprintf(stderr, "\n\n\tERROR :: Counter File NOT found, please re-create2\n\n");
124  counter_file2.close();
125  exit(0);
126  }
127 
128 
129 
130 counter_file2 << temp_counter;
131 
132 counter_file2.close();
133 
134 }
bool STD_save::increase_counter_data ( std::fstream::openmode  mode)
inline

Definition at line 221 of file STD_save.h.

References data_file, data_filename, and open_counted_file().

Referenced by MD::find_next_data_file(), MD::read_next_from_data_file(), and MD::solve().

221  {
222  return open_counted_file(data_file, data_filename.str(), mode);
223 }
std::stringstream data_filename
These store the save file names, by default they are derived from problem_name.
Definition: STD_save.h:246
bool open_counted_file(std::fstream &file, std::string filenameNoCount, std::fstream::openmode mode)
opens file needed if data is written in multiple files
Definition: STD_save.h:198
std::fstream data_file
Stream used for data files.
Definition: STD_save.h:252
bool STD_save::increase_counter_ene ( std::fstream::openmode  mode)
inline

Definition at line 228 of file STD_save.h.

References ene_file, ene_filename, file_counter, open_counted_file(), and step_size.

Referenced by MD::solve().

228  {
230  return open_counted_file(ene_file, ene_filename.str(), mode);
231 }
unsigned int file_counter
Counter needed if file will be written in multiple files.
Definition: STD_save.h:269
bool open_counted_file(std::fstream &file, std::string filenameNoCount, std::fstream::openmode mode)
opens file needed if data is written in multiple files
Definition: STD_save.h:198
std::stringstream ene_filename
Definition: STD_save.h:249
unsigned int step_size
Definition: STD_save.h:270
std::fstream ene_file
Definition: STD_save.h:255
bool STD_save::increase_counter_fstat ( std::fstream::openmode  mode)
inline

Definition at line 217 of file STD_save.h.

References file_counter, fstat_file, fstat_filename, open_counted_file(), and step_size.

Referenced by MD::solve().

217  {
219  return open_counted_file(fstat_file, fstat_filename.str(), mode);
220 }
unsigned int file_counter
Counter needed if file will be written in multiple files.
Definition: STD_save.h:269
std::fstream fstat_file
Definition: STD_save.h:254
bool open_counted_file(std::fstream &file, std::string filenameNoCount, std::fstream::openmode mode)
opens file needed if data is written in multiple files
Definition: STD_save.h:198
unsigned int step_size
Definition: STD_save.h:270
std::stringstream fstat_filename
Definition: STD_save.h:248
bool STD_save::increase_counter_stat ( std::fstream::openmode  mode)
inline

Definition at line 224 of file STD_save.h.

References file_counter, open_counted_file(), stat_file, stat_filename, and step_size.

Referenced by MD::solve().

224  {
226  return open_counted_file(stat_file, stat_filename.str(), mode);
227 }
unsigned int file_counter
Counter needed if file will be written in multiple files.
Definition: STD_save.h:269
std::stringstream stat_filename
Definition: STD_save.h:247
std::fstream stat_file
Definition: STD_save.h:253
bool open_counted_file(std::fstream &file, std::string filenameNoCount, std::fstream::openmode mode)
opens file needed if data is written in multiple files
Definition: STD_save.h:198
unsigned int step_size
Definition: STD_save.h:270
virtual void STD_save::info ( )
inlinevirtual

Set up a virtual info this will be provided from the inhertiance.

Reimplemented in MD.

Definition at line 111 of file STD_save.h.

Referenced by save_info_to_disk().

111 {}
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)}

Definition at line 219 of file STD_save.cc.

220 {
221  std::stringstream com("");
222 
223  if (quick)
224  {
225  com << "../sc/run " << name << " &";
226  }
227  else
228  {
229  com << "../sc/run " << name << " &";
230  }
231 
233  return system(com.str().c_str());
234 }
bool STD_save::open_counted_file ( std::fstream &  file,
std::string  filenameNoCount,
std::fstream::openmode  mode 
)
inline

opens file needed if data is written in multiple files

Definition at line 198 of file STD_save.h.

References file_counter, and step_size.

Referenced by increase_counter_data(), increase_counter_ene(), increase_counter_fstat(), and increase_counter_stat().

198  {
199  //create filename
200  std::stringstream filename;
201  filename << filenameNoCount << ".";
202  if (file_counter<1000) filename << "0";
203  if (file_counter<100) filename << "0";
204  if (file_counter<10) filename << "0";
205  filename << file_counter;
206  //close old file
207  if (file.is_open()) file.close();
208  //open new file
209  file.open(filename.str().c_str(), mode);
210  if (!file.is_open()) {std::cerr << "Error in opening " << filename.str() << std::endl; return false;}
211  //else std::cout << "open(" << mode << ") " << filename.str() << std::endl;
212  //increase counter
213  file_counter += step_size;
214  return true;
215 }
unsigned int file_counter
Counter needed if file will be written in multiple files.
Definition: STD_save.h:269
unsigned int step_size
Definition: STD_save.h:270
bool STD_save::open_data_file ( std::fstream::openmode  mode = std::fstream::out)
inline

Definition at line 187 of file STD_save.h.

References data_file, data_filename, get_options_data(), and open_file().

Referenced by MD::solve().

187  {
188  return open_file (data_file, data_filename.str(), get_options_data(), mode);
189 }
bool open_file(std::fstream &file, std::string filename, unsigned int options, std::fstream::openmode mode)
Definition: STD_save.h:174
std::stringstream data_filename
These store the save file names, by default they are derived from problem_name.
Definition: STD_save.h:246
std::fstream data_file
Stream used for data files.
Definition: STD_save.h:252
unsigned int get_options_data(void)
Definition: STD_save.h:162
bool STD_save::open_ene_file ( std::fstream::openmode  mode = std::fstream::out)
inline

Definition at line 193 of file STD_save.h.

References ene_file, ene_filename, get_options_ene(), and open_file().

Referenced by MD::solve().

193  {
194  return open_file (ene_file, ene_filename.str(), get_options_ene(), mode);
195 }
bool open_file(std::fstream &file, std::string filename, unsigned int options, std::fstream::openmode mode)
Definition: STD_save.h:174
std::stringstream ene_filename
Definition: STD_save.h:249
unsigned int get_options_ene(void)
Definition: STD_save.h:171
std::fstream ene_file
Definition: STD_save.h:255
bool STD_save::open_file ( std::fstream &  file,
std::string  filename,
unsigned int  options,
std::fstream::openmode  mode 
)
inline

Definition at line 174 of file STD_save.h.

Referenced by open_data_file(), open_ene_file(), open_fstat_file(), and open_stat_file().

175 {
176  if (options==1) {
177  //std::cout << "open " << filename << std::endl;
178  file.open( filename.c_str(), mode);
179  if (file.fail()) return false;
180  }
181  return true;
182 }
bool STD_save::open_fstat_file ( std::fstream::openmode  mode = std::fstream::out)
inline

Definition at line 184 of file STD_save.h.

References fstat_file, fstat_filename, get_options_fstat(), and open_file().

Referenced by MD::solve().

184  {
185  return open_file (fstat_file, fstat_filename.str(), get_options_fstat(), mode);
186 }
std::fstream fstat_file
Definition: STD_save.h:254
bool open_file(std::fstream &file, std::string filename, unsigned int options, std::fstream::openmode mode)
Definition: STD_save.h:174
unsigned int get_options_fstat(void)
Definition: STD_save.h:159
std::stringstream fstat_filename
Definition: STD_save.h:248
bool STD_save::open_stat_file ( std::fstream::openmode  mode = std::fstream::out)
inline

Definition at line 190 of file STD_save.h.

References get_options_stat(), open_file(), stat_file, and stat_filename.

190  {
191  return open_file (stat_file, stat_filename.str(), get_options_stat(), mode);
192 }
std::stringstream stat_filename
Definition: STD_save.h:247
bool open_file(std::fstream &file, std::string filename, unsigned int options, std::fstream::openmode mode)
Definition: STD_save.h:174
std::fstream stat_file
Definition: STD_save.h:253
unsigned int get_options_stat(void)
Definition: STD_save.h:165
int STD_save::read_run_num_from_file ( )

Read rom the counter file the counter.

Definition at line 37 of file STD_save.cc.

References counter.

Referenced by set_counter_from_file().

39 {
40 int counter;
41 
42 
43 FILE *counter_file;
44 if ((counter_file=fopen("COUNTER_DONOTDEL", "r+"))==NULL)
45 {
46  //counter file not found
47  if ((counter_file=fopen("COUNTER_DONOTDEL", "w"))==NULL)
48  {
49  //counter file could not be created
50  fprintf(stderr, "\n\n\tERROR :: Counter File NOT found, please re-create\n\n");
51  fclose(counter_file);
52  exit(-1);
53  } else {
54  //counter file sucessfully created
55  fprintf(counter_file, "1");
56  fprintf(stderr, "Counter File created\n");
57  fclose(counter_file);
58  return 1;
59  }
60 } else {
61  //counter file sucessfully opened
62  if (fscanf(counter_file,"%d",&counter)!=1)
63  {
64  //Something with reading went wrong
65  fprintf(stderr, "\n\n\tERROR :: Counter File found, but something went wrong with reading it\n\n");
66  fclose(counter_file);
67  exit(-1);
68  } else {
69  fclose(counter_file);
70  return counter;
71  }
72 }
73 
74 }
int counter
The stores the run number for saving.
Definition: STD_save.h:238
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 std::cout stream and calling the normal info call///.

Definition at line 139 of file STD_save.cc.

References counter, and info().

140 {
141 std::fstream file;
142 
143 //set up a std::string stream
144 std::stringstream filename;
145 
146 //Write info.counter to this stream
147 filename << "info." << counter;
148 
149 //open a file with this name. This has to be a c std::string, hence the rahter convoluted syntax.
150 file.open((filename.str()).c_str(),std::ios::out);
151 //Make a copy of where the current output buffer is pointing
152 std::streambuf *temp = std::cout.rdbuf();
153 std::cout.rdbuf(file.rdbuf());
154 info();
155 file.close();
156 //Return the output buffer back to were it was before.
157 std::cout.rdbuf(temp);
158 }
int counter
The stores the run number for saving.
Definition: STD_save.h:238
virtual void info()
Set up a virtual info this will be provided from the inhertiance.
Definition: STD_save.h:111
void STD_save::set_counter ( int  new_counter)

This set the counter, overriding the defaults.

Definition at line 78 of file STD_save.cc.

References counter.

Referenced by MD::readNextArgument(), and set_counter_from_file().

79 {
80 counter=new_counter;
81 }
int counter
The stores the run number for saving.
Definition: STD_save.h:238
void STD_save::set_counter_from_file ( )

Sets the counter based on the current number stored in the counter file.

Definition at line 92 of file STD_save.cc.

References read_run_num_from_file(), and set_counter().

Referenced by auto_number().

93 {
95 }
void set_counter(int new_counter)
This set the counter, overriding the defaults.
Definition: STD_save.cc:78
int read_run_num_from_file()
Read rom the counter file the counter.
Definition: STD_save.cc:37
void STD_save::set_data_filename ( std::string  filename)
inline

Definition at line 139 of file STD_save.h.

References data_filename.

139 {data_filename.str(""); data_filename << filename;}
std::stringstream data_filename
These store the save file names, by default they are derived from problem_name.
Definition: STD_save.h:246
void STD_save::set_data_filename ( )
inline

Definition at line 144 of file STD_save.h.

References data_filename, and problem_name.

Referenced by MD::solve().

144 {data_filename.str(""); data_filename << problem_name.str().c_str() << ".data";}
std::stringstream data_filename
These store the save file names, by default they are derived from problem_name.
Definition: STD_save.h:246
std::stringstream problem_name
Stores the problem_name.
Definition: STD_save.h:242
void STD_save::set_ene_filename ( std::string  filename)
inline

Definition at line 141 of file STD_save.h.

References ene_filename.

141 {ene_filename.str(""); ene_filename << filename;}
std::stringstream ene_filename
Definition: STD_save.h:249
void STD_save::set_ene_filename ( )
inline

Definition at line 146 of file STD_save.h.

References ene_filename, and problem_name.

Referenced by MD::solve().

146 {ene_filename.str(""); ene_filename << problem_name.str().c_str() << ".ene";}
std::stringstream problem_name
Stores the problem_name.
Definition: STD_save.h:242
std::stringstream ene_filename
Definition: STD_save.h:249
void STD_save::set_file_counter ( int  new_)
inline

Definition at line 233 of file STD_save.h.

References file_counter.

Referenced by MD::find_next_data_file().

233 {file_counter = new_;}
unsigned int file_counter
Counter needed if file will be written in multiple files.
Definition: STD_save.h:269
void STD_save::set_fstat_filename ( std::string  filename)
inline

Definition at line 138 of file STD_save.h.

References fstat_filename.

138 {fstat_filename.str(""); fstat_filename << filename;}
std::stringstream fstat_filename
Definition: STD_save.h:248
void STD_save::set_fstat_filename ( )
inline

Definition at line 143 of file STD_save.h.

References fstat_filename, and problem_name.

Referenced by MD::solve().

143 {fstat_filename.str(""); fstat_filename << problem_name.str().c_str() << ".fstat";}
std::stringstream problem_name
Stores the problem_name.
Definition: STD_save.h:242
std::stringstream fstat_filename
Definition: STD_save.h:248
void STD_save::set_name ( const char *  name)
inline

Sets the name of the problem, used for the same data files.

Definition at line 125 of file STD_save.h.

References problem_name.

125 {problem_name.str(""); problem_name << name;}
std::stringstream problem_name
Stores the problem_name.
Definition: STD_save.h:242
void STD_save::set_options_data ( unsigned int  new_)
inline

Definition at line 161 of file STD_save.h.

References options_data.

Referenced by ChuteBottom::constructor(), constructor(), MD::load_from_data_file(), MD::readNextArgument(), and STD_save().

161 {options_data = new_;}
unsigned int options_data
Definition: STD_save.h:263
void STD_save::set_options_ene ( unsigned int  new_)
inline

Definition at line 170 of file STD_save.h.

References options_ene.

Referenced by constructor(), MD::readNextArgument(), and STD_save().

170 {options_ene = new_;}
unsigned int options_ene
Definition: STD_save.h:265
void STD_save::set_options_fstat ( unsigned int  new_)
inline

set and get for file options

Definition at line 158 of file STD_save.h.

References options_fstat.

Referenced by ChuteBottom::constructor(), constructor(), MD::readNextArgument(), and STD_save().

158 {options_fstat = new_;}
unsigned int options_fstat
Indicators if files are created or not 0: file will not be created 1: file will be written in one fil...
Definition: STD_save.h:262
void STD_save::set_options_restart ( unsigned int  new_)
inline

Definition at line 167 of file STD_save.h.

References options_restart.

Referenced by ChuteBottom::constructor(), constructor(), MD::readNextArgument(), and STD_save().

167 {options_restart = new_;}
unsigned int options_restart
Definition: STD_save.h:266
void STD_save::set_options_stat ( unsigned int  new_)
inline

Definition at line 164 of file STD_save.h.

References options_stat.

Referenced by constructor(), MD::readNextArgument(), and STD_save().

164 {options_stat = new_;}
unsigned int options_stat
Definition: STD_save.h:264
void STD_save::set_stat_filename ( std::string  filename)
inline

Definition at line 140 of file STD_save.h.

References stat_filename.

140 {stat_filename.str(""); stat_filename << filename;}
std::stringstream stat_filename
Definition: STD_save.h:247
void STD_save::set_stat_filename ( )
inline

Definition at line 145 of file STD_save.h.

References problem_name, and stat_filename.

145 {stat_filename.str(""); stat_filename << problem_name.str().c_str() << ".stat";}
std::stringstream stat_filename
Definition: STD_save.h:247
std::stringstream problem_name
Stores the problem_name.
Definition: STD_save.h:242
void STD_save::set_step_size ( unsigned int  new_)
inline

Definition at line 154 of file STD_save.h.

References step_size.

154 {step_size= new_;}
unsigned int step_size
Definition: STD_save.h:270

Member Data Documentation

int STD_save::counter
private

The stores the run number for saving.

Definition at line 238 of file STD_save.h.

Referenced by constructor(), get_counter(), get_numbers(), read_run_num_from_file(), save_info_to_disk(), set_counter(), and STD_save().

std::stringstream STD_save::data_filename
protected

These store the save file names, by default they are derived from problem_name.

Definition at line 246 of file STD_save.h.

Referenced by MD::create_xballs_script(), get_data_filename(), increase_counter_data(), open_data_file(), MD::read_dim_from_data_file(), set_data_filename(), and MD::statistics_from_restart_data().

std::fstream STD_save::ene_file
protected
std::stringstream STD_save::ene_filename
protected
unsigned int STD_save::file_counter
protected

Counter needed if file will be written in multiple files.

Definition at line 269 of file STD_save.h.

Referenced by constructor(), get_file_counter(), increase_counter_ene(), increase_counter_fstat(), increase_counter_stat(), open_counted_file(), and set_file_counter().

std::stringstream STD_save::fstat_filename
protected
unsigned int STD_save::options_data
protected
unsigned int STD_save::options_ene
protected
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.

Definition at line 262 of file STD_save.h.

Referenced by get_options_fstat(), MD::print(), MD::read(), MD::read_v1(), MD::read_v2(), set_options_fstat(), MD::write(), and MD::write_v1().

unsigned int STD_save::options_restart
protected
unsigned int STD_save::options_stat
protected

Definition at line 264 of file STD_save.h.

Referenced by get_options_stat(), and set_options_stat().

std::fstream STD_save::stat_file
protected
std::stringstream STD_save::stat_filename
protected
unsigned int STD_save::step_size
protected

The documentation for this class was generated from the following files: