24 #include "core/Action.h"
25 #include "core/PlumedMain.h"
26 #include "core/Value.h"
43 if(!
fp) plumed_merror(
"writing on uninitilized File");
87 if(r>=
buflen-actual_buffer_length){
89 while(newlen<=r+actual_buffer_length) newlen*=2;
90 char* newbuf=
new char [newlen];
92 for(
int k=
buflen;k<newlen;k++) newbuf[k]=0;
98 r=std::vsnprintf(&
buffer[actual_buffer_length],
buflen-actual_buffer_length,fmt,arg);
101 plumed_massert(r>-1 && r<
buflen-actual_buffer_length,
"error using fmt string " + std::string(fmt));
108 actual_buffer_length+=r;
109 while((p2=strchr(psearch,
'\n'))){
112 actual_buffer_length-=(p2-p1)+1;
183 std::string min, max; val->
getDomain( min, max );
194 }
else for(
unsigned i=0;i<
fields.size();i++){
224 size_t found=str.find_last_of(
"/\\");
225 std::string filename = str +
plumed->getSuffix();
226 std::string directory=filename.substr(0,found+1);
227 std::string file=filename.substr(found+1);
231 std::string filestr = directory +
backstring +
"." + num +
"." + file;
239 if(std::getenv(
"PLUMED_MAXBACKUP"))
Tools::convert(std::getenv(
"PLUMED_MAXBACKUP"),maxbackup);
241 FILE* ff=std::fopen(const_cast<char*>(fname.c_str()),
"r");
246 size_t found=fname.find_last_of(
"/\\");
247 std::string directory=fname.substr(0,found+1);
248 std::string file=fname.substr(found+1);
252 if(i>maxbackup) plumed_merror(
"cannot backup file "+file+
" maximum number of backup is "+num+
"\n");
253 backup=directory+bstring +
"."+num+
"."+file;
254 fff=std::fopen(backup.c_str(),
"r");
256 else std::fclose(fff);
258 int check=rename(fname.c_str(),backup.c_str());
259 plumed_massert(check==0,
"renaming "+fname+
" into "+backup+
" failed for reason: "+strerror(errno));
271 this->path+=
plumed->getSuffix();
274 fp=std::fopen(const_cast<char*>(this->path.c_str()),
"a");
278 fp=std::fopen(const_cast<char*>(this->path.c_str()),
"w");
290 fp=std::fopen(const_cast<char*>(
path.c_str()),
"w");
std::string linePrefix
Prefix for line (e.g. "PLUMED: ")
const std::string & getName() const
Get the name of the quantity.
std::string path
path of the opened file
OFile & rewind()
Rewind a file.
std::string backstring
The string used for backing up files.
void backupAllFiles(const std::string &str)
This backs up all the files that would have been created with the name str.
Class identifying a single field for fielded output.
OFile & fmtField()
Reset the format for writing double precision fields to its default.
A class for holding the value of a function together with its derivatives.
void Bcast(T *, int, int)
char * buffer_string
Internal buffer for printf.
OFile & printField()
Close a line.
OFile & addConstantField(const std::string &)
std::vector< Field > previous_fields
All the previously defined variable fields.
void getDomain(std::string &, std::string &) const
Get the domain of the quantity.
int Get_rank() const
Obtain the rank of the present process.
Communicator * comm
communicator. NULL if not set
int buflen
Internal buffer length.
size_t llwrite(const char *, size_t)
Low-level write.
OFile & link(OFile &)
Allows linking this OFile to another one.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
bool eof
Set to true when end of file is encountered.
std::string fieldFmt
Format for fields writing.
bool cloned
Control closing on destructor.
void backupFile(const std::string &bstring, const std::string &fname)
Backup a file by giving it a different name.
std::vector< Field > fields
All the defined variable fields.
bool FileExist(const std::string &path)
Check if the file exists.
bool err
Set to true when error is encountered.
bool isPeriodic() const
Check if the value is periodic.
void Barrier() const
Wrapper to MPI_Barrier.
OFile & clearFields()
Resets the list of fields.
unsigned actual_buffer_length
This variables stores the actual buffer length.
bool fieldChanged
True if fields has changed.
char * buffer
Internal buffer (generic use)
std::vector< Field > const_fields
All the defined constant fields.
void setBackupString(const std::string &)
Set the string name to be used for automatic backup.
OFile & setLinePrefix(const std::string &)
Set the prefix for output.
OFile & open(const std::string &name)
Opens the file using automatic append/backup.
OFile * linked
Pointer to a linked OFile.
OFile & setupPrintValue(Value *val)
Used to setup printing of values.