diff --git a/src/Action.cpp b/src/Action.cpp index 5a2e12d94b21849ed33460125a53d52ec7faa3e9..31093e1d21b81e025a48b29d262a216ad14abff9 100644 --- a/src/Action.cpp +++ b/src/Action.cpp @@ -31,7 +31,13 @@ Action::Action(const ActionOptions&ao): } FILE* Action::fopen(const char *path, const char *mode){ - FILE*fp=std::fopen(const_cast<char*>(path),const_cast<char*>(mode)); + std::string mmode(mode); + std::string ppath(path); + std::string suffix(plumed.getSuffix()); + std::string ppathsuf=ppath+suffix; + FILE*fp=std::fopen(const_cast<char*>(ppathsuf.c_str()),const_cast<char*>(mmode.c_str())); + if(!fp) std::fopen(const_cast<char*>(ppath.c_str()),const_cast<char*>(mmode.c_str())); + assert(fp); files.insert(fp); return fp; } diff --git a/src/PlumedMain.cpp b/src/PlumedMain.cpp index e3267f097ce0f1382e883dc734f1cf4bee3ad700..1bf1ac2c90578b73b0342a4418eaf8a0adddda56 100644 --- a/src/PlumedMain.cpp +++ b/src/PlumedMain.cpp @@ -316,6 +316,10 @@ void PlumedMain::readInputFile(std::string str){ if(words.size()==0)continue; else if(words[0]=="ENDPLUMED") break; else if(words[0]=="LOAD") load(words); + else if(words[0]=="_SET_SUFFIX"){ + assert(words.size()==2); + setSuffix(words[1]); + } else if(words[0]=="INCLUDE"){ assert(words.size()==2); readInputFile(words[1]); diff --git a/src/PlumedMain.h b/src/PlumedMain.h index 060800e18c20fc815e631a9192de7f9e9b1a9b2b..d298b38b839ba70ae1b2566a357bff246ad2af61 100644 --- a/src/PlumedMain.h +++ b/src/PlumedMain.h @@ -77,6 +77,9 @@ private: /// These are the action the, if they are Pilot::onStep(), can trigger execution std::vector<ActionPilot*> pilots; +/// Suffix string for file opening, useful for multiple simulations in the same directory + std::string suffix; + public: /// Flag to switch off virial calculation (for debug) bool novirial; @@ -124,6 +127,10 @@ public: void exit(int c=0); /// Load a shared library void load(std::vector<std::string> & words); +/// Get the suffix string + const std::string & getSuffix()const; +/// Set the suffix string + void setSuffix(const std::string&); }; ///// @@ -139,6 +146,17 @@ Atoms& PlumedMain::getAtoms(){ return atoms; } +inline +const std::string & PlumedMain::getSuffix()const{ + return suffix; +} + +inline +void PlumedMain::setSuffix(const std::string&s){ + suffix=s; +} + + } #endif