diff --git a/src/tools/OFile.cpp b/src/tools/OFile.cpp index 5ff9a73a1446fe220f52aa28a11e60f5382b3edf..effc8fa18e54ff5b0f46ea052789161f48f3ed27 100644 --- a/src/tools/OFile.cpp +++ b/src/tools/OFile.cpp @@ -280,6 +280,16 @@ OFile& OFile::open(const std::string&path){ return *this; } +OFile& OFile::rewind(){ +// we use here "hard" rewind, which means close/reopen +// the reason is that normal rewind does not work when in append mode + plumed_assert(fp); + clearFields(); + fclose(fp); + fp=std::fopen(const_cast<char*>(path.c_str()),"w"); + return *this; +} + } diff --git a/src/tools/OFile.h b/src/tools/OFile.h index fe08c9dce7cf7fb62cd00c5a281a02a486ee0896..3c6b76cc03a8bcc754e83a7bbfc56198ebe4caea 100644 --- a/src/tools/OFile.h +++ b/src/tools/OFile.h @@ -184,6 +184,8 @@ this method can be used to clean the field list. /// Formatted output with << operator template <class T> friend OFile& operator<<(OFile&,const T &); +/// Rewind a file + OFile&rewind(); }; /// Write using << syntax