From 00a4ee95149fb6a01f0f5a3ea46493198b92f2ec Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Tue, 23 Jul 2013 01:00:42 +0200 Subject: [PATCH] PLUMED_MAXBACKUP environment variable Allows to switch off auto backup or to change the maximum number of backups --- src/tools/OFile.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tools/OFile.cpp b/src/tools/OFile.cpp index 5587d4a84..28caee7c6 100644 --- a/src/tools/OFile.cpp +++ b/src/tools/OFile.cpp @@ -31,6 +31,7 @@ #include <iostream> #include <string> +#include <cstdlib> namespace PLMD{ @@ -221,7 +222,9 @@ OFile& OFile::open(const std::string&path){ if(plumed && plumed->getRestart()){ fp=std::fopen(const_cast<char*>(this->path.c_str()),"a"); } else { - if(!comm || comm->Get_rank()==0){ + int maxbackup=100; + if(std::getenv("PLUMED_MAXBACKUP")) Tools::convert(std::getenv("PLUMED_MAXBACKUP"),maxbackup); + if(maxbackup>0 && (!comm || comm->Get_rank()==0)){ FILE* ff=std::fopen(const_cast<char*>(this->path.c_str()),"r"); FILE* fff=NULL; if(ff){ @@ -232,6 +235,7 @@ OFile& OFile::open(const std::string&path){ for(int i=0;;i++){ std::string num; Tools::convert(i,num); + if(i>maxbackup) plumed_merror("cannot backup file "+file+" maximum number of backup is "+num+"\n"); backup=directory+"bck."+num+"."+file; fff=std::fopen(backup.c_str(),"r"); if(!fff) break; -- GitLab