MercuryDPM  Alpha
 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  name_ = "out";
43 }
44 
46 {
47 
48 }
53 Files::Files(const Files& other)
54 {
55  //constructor();
56  setName(other.getName());
57 }
62 {
63  return dataFile;
64 }
69 {
70  return eneFile;
71 }
76 {
77  return fStatFile;
78 }
83 {
84  return restartFile;
85 }
90 {
91  return statFile;
92 }
96 const File& Files::getDataFile() const
97 {
98  return dataFile;
99 }
100 
104 const File& Files::getEneFile() const
105 {
106  return eneFile;
107 }
111 const File& Files::getFStatFile() const
112 {
113  return fStatFile;
114 }
119 {
120  return restartFile;
121 }
125 const File& Files::getStatFile() const
126 {
127  return statFile;
128 }
132 const std::string& Files::getName() const
133 {
134  return name_;
135 }
139 void Files::setSaveCount(unsigned int saveCount)
140 {
141  dataFile.setSaveCount(saveCount);
142  fStatFile.setSaveCount(saveCount);
143  restartFile.setSaveCount(saveCount);
144  statFile.setSaveCount(saveCount);
145  eneFile.setSaveCount(saveCount);
146 }
150 void Files::setName(const std::string& name)
151 {
152  name_ = name; // was before this->name_ = name
153  dataFile.setName(name_ + ".data");
154  fStatFile.setName(name_ + ".fstat");
155  restartFile.setName(name_ + ".restart");
156  statFile.setName(name_ + ".stat");
157  eneFile.setName(name_ + ".ene");
158 }
162 void Files::setName(const char* name)
163 {
164  setName(std::string(name));
165 }
171 {
172  dataFile.setFileType(fileType);
173  fStatFile.setFileType(fileType);
174  restartFile.setFileType(fileType);
175  statFile.setFileType(fileType);
176  eneFile.setFileType(fileType);
177 }
178 
179 //void Files::openNextFile(const int counter)
180 //{
181 // dataFile.openNextFile(counter);
182 // fStatFile.openNextFile(counter);
183 // restartFile.openNextFile(counter);
184 // statFile.openNextFile(counter);
185 // eneFile.openNextFile(counter);
186 //}
191 {
192  dataFile.setCounter(0);
195  statFile.setCounter(0);
196  eneFile.setCounter(0);
197 }
201 void Files::setOpenMode(std::fstream::openmode openMode)
202 {
203  dataFile.setOpenMode(openMode);
204  fStatFile.setOpenMode(openMode);
205  restartFile.setOpenMode(openMode);
206  statFile.setOpenMode(openMode);
207  eneFile.setOpenMode(openMode);
208 }
212 void Files::read(std::istream& is)
213 {
214  std::string dummy;
215  is >> dummy >> name_;
216  setName(name_);
217  is >> dummy >> dataFile;
218  is >> dummy >> fStatFile;
219  is >> dummy >> eneFile;
220  is >> dummy >> restartFile;
221  is >> dummy >> statFile;
222 }
229 void Files::write(std::ostream& os) const
230 {
231  os << " name " << name_<< std::endl;
232  os << "dataFile " << dataFile << std::endl;
233  os << "fStatFile " << fStatFile << std::endl;
234  os << "eneFile " << eneFile << std::endl;
235  os << "restartFile " << restartFile << std::endl;
236  os << "statFile " << statFile << std::endl;
237 }
242 {
243  dataFile.open();
244  fStatFile.open();
245  restartFile.open();
246  //statFile.open();
247  eneFile.open();
248 }
253 {
254  dataFile.close();
255  fStatFile.close();
256  restartFile.close();
257  statFile.close();
258  eneFile.close();
259 }
263 void Files::setNextSavedTimeStep(unsigned int nextSavedTimeStep)
264 {
265  dataFile.setNextSavedTimeStep(nextSavedTimeStep);
266  fStatFile.setNextSavedTimeStep(nextSavedTimeStep);
267  restartFile.setNextSavedTimeStep(nextSavedTimeStep);
268  statFile.setNextSavedTimeStep(nextSavedTimeStep);
269  eneFile.setNextSavedTimeStep(nextSavedTimeStep);
270 }
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:263
void setCounter(unsigned int counter)
Allows the user to set the file counter according to his need. Sets File::counter_.
Definition: File.cc:224
MERCURY_DEPRECATED File & getDataFile()
The non const version. Allows one to edit the File::dataFile.
Definition: Files.cc:61
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:252
Files()
A constructor.
Definition: Files.cc:33
MERCURY_DEPRECATED File & getStatFile()
The non const version. Allows to edit the File::statFile.
Definition: Files.cc:89
void setFileType(FileType fileType)
Sets File::fileType_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:170
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:201
void close()
Closes the file by calling fstream_.close()
Definition: File.cc:362
MERCURY_DEPRECATED File & getFStatFile()
The non const version. Allows to edit the File::fStatFile.
Definition: Files.cc:75
virtual ~Files()
A destructor, watch out its a virtual destructor.
Definition: Files.cc:45
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:241
std::fstream & getFstream()
Allows to access the member variable File::fstream_.
Definition: File.cc:151
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: Files.cc:150
void resetFileCounter()
Resets the file counter for each file i.e. for ene, data, fstat, restart, stat)
Definition: Files.cc:190
void setNextSavedTimeStep(unsigned int nextSavedTimeStep)
Sets File::nextSavedTimeStep_.
Definition: File.cc:300
MERCURY_DEPRECATED File & getEneFile()
The non const version. Allows to edit the File::eneFile.
Definition: Files.cc:68
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:139
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:283
void setFileType(FileType fileType)
Sets the type of file needed to write into or read from. File::fileType_.
Definition: File.cc:210
void write(std::ostream &os) const
Writes data into a file from the member variables name_, restartFile, dataFile etc.
Definition: Files.cc:229
bool open()
Checks if the file stream fstream_ has any issues while opening. Alongside, it also increments the ne...
Definition: File.cc:320
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:212
void setName(const std::string &name)
Sets the file name, e.g. "Name.data".
Definition: File.cc:196
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:132
MERCURY_DEPRECATED File & getRestartFile()
The non const version. Allows to edit the File::restartFile.
Definition: Files.cc:82
void setOpenMode(std::fstream::openmode openMode)
Allows the user to Sets File::openMode_.
Definition: File.cc:268