From 00982e032051b5a0b22ce1eafaa885affe85c9e4 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Fri, 2 Dec 2011 17:27:57 +0100 Subject: [PATCH] File opening tools moved to PlumedMain I moved the tools to open a file with a specific prefix to PlumedMain. This allows easily to use them also to open the input file, which in turn means that we will be able to do bias-exchange and Hamiltonian replica exchange --- src/Action.cpp | 10 ++-------- src/PlumedMain.cpp | 18 ++++++++++++++++++ src/PlumedMain.h | 3 +++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Action.cpp b/src/Action.cpp index 31093e1d2..b3d82cd03 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 af23e340c..2fa4350c1 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 1ab8c4919..f4e0ca823 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); }; ///// -- GitLab