diff --git a/src/analysis/Histogram.cpp b/src/analysis/Histogram.cpp index 14a672d2ca1b2c40782abeead545b603e6ba52be..aaa6cfd6260f710e627b8a5c20d016a9755f8b08 100644 --- a/src/analysis/Histogram.cpp +++ b/src/analysis/Histogram.cpp @@ -175,8 +175,8 @@ void Histogram::performAnalysis(){ gg->scaleAllValuesAndDerivatives( 1.0 / getNormalization() ); // Write the grid to a file - OFile gridfile; gridfile.link(*this); - gridfile.open( gridfname, "analysis" ); gg->writeToFile( gridfile ); + OFile gridfile; gridfile.link(*this); gridfile.setBackupString("analysis"); + gridfile.open( gridfname ); gg->writeToFile( gridfile ); // Close the file gridfile.close(); delete gg; } diff --git a/src/tools/OFile.cpp b/src/tools/OFile.cpp index 569395d69fc51e2656dc47f7ac0354591fde8e5e..caca9a9a788e9e6d5f7dad518c5bf4eb452ee6eb 100644 --- a/src/tools/OFile.cpp +++ b/src/tools/OFile.cpp @@ -48,7 +48,8 @@ size_t OFile::llwrite(const char*ptr,size_t s){ OFile::OFile(): linked(NULL), - fieldChanged(false) + fieldChanged(false), + backstring("bck") { fmtField(); buflen=1; @@ -210,7 +211,11 @@ OFile& OFile::printField(){ return *this; } -OFile& OFile::open(const std::string&path, const std::string& backstring ){ +void OFile::setBackupString( const std::string& str ){ + backstring=str; +} + +OFile& OFile::open(const std::string&path){ plumed_assert(!cloned); eof=false; err=false; diff --git a/src/tools/OFile.h b/src/tools/OFile.h index c3611e56e03c974b684eeee259ebe6f8174056aa..cb96116f1378c5c94ca25b71ddd9adf871185d12 100644 --- a/src/tools/OFile.h +++ b/src/tools/OFile.h @@ -114,6 +114,8 @@ public virtual FileBase{ std::string linePrefix; /// Temporary ostringstream for << output std::ostringstream oss; +/// The string used for backing up files + std::string backstring; /// Find field index given name unsigned findField(const std::string&name)const; public: @@ -130,8 +132,10 @@ public: /// written on the linked OFile. Notice that a OFile should /// be either opened explicitly, linked to a FILE or linked to a OFile OFile& link(OFile&); +/// Set the string name to be used for automatic backup + void setBackupString( const std::string& ); /// Opens the file using automatic append/backup - OFile& open(const std::string&name, const std::string& backstring="bck"); + OFile& open(const std::string&name); /// Set the prefix for output. /// Typically "PLUMED: ". Notice that lines with a prefix cannot /// be parsed using fields in a IFile.