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

Fixed flushing

PlumedFile's were not flushed correctly
parent 9811caa3
No related branches found
No related tags found
No related merge requests found
......@@ -55,6 +55,7 @@ public:
static void registerKeywords( Keywords& keys );
void calculate(){};
void apply(){
plumed.fflush();
log.flush();
const ActionSet & actionSet(plumed.getActionSet());
for(ActionSet::const_iterator p=actionSet.begin();p!=actionSet.end();++p)
......
......@@ -116,6 +116,7 @@ PlumedFileBase& PlumedFileBase::open(const std::string& path,const std::string&
const std::string pathsuf=path+plumed->getSuffix();
fp=std::fopen(const_cast<char*>(pathsuf.c_str()),const_cast<char*>(mode.c_str()));
}
if(plumed) plumed->insertFile(*this);
if(!fp) fp=std::fopen(const_cast<char*>(path.c_str()),const_cast<char*>(mode.c_str()));
plumed_massert(fp,"file " + path + "cannot be found");
return *this;
......
......@@ -595,6 +595,22 @@ std::string PlumedMain::cite(const std::string&item){
return citations.cite(item);
}
void PlumedMain::fflush(){
for(files_iterator p=files.begin();p!=files.end();++p){
(*p)->flush();
}
}
void PlumedMain::insertFile(PlumedFileBase&f){
files.insert(&f);
}
void PlumedMain::eraseFile(PlumedFileBase&f){
files.erase(&f);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -27,6 +27,7 @@
#include <cstdio>
#include <string>
#include <vector>
#include <set>
// !!!!!!!!!!!!!!!!!!!!!! DANGER !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
......@@ -59,6 +60,7 @@ class PlumedCommunicator;
class Stopwatch;
class Citations;
class ExchangePatterns;
class PlumedFileBase;
/**
Main plumed object.
......@@ -119,6 +121,10 @@ private:
/// Class of possible exchange patterns, used for BIASEXCHANGE but also for future parallel tempering
ExchangePatterns exchangepatterns;
std::set<PlumedFileBase*> files;
typedef std::set<PlumedFileBase*>::iterator files_iterator;
public:
/// Flag to switch off virial calculation (for debug)
bool novirial;
......@@ -219,6 +225,12 @@ public:
FILE* fopen(const char *path, const char *mode);
/// Closes a file opened with PlumedMain::fopen()
int fclose(FILE*fp);
/// Insert a file
void insertFile(PlumedFileBase&);
/// Erase a file
void eraseFile(PlumedFileBase&);
/// Flush all files
void fflush();
};
/////
......
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