Skip to content
Snippets Groups Projects
Commit 4391ba14 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Add method to retrieve path and mode

Can be useful if one wants to open externally a file
but generate the name with PLUMED rules
and properly use backups/append.
parent 7a85bbe6
No related branches found
No related tags found
No related merge requests found
......@@ -103,10 +103,12 @@ bool FileBase::FileExist(const std::string& path){
if(plumed){
this->path=appendSuffix(path,plumed->getSuffix());
ff=std::fopen(const_cast<char*>(this->path.c_str()),"r");
mode="r";
}
if(!ff){
this->path=path;
ff=std::fopen(const_cast<char*>(this->path.c_str()),"r");
mode="r";
}
if(ff) {do_exist=true; fclose(ff);}
if(comm) comm->Barrier();
......
......@@ -75,6 +75,8 @@ protected:
bool err;
/// path of the opened file
std::string path;
/// mode of the opened file
std::string mode;
/// Set to true if you want flush to be heavy (close/reopen)
bool heavyFlush;
/// Append suffix.
......@@ -111,8 +113,23 @@ public:
bool FileExist(const std::string& path);
/// Check if a file is open
bool isOpen();
/// Retrieve the path
std::string getPath()const;
/// Retrieve the mode
std::string getMode()const;
};
inline
std::string FileBase::getPath()const{
return path;
}
inline
std::string FileBase::getMode()const{
return mode;
}
}
......
......@@ -287,6 +287,7 @@ OFile& OFile::open(const std::string&path){
}
if(checkRestart()){
fp=std::fopen(const_cast<char*>(this->path.c_str()),"a");
mode="a";
if(Tools::extension(this->path)=="gz"){
#ifdef __PLUMED_HAS_ZLIB
gzfp=(void*)gzopen(const_cast<char*>(this->path.c_str()),"a9");
......@@ -298,6 +299,7 @@ OFile& OFile::open(const std::string&path){
backupFile( backstring, this->path );
if(comm)comm->Barrier();
fp=std::fopen(const_cast<char*>(this->path.c_str()),"w");
mode="w";
if(Tools::extension(this->path)=="gz"){
#ifdef __PLUMED_HAS_ZLIB
gzfp=(void*)gzopen(const_cast<char*>(this->path.c_str()),"w9");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment