12 std::string
getName(
int argc,
char *argv[]) {
13 logger.assert_always(argc>1,
"Please provide name of first data file as input argument");
14 return std::string(argv[1]);
19 IFile (std::ifstream* file_,
unsigned n_) :
file(file_),
n(n_) {}
38 std::string name =
getName(argc, argv);
41 size_t dot = name.find_last_of(
'.');
43 if (dot==std::string::npos) {
48 dot = name.find_last_of(
'.');
49 char afterDot = name[dot + 1];
51 if (afterDot >=
'0' && afterDot <=
'9') {
58 size_t dot = name.find_last_of(
'.');
63 for(
unsigned processorID = 0;
true; ++processorID) {
66 auto* file =
new std::ifstream(fileName.c_str());
70 iFiles.emplace_back(file,0);
74 logger.assert_always(!
iFiles.empty(),
"No input file found with name % ",name +
".data0" +
ending);
77 std::string oFileName = name +
".data" +
ending;
78 oFile.open(oFileName);
82 logger(
INFO,
"Opened % for output", oFileName);
92 for (
auto iFile :
iFiles) {
115 for(
auto& iFile :
iFiles) {
117 *iFile.file >> iFile.n;
120 *iFile.file >> iFile.time;
122 if (iFile.file->fail())
return false;
124 std::getline(*iFile.file, line);
126 static std::string headerLine = line;
129 if (line != headerLine || iFile.time < time) {
131 *iFile.file >> iFile.n;
133 *iFile.file >> iFile.time;
134 if (iFile.file->fail())
return false;
135 std::getline(*iFile.file, line);
136 }
while (line != headerLine || iFile.time < time);
137 logger(
WARN,
"Mistake detected; moving forward to time %",iFile.time);
145 oFile << n <<
' ' << time << line <<
'\n';
148 for(
auto& iFile : iFiles) {
149 for (
unsigned i=0;
i<iFile.n; ++
i) {
150 std::getline(*iFile.file, line);
151 oFile << line <<
'\n';
159 int main (
int argc,
char *argv[])
std::string getName(int argc, char *argv[])
extracts the file name from the command line input
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
DataFiles(int argc, char *argv[])
opens the input and output data files
const std::complex< Mdouble > i
bool writeTimeStep()
writes single timestep
int main(int argc, char *argv[])
IFile(std::ifstream *file_, unsigned n_)
std::string to_string(const T &n)
~DataFiles()
closes the input/output data files
void write()
write all time steps
std::vector< IFile > iFiles