Skip to content
Snippets Groups Projects
Commit 9dfbc8f6 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Added tool to add a suffix to all open files

It is now possible to automatically add a suffix to
all the files opened through the Action::fopen tool.
Opening is done as follows:
First the file+suffix is tried.
In case of error the file without suffix is tried.

In this manner, it should be possible to provide a single
input file also for replica exchange stuff. For output files,
it should make any difference.

I also added a stupid keyword to test this feature. Just use
_SET_SUFFIX pippo
in the plumed.dat file to add a suffix pippo to opened files
parent afd1b872
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,13 @@ Action::Action(const ActionOptions&ao): ...@@ -31,7 +31,13 @@ Action::Action(const ActionOptions&ao):
} }
FILE* Action::fopen(const char *path, const char *mode){ 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); files.insert(fp);
return fp; return fp;
} }
......
...@@ -316,6 +316,10 @@ void PlumedMain::readInputFile(std::string str){ ...@@ -316,6 +316,10 @@ void PlumedMain::readInputFile(std::string str){
if(words.size()==0)continue; if(words.size()==0)continue;
else if(words[0]=="ENDPLUMED") break; else if(words[0]=="ENDPLUMED") break;
else if(words[0]=="LOAD") load(words); 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"){ else if(words[0]=="INCLUDE"){
assert(words.size()==2); assert(words.size()==2);
readInputFile(words[1]); readInputFile(words[1]);
......
...@@ -77,6 +77,9 @@ private: ...@@ -77,6 +77,9 @@ private:
/// These are the action the, if they are Pilot::onStep(), can trigger execution /// These are the action the, if they are Pilot::onStep(), can trigger execution
std::vector<ActionPilot*> pilots; std::vector<ActionPilot*> pilots;
/// Suffix string for file opening, useful for multiple simulations in the same directory
std::string suffix;
public: public:
/// Flag to switch off virial calculation (for debug) /// Flag to switch off virial calculation (for debug)
bool novirial; bool novirial;
...@@ -124,6 +127,10 @@ public: ...@@ -124,6 +127,10 @@ public:
void exit(int c=0); void exit(int c=0);
/// Load a shared library /// Load a shared library
void load(std::vector<std::string> & words); 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(){ ...@@ -139,6 +146,17 @@ Atoms& PlumedMain::getAtoms(){
return atoms; return atoms;
} }
inline
const std::string & PlumedMain::getSuffix()const{
return suffix;
}
inline
void PlumedMain::setSuffix(const std::string&s){
suffix=s;
}
} }
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment