diff --git a/src/Action.cpp b/src/Action.cpp
index 3aedd0b389b05b342dde1562d8da85c4a55247cd..f886f7187b0999790c7cfcf8ddb4a2fe24540b25 100644
--- a/src/Action.cpp
+++ b/src/Action.cpp
@@ -30,6 +30,23 @@ Action::Action(const ActionOptions&ao):
   log.printf("  with label %s\n",label.c_str());
 }
 
+FILE* Action::fopen(const char *path, const char *mode){
+  FILE*fp=std::fopen(const_cast<char*>(path),const_cast<char*>(mode));
+  files.insert(fp);
+  return fp;
+}
+
+int Action::fclose(FILE*fp){
+  files.erase(fp);
+  return std::fclose(fp);
+}
+
+void Action::fflush(){
+  for(files_iterator p=files.begin();p!=files.end();++p){
+    std::fflush((*p));
+  }
+}
+
 void Action::parseFlag(const std::string&key,bool & t){
   if(!Tools::parseFlag(line,key,t)){
     log.printf("ERROR parsing keyword %s\n",key.c_str());
diff --git a/src/Action.h b/src/Action.h
index 61c111bbe8752e1a8777465f95aada246ff3ad19..51d6f3d80e57ba464c8bc51a6ea7249355ba2fc9 100644
--- a/src/Action.h
+++ b/src/Action.h
@@ -94,6 +94,10 @@ protected:
 /// Exit with error code c
   void exit(int c=0);
 
+///
+  std::set<FILE*> files;
+  typedef std::set<FILE*>::iterator files_iterator;
+
 public:
   Action(const ActionOptions&);
   virtual ~Action(){};
@@ -111,7 +115,7 @@ public:
   virtual void apply()=0;
 
 /// Tell to the Action to flush open files
-  virtual void flush(){};
+  void fflush();
 
   virtual std::string getDocumentation()const;
 
@@ -138,6 +142,9 @@ public:
 
 /// Perform calculation using numerical derivatives
   virtual void calculateNumericalDerivatives();
+
+  FILE *fopen(const char *path, const char *mode);
+  int   fclose(FILE*fp);
 };
 
 /////////////////////
diff --git a/src/DumpDerivatives.cpp b/src/DumpDerivatives.cpp
index 4f785ea92a06d2e662c2ac965eb8366c1c08c7a1..c37e354b51edce89e85db901e3dc29df27895541 100644
--- a/src/DumpDerivatives.cpp
+++ b/src/DumpDerivatives.cpp
@@ -46,7 +46,6 @@ public:
   void calculate();
   DumpDerivatives(const ActionOptions&);
   void apply(){};
-  void flush();
   ~DumpDerivatives();
 };
 
@@ -98,10 +97,6 @@ DumpDerivatives::~DumpDerivatives(){
   if(fp) fclose(fp);
 }
 
-void DumpDerivatives::flush(){
-  if(fp) fflush(fp);
-}
-
 }
 
 
diff --git a/src/Flush.cpp b/src/Flush.cpp
index 60c31c09f092bebc115f29a1fc4d01c9e6ace435..99c6ab0244d7113c61a705e0f5b92b264bfb66ee 100644
--- a/src/Flush.cpp
+++ b/src/Flush.cpp
@@ -34,7 +34,7 @@ public:
   void apply(){
     const ActionSet & actionSet(plumed.getActionSet());
     for(ActionSet::const_iterator p=actionSet.begin();p!=actionSet.end();++p)
-    (*p)->flush();
+    (*p)->fflush();
   }
 };
 
diff --git a/src/Print.cpp b/src/Print.cpp
index a0ad96632295bb857ec446ca659cbe6f56886d65..5af0cf4c7f4a3d4b9afc02282bd931e5cced746f 100644
--- a/src/Print.cpp
+++ b/src/Print.cpp
@@ -45,7 +45,6 @@ public:
   void calculate();
   Print(const ActionOptions&);
   void apply(){};
-  void flush();
   ~Print();
 };
 
@@ -101,10 +100,6 @@ Print::~Print(){
   if(fp) fclose(fp);
 }
 
-void Print::flush(){
-  if(fp) fflush(fp);
-}
-
 }