diff --git a/src/Action.cpp b/src/Action.cpp index 31093e1d21b81e025a48b29d262a216ad14abff9..b3d82cd03baa3a2c5f7375ffdba11c94da96880b 100644 --- a/src/Action.cpp +++ b/src/Action.cpp @@ -31,20 +31,14 @@ Action::Action(const ActionOptions&ao): } FILE* Action::fopen(const char *path, const 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); + FILE* fp=plumed.fopen(path,mode); files.insert(fp); return fp; } int Action::fclose(FILE*fp){ files.erase(fp); - return std::fclose(fp); + return plumed.fclose(fp); } void Action::fflush(){ diff --git a/src/PlumedMain.cpp b/src/PlumedMain.cpp index af23e340ce5b178db52358be4680a0d58704694a..2fa4350c190fe1cd20af5666635c062f4a934177 100644 --- a/src/PlumedMain.cpp +++ b/src/PlumedMain.cpp @@ -300,6 +300,7 @@ void PlumedMain::init(){ log.printf("Precision of reals: %d\n",atoms.getRealPrecision()); log.printf("Running over %d %s\n",comm.Get_size(),(comm.Get_size()>1?"nodes":"node")); log.printf("Number of atoms: %d\n",atoms.getNatoms()); + log.printf("File suffix: %s\n",getSuffix().c_str()); if(plumedDat.length()>0){ readInputFile(plumedDat); plumedDat=""; @@ -500,6 +501,23 @@ void PlumedMain::load(std::vector<std::string> & words){ double PlumedMain::getBias() const{ return bias; } + +FILE* PlumedMain::fopen(const char *path, const char *mode){ + std::string mmode(mode); + std::string ppath(path); + std::string suffix(getSuffix()); + std::string ppathsuf=ppath+suffix; + FILE*fp=std::fopen(const_cast<char*>(ppathsuf.c_str()),const_cast<char*>(mmode.c_str())); + if(!fp) fp=std::fopen(const_cast<char*>(ppath.c_str()),const_cast<char*>(mmode.c_str())); + assert(fp); + return fp; +} + +int PlumedMain::fclose(FILE*fp){ + return std::fclose(fp); +} + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/PlumedMain.h b/src/PlumedMain.h index 1ab8c491908ed218dd7772c6ff3dccb2e592c685..f4e0ca823ba398b26b5055d28e0c70a64099a921 100644 --- a/src/PlumedMain.h +++ b/src/PlumedMain.h @@ -5,6 +5,7 @@ #include "ActionSet.h" #include "Atoms.h" #include "PlumedCommunicator.h" +#include <cstdio> #include <string> #include <vector> @@ -136,6 +137,8 @@ public: void setSuffix(const std::string&); /// get the value of the bias double getBias()const; + FILE* fopen(const char *path, const char *mode); + int fclose(FILE*fp); }; /////