MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Files.cc
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 
27 #include <iostream>
28 #include "Files.h"
29 
34 {
35  //constructor();
36  dataFile.getFstream().precision(13);
37  fStatFile.getFstream().precision(13);
38  eneFile.getFstream().precision(13);
39  restartFile.getFstream().precision(15);
40  statFile.getFstream().precision(5);
41  statFile.getFstream().setf(std::ios::left);
42 }
43 
45 {
46 
47 }
52 Files::Files(const Files& other)
53 {
54  //constructor();
55  setName(other.getName());
56 }
61 {
62  return dataFile;
63 }
68 {
69  return eneFile;
70 }
75 {
76  return fStatFile;
77 }
82 {
83  return restartFile;
84 }
89 {
90  return statFile;
91 }
95 const File& Files::getDataFile() const
96 {
97  return dataFile;
98 }
99 
103 const File& Files::getEneFile() const
104 {
105  return eneFile;
106 }
110 const File& Files::getFStatFile() const
111 {
112  return fStatFile;
113 }
118 {
119  return restartFile;
120 }
124 const File& Files::getStatFile() const
125 {
126  return statFile;
127 }
131 const std::string& Files::getName() const
132 {
133  return name_;
134 }
138 void Files::setSaveCount(unsigned int saveCount)
139 {
140  dataFile.setSaveCount(saveCount);
141  fStatFile.setSaveCount(saveCount);
142  restartFile.setSaveCount(saveCount);
143  statFile.setSaveCount(saveCount);
144  eneFile.setSaveCount(saveCount);
145 }
149 void Files::setName(const std::string& name)
150 {
151  name_ = name; // was before this->name_ = name
152  dataFile.setName(name_ + ".data");
153  fStatFile.setName(name_ + ".fstat");
154  restartFile.setName(name_ + ".restart");
155  statFile.setName(name_ + ".stat");
156  eneFile.setName(name_ + ".ene");
157 }
161 void Files::setName(const char* name)
162 {
163  setName(std::string(name));
164 }
170 {
171  dataFile.setFileType(fileType);
172  fStatFile.setFileType(fileType);
173  restartFile.setFileType(fileType);
174  statFile.setFileType(fileType);
175  eneFile.setFileType(fileType);
176 }
177 
178 //void Files::openNextFile(const int counter)
179 //{
180 // getDataFile().openNextFile(counter);
181 // fStatFile.openNextFile(counter);
182 // restartFile.openNextFile(counter);
183 // statFile.openNextFile(counter);
184 // getEneFile().openNextFile(counter);
185 //}
190 {
191  dataFile.setCounter(0);
194  statFile.setCounter(0);
195  eneFile.setCounter(0);
196 }
200 void Files::setOpenMode(std::fstream::openmode openMode)
201 {
202  dataFile.setOpenMode(openMode);
203  fStatFile.setOpenMode(openMode);
204  restartFile.setOpenMode(openMode);
205  statFile.setOpenMode(openMode);
206  eneFile.setOpenMode(openMode);
207 }
211 void Files::read(std::istream& is)
212 {
213  std::string dummy;
214  is >> dummy >> name_;
215  is >> dummy >> dataFile;
216  is >> dummy >> fStatFile;
217  is >> dummy >> eneFile;
218  is >> dummy >> restartFile;
219  is >> dummy >> statFile;
220 }
227 void Files::write(std::ostream& os) const
228 {
229  os << " name " << name_<< std::endl;
230  os << "dataFile " << dataFile << std::endl;
231  os << "fStatFile " << fStatFile << std::endl;
232  os << "eneFile " << eneFile << std::endl;
233  os << "restartFile " << restartFile << std::endl;
234  os << "statFile " << statFile << std::endl;
235 }
240 {
241  dataFile.open();
242  fStatFile.open();
243  restartFile.open();
244  //statFile.open();
245  eneFile.open();
246 }
251 {
252  dataFile.close();
253  fStatFile.close();
254  restartFile.close();
255  statFile.close();
256  eneFile.close();
257 }
261 void Files::setNextSavedTimeStep(unsigned int nextSavedTimeStep)
262 {
263  dataFile.setNextSavedTimeStep(nextSavedTimeStep);
264  fStatFile.setNextSavedTimeStep(nextSavedTimeStep);
265  restartFile.setNextSavedTimeStep(nextSavedTimeStep);
266  statFile.setNextSavedTimeStep(nextSavedTimeStep);
267  eneFile.setNextSavedTimeStep(nextSavedTimeStep);
268 }
Every simulation requires data files to store all the information necessary for visualisation and ana...
Definition: Files.h:42
void setNextSavedTimeStep(unsigned int nextSavedTimeStep)
Sets the next time step for all the files (ene, data, fstat, restart, stat) at which the data is to b...
Definition: Files.cc:261
void setCounter(unsigned int counter)
Allows the user to set the file counter according to his need. Sets File::counter_.
Definition: File.cc:223
MERCURY_DEPRECATED File & getDataFile()
The non const version. Allows one to edit the File::dataFile.
Definition: Files.cc:60
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
void closeFiles()
Closes all files (ene, data, fstat, restart, stat) that were opened to read or write.
Definition: Files.cc:250
Files()
A constructor.
Definition: Files.cc:33
MERCURY_DEPRECATED File & getStatFile()
The non const version. Allows to edit the File::statFile.
Definition: Files.cc:88
void setFileType(FileType fileType)
Sets File::fileType_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:169
FileType
With FileType options, one is able to choose if data is to be read/written from/into no or single or ...
Definition: File.h:35
void setOpenMode(std::fstream::openmode openMode)
Sets File::openMode_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:200
void close()
Closes the file by calling fstream_.close()
Definition: File.cc:360
MERCURY_DEPRECATED File & getFStatFile()
The non const version. Allows to edit the File::fStatFile.
Definition: Files.cc:74
virtual ~Files()
A destructor, watch out its a virtual destructor.
Definition: Files.cc:44
std::string name_
the name of the problem, used, e.g., for the files
Definition: Files.h:230
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: Files.h:214
void openFiles()
Opens all the files (ene, data, fstat, restart, stat) for reading and writing purposes.
Definition: Files.cc:239
std::fstream & getFstream()
Allows to access the member variable File::fstream_.
Definition: File.cc:150
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: Files.cc:149
void resetFileCounter()
Resets the file counter for each file i.e. for ene, data, fstat, restart, stat)
Definition: Files.cc:189
void setNextSavedTimeStep(unsigned int nextSavedTimeStep)
Sets File::nextSavedTimeStep_.
Definition: File.cc:298
MERCURY_DEPRECATED File & getEneFile()
The non const version. Allows to edit the File::eneFile.
Definition: Files.cc:67
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:138
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_.
Definition: File.cc:282
void setFileType(FileType fileType)
Sets the type of file needed to write into or read from. File::fileType_.
Definition: File.cc:209
void write(std::ostream &os) const
Writes data into a file from the member variables name_, restartFile, dataFile etc.
Definition: Files.cc:227
bool open()
Checks if the file stream fstream_ has any issues while opening. Alongside, it also increments the ne...
Definition: File.cc:318
void read(std::istream &is)
Extracts data from the input stream (which is basically a file you want to read from) into name_...
Definition: Files.cc:211
void setName(const std::string &name)
Sets the file name, e.g. "Name.data".
Definition: File.cc:195
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224
Definition: File.h:78
const std::string & getName() const
Returns the name of the file. Does not allow to change it though.
Definition: Files.cc:131
MERCURY_DEPRECATED File & getRestartFile()
The non const version. Allows to edit the File::restartFile.
Definition: Files.cc:81
void setOpenMode(std::fstream::openmode openMode)
Allows the user to Sets File::openMode_.
Definition: File.cc:267