9 #include <tools/config/DdMdConfigReader.h> 10 #include <tools/config/DdMdConfigWriter.h> 11 #include <tools/trajectory/LammpsDumpReader.h> 12 #include <util/format/Str.h> 26 : configReaderPtr_(0),
27 trajectoryReaderPtr_(0),
28 configReaderFactory_(*this),
29 configWriterFactory_(*this),
30 trajectoryReaderFactory_(*this),
31 analyzerManager_(*this)
39 if (configReaderPtr_) {
40 delete configReaderPtr_;
42 if (trajectoryReaderPtr_) {
43 delete trajectoryReaderPtr_;
55 while ((c = getopt(argc, argv,
"ep:c:")) != -1) {
67 Log::file() <<
"Unknown option -" << optopt << std::endl;
124 std::string filename;
125 std::ifstream inputFile;
126 std::ofstream outputFile;
128 bool readNext =
true;
134 if (command ==
"FINISH") {
138 if (command ==
"SET_CONFIG_READER") {
139 std::string classname;
141 Log::file() <<
" " << classname << std::endl;
144 if (command ==
"READ_CONFIG") {
148 Log::file() <<
"\nReading auxiliary file: ";
157 Log::file() <<
"\nReading config file: ";
165 if (command ==
"SET_CONFIG_WRITER") {
166 std::string classname;
168 Log::file() <<
" " << classname << std::endl;
171 if (command ==
"WRITE_CONFIG") {
173 Log::file() <<
"\nReading auxiliary file: ";
180 Log::file() <<
"\nWriting config file: ";
187 if (command ==
"SET_TRAJECTORY_READER") {
188 std::string classname;
190 Log::file() <<
" " << classname << std::endl;
193 if (command ==
"ANALYZE_TRAJECTORY") {
195 Log::file() <<
" " << filename << std::endl;
199 Log::file() <<
" Error: Unknown command " << std::endl;
213 configReaderPtr_ = configReaderFactory_.
factory(configStyle);
214 if (configReaderPtr_ == 0) {
216 msg =
"Unrecognized ConfigReader subclass name: ";
229 if (configReaderPtr_ == 0) {
231 assert(configReaderPtr_);
233 return *configReaderPtr_;
251 file.open(filename.c_str());
260 int min,
int max,
int interval)
265 if (interval <= 0)
UTIL_THROW(
"interval <= 0");
268 std::string filename;
269 std::stringstream indexString;
270 std::ifstream configFile;
273 Log::file() <<
"begin main loop" << std::endl;
275 for (
int iStep = min; iStep <= max; iStep += interval) {
277 indexString << iStep;
278 filename = baseFileName;
279 filename += indexString.str();
280 configFile.open(filename.c_str());
281 if (!configFile.is_open()) {
282 std::string msg =
"Configuration file is not open. Filename =";
297 pairPotential().buildCellList();
307 analyzerManager_.
setup();
311 analyzerManager_.
sample(iStep);
315 Log::file() <<
"end main loop" << std::endl;
318 analyzerManager_.
output();
329 configWriterPtr_ = configWriterFactory_.
factory(configStyle);
330 if (configWriterPtr_ == 0) {
332 msg =
"Unrecognized ConfigWriter subclass name: ";
343 if (configWriterPtr_ == 0) {
345 assert(configWriterPtr_);
347 return *configWriterPtr_;
362 file.open(filename.c_str());
374 trajectoryReaderPtr_ =
375 trajectoryReaderFactory_.
factory(trajectoryStyle);
376 if (trajectoryReaderPtr_ == 0) {
378 msg =
"Unrecognized TrajectoryReader subclass name: ";
379 msg += trajectoryStyle;
389 if (trajectoryReaderPtr_ == 0) {
391 assert(trajectoryReaderPtr_);
393 return *trajectoryReaderPtr_;
406 std::ios::in | std::ios::binary);
410 if (!file.is_open()) {
411 std::string msg =
"Trajectory file is not open. Filename =";
417 analyzerManager_.
setup();
421 Log::file() <<
"begin main loop" << std::endl;
427 analyzerManager_.
sample(iStep);
431 Log::file() <<
"end main loop" << std::endl;
434 analyzerManager_.
output();
443 {
return fileMaster_; }
std::istream & commandFile()
Get the command input stream by reference.
void setCommandFileName(const std::string &commandFileName)
Set the command file name.
std::string paramFileName() const
Return the param file name, if any.
void openOutputFile(const std::string &filename, std::ofstream &out, std::ios_base::openmode mode=std::ios_base::out) const
Open an output file.
static void setEcho(bool echo=true)
Enable or disable echoing for all subclasses of ParamComponent.
void openInputFile(const std::string &filename, std::ifstream &in, std::ios_base::openmode mode=std::ios_base::in) const
Open an input file.
std::istream & paramFile()
Get a default parameter stream by reference.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
std::string commandFileName() const
Return the command file name.
void readParamCompositeOptional(std::istream &in, ParamComposite &child, bool next=true)
Add and attempt to read an optional child ParamComposite.
static std::ostream & file()
Get log ostream by reference.
A FileMaster manages input and output files for a simulation.
void setClassName(const char *className)
Set class name string.
void setParamFileName(const std::string ¶mFileName)
Set the parameter file name.
void readParamComposite(std::istream &in, ParamComposite &child, bool next=true)
Add and read a required child ParamComposite.