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

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
parent 4c8d346e
No related branches found
No related tags found
No related merge requests found
...@@ -31,20 +31,14 @@ Action::Action(const ActionOptions&ao): ...@@ -31,20 +31,14 @@ Action::Action(const ActionOptions&ao):
} }
FILE* Action::fopen(const char *path, const char *mode){ FILE* Action::fopen(const char *path, const char *mode){
std::string mmode(mode); FILE* fp=plumed.fopen(path,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;
} }
int Action::fclose(FILE*fp){ int Action::fclose(FILE*fp){
files.erase(fp); files.erase(fp);
return std::fclose(fp); return plumed.fclose(fp);
} }
void Action::fflush(){ void Action::fflush(){
......
...@@ -300,6 +300,7 @@ void PlumedMain::init(){ ...@@ -300,6 +300,7 @@ void PlumedMain::init(){
log.printf("Precision of reals: %d\n",atoms.getRealPrecision()); 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("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("Number of atoms: %d\n",atoms.getNatoms());
log.printf("File suffix: %s\n",getSuffix().c_str());
if(plumedDat.length()>0){ if(plumedDat.length()>0){
readInputFile(plumedDat); readInputFile(plumedDat);
plumedDat=""; plumedDat="";
...@@ -500,6 +501,23 @@ void PlumedMain::load(std::vector<std::string> & words){ ...@@ -500,6 +501,23 @@ void PlumedMain::load(std::vector<std::string> & words){
double PlumedMain::getBias() const{ double PlumedMain::getBias() const{
return bias; 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);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ActionSet.h" #include "ActionSet.h"
#include "Atoms.h" #include "Atoms.h"
#include "PlumedCommunicator.h" #include "PlumedCommunicator.h"
#include <cstdio>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -136,6 +137,8 @@ public: ...@@ -136,6 +137,8 @@ public:
void setSuffix(const std::string&); void setSuffix(const std::string&);
/// get the value of the bias /// get the value of the bias
double getBias()const; double getBias()const;
FILE* fopen(const char *path, const char *mode);
int fclose(FILE*fp);
}; };
///// /////
......
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