diff --git a/src/analysis/Analysis.cpp b/src/analysis/Analysis.cpp index ff5dfc428c547fb11a8e8fc95f3e9dc44ab7f4ce..c108897c0066de11ffc7e9b0ec5ef48cdcc4ba74 100644 --- a/src/analysis/Analysis.cpp +++ b/src/analysis/Analysis.cpp @@ -170,7 +170,7 @@ old_norm(0.0) } void Analysis::readDataFromFile( const std::string& filename ){ - double tstep, oldtstep; PlumedIFile ifile; + double tstep, oldtstep; IFile ifile; if( !ifile.FileExist(filename) ) error("failed to find required restart file " + filename ); ifile.open(filename); diff --git a/src/analysis/Analysis.h b/src/analysis/Analysis.h index 0f32a0e5f52a0d4da132aac671bbc60e861087c1..9d3711dc823ad30e9c13f1fdf99df34b0fdb392e 100644 --- a/src/analysis/Analysis.h +++ b/src/analysis/Analysis.h @@ -79,7 +79,7 @@ private: /// The value of the old normalization constant double norm, old_norm; /// The checkpoint file - PlumedOFile rfile; + OFile rfile; /// Read in data from a file void readDataFromFile( const std::string& filename ); /// This retrieves the value of norm from the analysis action. diff --git a/src/analysis/Histogram.cpp b/src/analysis/Histogram.cpp index 92596de446ba8c986c2c45c8943ab293cecc5120..52dc930ce2e26e62a32f8835fd5fa08838461332 100644 --- a/src/analysis/Histogram.cpp +++ b/src/analysis/Histogram.cpp @@ -156,7 +156,7 @@ void Histogram::performAnalysis(){ } Grid* gg; if( oldfname.length()>0 && usingMemory() ){ - PlumedIFile oldf; oldf.link(*this); oldf.open(oldfname); + IFile oldf; oldf.link(*this); oldf.open(oldfname); gg = Grid::create( "probs", getArguments(), oldf, gmin, gmax, gbin, false, false, false ); oldf.close(); } else { @@ -175,7 +175,7 @@ void Histogram::performAnalysis(){ gg->scaleAllValuesAndDerivatives( 1.0 / getNormalization() ); // Write the grid to a file - PlumedOFile gridfile; gridfile.link(*this); + OFile gridfile; gridfile.link(*this); gridfile.open( gridfname ); gg->writeToFile( gridfile ); // Close the file gridfile.close(); delete gg; diff --git a/src/bias/External.cpp b/src/bias/External.cpp index 83c6b9945e7bcb1b76ffe81b080a1f0dd9972e1d..9cdf3b1abde4b541a94423f3cea7a5201d8d3eff 100644 --- a/src/bias/External.cpp +++ b/src/bias/External.cpp @@ -23,7 +23,7 @@ #include "ActionRegister.h" #include "tools/Grid.h" #include "tools/PlumedException.h" -#include "tools/PlumedFile.h" +#include "tools/File.h" using namespace std; @@ -141,7 +141,7 @@ BiasGrid_(NULL) addComponent("bias"); componentIsNotPeriodic("bias"); // read grid - PlumedIFile gridfile; gridfile.open(filename); + IFile gridfile; gridfile.open(filename); std::string funcl=getLabel() + ".bias"; BiasGrid_=Grid::create(funcl,getArguments(),gridfile,sparsegrid,spline,true); gridfile.close(); diff --git a/src/bias/MetaD.cpp b/src/bias/MetaD.cpp index fe76cbfc74344dbd53582e14d8403c8e74f75304..2f27842a46457aef87e05bf716f704881c6d82b1 100644 --- a/src/bias/MetaD.cpp +++ b/src/bias/MetaD.cpp @@ -30,7 +30,7 @@ #include "tools/Random.h" #include <string> #include <cstring> -#include "tools/PlumedFile.h" +#include "tools/File.h" #include "time.h" #include <iostream> @@ -120,7 +120,7 @@ private: }; vector<double> sigma0_; vector<Gaussian> hills_; - PlumedOFile hillsOfile_; + OFile hillsOfile_; Grid* BiasGrid_; bool storeOldGrids_; std::string gridfilename_; @@ -138,11 +138,11 @@ private: string mw_dir_; int mw_id_; int mw_rstride_; - vector<PlumedIFile*> ifiles; + vector<IFile*> ifiles; vector<string> ifilesnames; - void readGaussians(PlumedIFile*); - void writeGaussian(const Gaussian&,PlumedOFile&); + void readGaussians(IFile*); + void writeGaussian(const Gaussian&,OFile&); void addGaussian(const Gaussian&); double getHeight(const vector<double>&); double getBiasAndDerivatives(const vector<double>&,double* der=NULL); @@ -337,7 +337,7 @@ mw_n_(1), mw_dir_("./"), mw_id_(0), mw_rstride_(1) } else { fname = hillsfname; } - PlumedIFile *ifile = new PlumedIFile(); + IFile *ifile = new IFile(); ifile->link(*this); ifiles.push_back(ifile); ifilesnames.push_back(fname); @@ -369,7 +369,7 @@ mw_n_(1), mw_dir_("./"), mw_id_(0), mw_rstride_(1) } -void MetaD::readGaussians(PlumedIFile *ifile) +void MetaD::readGaussians(IFile *ifile) { unsigned ncv=getNumberOfArguments(); double dummy; @@ -442,7 +442,7 @@ void MetaD::readGaussians(PlumedIFile *ifile) log.printf(" %d Gaussians read\n",nhills); } -void MetaD::writeGaussian(const Gaussian& hill, PlumedOFile&file){ +void MetaD::writeGaussian(const Gaussian& hill, OFile&file){ unsigned ncv=getNumberOfArguments(); file.printField("time",getTimeStep()*getStep()); for(unsigned i=0;i<ncv;++i){ @@ -717,7 +717,7 @@ void MetaD::update(){ } // dump grid on file if(wgridstride_>0&&getStep()%wgridstride_==0){ - PlumedOFile gridfile; gridfile.link(*this); + OFile gridfile; gridfile.link(*this); if(!storeOldGrids_) remove( gridfilename_.c_str() ); gridfile.open(gridfilename_); BiasGrid_->writeToFile(gridfile); diff --git a/src/core/PlumedMain.cpp b/src/core/PlumedMain.cpp index b0127fec7d3c6f69af6ca24060138c7a87735dc4..592decf6d98815a32d2f5baa3b537d5d28df5173 100644 --- a/src/core/PlumedMain.cpp +++ b/src/core/PlumedMain.cpp @@ -370,7 +370,7 @@ void PlumedMain::init(){ void PlumedMain::readInputFile(std::string str){ plumed_assert(initialized); log.printf("FILE: %s\n",str.c_str()); - PlumedIFile ifile; + IFile ifile; ifile.link(*this); ifile.open(str); std::vector<std::string> words; @@ -611,11 +611,11 @@ void PlumedMain::fflush(){ } } -void PlumedMain::insertFile(PlumedFileBase&f){ +void PlumedMain::insertFile(FileBase&f){ files.insert(&f); } -void PlumedMain::eraseFile(PlumedFileBase&f){ +void PlumedMain::eraseFile(FileBase&f){ files.erase(&f); } diff --git a/src/core/PlumedMain.h b/src/core/PlumedMain.h index 395bc4993d67d8e464591925eba4a7cf5fd94d8f..a498189880ff5cbea8614e25520076ed0a646274 100644 --- a/src/core/PlumedMain.h +++ b/src/core/PlumedMain.h @@ -59,7 +59,7 @@ class Communicator; class Stopwatch; class Citations; class ExchangePatterns; -class PlumedFileBase; +class FileBase; /** Main plumed object. @@ -124,8 +124,8 @@ private: /// Flag for restart bool restart; - std::set<PlumedFileBase*> files; - typedef std::set<PlumedFileBase*>::iterator files_iterator; + std::set<FileBase*> files; + typedef std::set<FileBase*>::iterator files_iterator; /// Stuff to make plumed stop the MD code cleanly int* stopFlag; @@ -238,9 +238,9 @@ public: /// Closes a file opened with PlumedMain::fopen() int fclose(FILE*fp); /// Insert a file - void insertFile(PlumedFileBase&); + void insertFile(FileBase&); /// Erase a file - void eraseFile(PlumedFileBase&); + void eraseFile(FileBase&); /// Flush all files void fflush(); /// Check if restarting diff --git a/src/generic/DumpAtoms.cpp b/src/generic/DumpAtoms.cpp index 4f8de058190d7cbb2f82cdba6a82ddfbc2c3745f..11eab78f41c939a599315a5c0f0dfc367286a00c 100644 --- a/src/generic/DumpAtoms.cpp +++ b/src/generic/DumpAtoms.cpp @@ -23,7 +23,7 @@ #include "core/ActionPilot.h" #include "core/ActionRegister.h" #include "tools/Pbc.h" -#include "tools/PlumedFile.h" +#include "tools/File.h" #include "core/PlumedMain.h" #include "core/Atoms.h" #include "tools/Units.h" @@ -63,7 +63,7 @@ class DumpAtoms: public ActionAtomistic, public ActionPilot { - PlumedOFile of; + OFile of; double lenunit; public: DumpAtoms(const ActionOptions&); diff --git a/src/generic/DumpDerivatives.cpp b/src/generic/DumpDerivatives.cpp index 04da026b3ec679a5f284184a17050182c919f1c0..7eb9942f81e25455f30e252f7fbbd26d419d654b 100644 --- a/src/generic/DumpDerivatives.cpp +++ b/src/generic/DumpDerivatives.cpp @@ -22,7 +22,7 @@ #include "core/ActionPilot.h" #include "core/ActionWithArguments.h" #include "core/ActionRegister.h" -#include "tools/PlumedFile.h" +#include "tools/File.h" using namespace std; @@ -58,7 +58,7 @@ public ActionWithArguments { string file; string fmt; - PlumedOFile of; + OFile of; public: void calculate(){}; DumpDerivatives(const ActionOptions&); diff --git a/src/generic/DumpForces.cpp b/src/generic/DumpForces.cpp index 7cfda754316e3fd8115548d4a3eebb100383fe65..c010e6650f9efe85e5c73a745315b0d7641693a6 100644 --- a/src/generic/DumpForces.cpp +++ b/src/generic/DumpForces.cpp @@ -22,7 +22,7 @@ #include "core/ActionPilot.h" #include "core/ActionWithArguments.h" #include "core/ActionRegister.h" -#include "tools/PlumedFile.h" +#include "tools/File.h" using namespace std; @@ -58,7 +58,7 @@ public ActionPilot, public ActionWithArguments { string file; - PlumedOFile of; + OFile of; public: void calculate(){}; DumpForces(const ActionOptions&); diff --git a/src/generic/DumpProjections.cpp b/src/generic/DumpProjections.cpp index e50d027c361fec75aaba2331e7a5725d6799ddbc..f8a089c23129d86a2c38fc315bf174a392db4218 100644 --- a/src/generic/DumpProjections.cpp +++ b/src/generic/DumpProjections.cpp @@ -22,7 +22,7 @@ #include "core/ActionPilot.h" #include "core/ActionWithArguments.h" #include "core/ActionRegister.h" -#include "tools/PlumedFile.h" +#include "tools/File.h" using namespace std; @@ -42,7 +42,7 @@ public ActionWithArguments { string file; string fmt; - PlumedOFile of; + OFile of; public: void calculate(){}; DumpProjections(const ActionOptions&); diff --git a/src/generic/Print.cpp b/src/generic/Print.cpp index 5101b67b744b63ae41a492cc54cba3f176c30ef3..3d3e137b6c40f0532968d5807abd59f49c19ed89 100644 --- a/src/generic/Print.cpp +++ b/src/generic/Print.cpp @@ -56,7 +56,7 @@ public ActionPilot, public ActionWithArguments { string file; - PlumedOFile ofile; + OFile ofile; string fmt; // small internal utility ///////////////////////////////////////// diff --git a/src/generic/Read.cpp b/src/generic/Read.cpp index 20a770f13f3ce6b24c3ab0cc5e378aeb8d94079a..bfaca652a18b8b9606a11bfc25a2466625fa7f8a 100644 --- a/src/generic/Read.cpp +++ b/src/generic/Read.cpp @@ -46,7 +46,7 @@ private: bool cloned_file; unsigned nlinesPerStep; std::string filename; - PlumedIFile* ifile; + IFile* ifile; std::vector<Value*> readvals; public: static void registerKeywords( Keywords& keys ); @@ -57,7 +57,7 @@ public: void calculate(); void update(); std::string getFilename() const; - PlumedIFile* getFile(); + IFile* getFile(); }; PLUMED_REGISTER_ACTION(Read,"READ") @@ -91,7 +91,7 @@ nlinesPerStep(1) } } if( !cloned_file ){ - ifile=new PlumedIFile(); + ifile=new IFile(); if( !ifile->FileExist(filename) ) error("could not find file named " + filename); ifile->link(*this); ifile->open(filename); @@ -144,7 +144,7 @@ std::string Read::getFilename() const { return filename; } -PlumedIFile* Read::getFile(){ +IFile* Read::getFile(){ return ifile; } diff --git a/src/tools/PlumedFile.cpp b/src/tools/File.cpp similarity index 82% rename from src/tools/PlumedFile.cpp rename to src/tools/File.cpp index e612151ff0ba3281d434d51630ba5c96d889a4a6..0fc8a52e21304855f298d350c44a31f7932ad4d0 100644 --- a/src/tools/PlumedFile.cpp +++ b/src/tools/File.cpp @@ -19,7 +19,7 @@ You should have received a copy of the GNU Lesser General Public License along with plumed. If not, see <http://www.gnu.org/licenses/>. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ -#include "PlumedFile.h" +#include "File.h" #include "PlumedException.h" #include "core/Action.h" #include "core/PlumedMain.h" @@ -34,8 +34,8 @@ using namespace PLMD; -void PlumedFileBase::test(){ - PLMD::PlumedOFile pof; +void FileBase::test(){ + PLMD::OFile pof; pof.open("ciao"); pof.printf("%s\n","test1"); pof.setLinePrefix("plumed: "); @@ -48,7 +48,7 @@ void PlumedFileBase::test(){ pof.printField("x3",67.0).printField("x1",18.0).printField(); pof.close(); - PLMD::PlumedIFile pif; + PLMD::IFile pif; std::string s; pif.open("ciao"); pif.getline(s); std::printf("%s\n",s.c_str()); @@ -61,18 +61,18 @@ void PlumedFileBase::test(){ pif.close(); } -size_t PlumedOFile::llwrite(const char*ptr,size_t s){ +size_t OFile::llwrite(const char*ptr,size_t s){ size_t r; if(linked) return linked->llwrite(ptr,s); if(! (comm && comm->Get_rank()>0)){ - if(!fp) plumed_merror("writing on uninitilized PlumedFile"); + if(!fp) plumed_merror("writing on uninitilized File"); r=fwrite(ptr,1,s,fp); } if(comm) comm->Bcast(&r,1,0); return r; } -size_t PlumedIFile::llread(char*ptr,size_t s){ +size_t IFile::llread(char*ptr,size_t s){ plumed_assert(fp); size_t r; r=fread(ptr,1,s,fp); @@ -81,13 +81,13 @@ size_t PlumedIFile::llread(char*ptr,size_t s){ return r; } -PlumedFileBase& PlumedFileBase::link(FILE*fp){ +FileBase& FileBase::link(FILE*fp){ this->fp=fp; cloned=true; return *this; } -PlumedFileBase& PlumedFileBase::flush(){ +FileBase& FileBase::flush(){ fflush(fp); if(heavyFlush){ fclose(fp); @@ -96,27 +96,27 @@ PlumedFileBase& PlumedFileBase::flush(){ return *this; } -PlumedFileBase& PlumedFileBase::link(Communicator&comm){ +FileBase& FileBase::link(Communicator&comm){ plumed_massert(!fp,"cannot link an already open file"); this->comm=&comm; return *this; } -PlumedFileBase& PlumedFileBase::link(PlumedMain&plumed){ +FileBase& FileBase::link(PlumedMain&plumed){ plumed_massert(!fp,"cannot link an already open file"); this->plumed=&plumed; link(plumed.comm); return *this; } -PlumedFileBase& PlumedFileBase::link(Action&action){ +FileBase& FileBase::link(Action&action){ plumed_massert(!fp,"cannot link an already open file"); this->action=&action; link(action.plumed); return *this; } -PlumedFileBase& PlumedFileBase::open(const std::string& path,const std::string& mode){ +FileBase& FileBase::open(const std::string& path,const std::string& mode){ plumed_assert(!cloned); eof=false; err=false; @@ -135,7 +135,7 @@ PlumedFileBase& PlumedFileBase::open(const std::string& path,const std::string& } -bool PlumedFileBase::FileExist(const std::string& path){ +bool FileBase::FileExist(const std::string& path){ FILE *ff=NULL; bool do_exist=false; if(plumed){ @@ -150,13 +150,13 @@ bool PlumedFileBase::FileExist(const std::string& path){ return do_exist; } -bool PlumedFileBase::isOpen(){ +bool FileBase::isOpen(){ bool isopen=false; if(fp) isopen=true; return isopen; } -void PlumedFileBase::close(){ +void FileBase::close(){ plumed_assert(!cloned); eof=false; err=false; @@ -164,7 +164,7 @@ void PlumedFileBase::close(){ fp=NULL; } -PlumedFileBase::PlumedFileBase(): +FileBase::FileBase(): fp(NULL), comm(NULL), plumed(NULL), @@ -176,18 +176,18 @@ PlumedFileBase::PlumedFileBase(): { } -PlumedFileBase::~PlumedFileBase() +FileBase::~FileBase() { if(plumed) plumed->eraseFile(*this); if(!cloned && fp) fclose(fp); } -PlumedFileBase::operator bool()const{ +FileBase::operator bool()const{ return !eof; } -PlumedOFile::PlumedOFile(): +OFile::OFile(): linked(NULL), fieldChanged(false) { @@ -201,23 +201,23 @@ PlumedOFile::PlumedOFile(): for(unsigned i=0;i<1000;++i) buffer_string[i]=0; } -PlumedOFile::~PlumedOFile(){ +OFile::~OFile(){ delete [] buffer_string; delete [] buffer; } -PlumedOFile& PlumedOFile::link(PlumedOFile&l){ +OFile& OFile::link(OFile&l){ fp=NULL; linked=&l; return *this; } -PlumedOFile& PlumedOFile::setLinePrefix(const std::string&l){ +OFile& OFile::setLinePrefix(const std::string&l){ linePrefix=l; return *this; } -int PlumedOFile::printf(const char*fmt,...){ +int OFile::printf(const char*fmt,...){ size_t pointer=strlen(buffer); va_list arg; va_start(arg, fmt); @@ -253,7 +253,7 @@ int PlumedOFile::printf(const char*fmt,...){ return r; } -PlumedOFile& PlumedOFile::addConstantField(const std::string&name){ +OFile& OFile::addConstantField(const std::string&name){ Field f; f.name=name; const_fields.push_back(f); @@ -261,36 +261,36 @@ PlumedOFile& PlumedOFile::addConstantField(const std::string&name){ } -PlumedOFile& PlumedOFile::clearFields(){ +OFile& OFile::clearFields(){ fields.clear(); const_fields.clear(); previous_fields.clear(); return *this; } -PlumedOFile& PlumedOFile::fmtField(const std::string&fmt){ +OFile& OFile::fmtField(const std::string&fmt){ this->fieldFmt=fmt; return *this; } -PlumedOFile& PlumedOFile::fmtField(){ +OFile& OFile::fmtField(){ this->fieldFmt="%23.16lg"; return *this; } -PlumedOFile& PlumedOFile::printField(const std::string&name,double v){ +OFile& OFile::printField(const std::string&name,double v){ sprintf(buffer_string,fieldFmt.c_str(),v); printField(name,buffer_string); return *this; } -PlumedOFile& PlumedOFile::printField(const std::string&name,int v){ +OFile& OFile::printField(const std::string&name,int v){ sprintf(buffer_string," %d",v); printField(name,buffer_string); return *this; } -PlumedOFile& PlumedOFile::printField(const std::string&name,const std::string & v){ +OFile& OFile::printField(const std::string&name,const std::string & v){ unsigned i; for(i=0;i<const_fields.size();i++) if(const_fields[i].name==name) break; if(i>=const_fields.size()){ @@ -305,7 +305,7 @@ PlumedOFile& PlumedOFile::printField(const std::string&name,const std::string & return *this; } -PlumedOFile& PlumedOFile::setupPrintValue( Value *val ){ +OFile& OFile::setupPrintValue( Value *val ){ if( val->isPeriodic() ){ addConstantField("min_" + val->getName() ); addConstantField("max_" + val->getName() ); @@ -313,7 +313,7 @@ PlumedOFile& PlumedOFile::setupPrintValue( Value *val ){ return *this; } -PlumedOFile& PlumedOFile::printField( Value* val, const double& v ){ +OFile& OFile::printField( Value* val, const double& v ){ printField( val->getName(), v ); if( val->isPeriodic() ){ std::string min, max; val->getDomain( min, max ); @@ -323,7 +323,7 @@ PlumedOFile& PlumedOFile::printField( Value* val, const double& v ){ return *this; } -PlumedOFile& PlumedOFile::printField(){ +OFile& OFile::printField(){ bool reprint=false; if(fieldChanged || fields.size()!=previous_fields.size()){ reprint=true; @@ -351,7 +351,7 @@ PlumedOFile& PlumedOFile::printField(){ return *this; } -PlumedOFile& PlumedOFile::open(const std::string&path){ +OFile& OFile::open(const std::string&path){ plumed_assert(!cloned); eof=false; err=false; @@ -392,7 +392,7 @@ PlumedOFile& PlumedOFile::open(const std::string&path){ } -PlumedIFile& PlumedIFile::advanceField(){ +IFile& IFile::advanceField(){ plumed_assert(!inMiddleOfField); std::string line; bool done=false; @@ -436,12 +436,12 @@ PlumedIFile& PlumedIFile::advanceField(){ return *this; } -PlumedIFile& PlumedIFile::open(const std::string&name){ - PlumedFileBase::open(name,"r"); +IFile& IFile::open(const std::string&name){ + FileBase::open(name,"r"); return *this; } -PlumedIFile& PlumedIFile::scanFieldList(std::vector<std::string>&s){ +IFile& IFile::scanFieldList(std::vector<std::string>&s){ if(!inMiddleOfField) advanceField(); if(!*this) return *this; s.clear(); @@ -450,7 +450,7 @@ PlumedIFile& PlumedIFile::scanFieldList(std::vector<std::string>&s){ return *this; } -bool PlumedIFile::FieldExist(const std::string& s){ +bool IFile::FieldExist(const std::string& s){ std::vector<std::string> slist; scanFieldList(slist); int mycount = (int) std::count(slist.begin(), slist.end(), s); @@ -458,7 +458,7 @@ bool PlumedIFile::FieldExist(const std::string& s){ else return false; } -PlumedIFile& PlumedIFile::scanField(const std::string&name,std::string&str){ +IFile& IFile::scanField(const std::string&name,std::string&str){ if(!inMiddleOfField) advanceField(); if(!*this) return *this; unsigned i=findField(name); @@ -467,21 +467,21 @@ PlumedIFile& PlumedIFile::scanField(const std::string&name,std::string&str){ return *this; } -PlumedIFile& PlumedIFile::scanField(const std::string&name,double &x){ +IFile& IFile::scanField(const std::string&name,double &x){ std::string str; scanField(name,str); if(*this) Tools::convert(str,x); return *this; } -PlumedIFile& PlumedIFile::scanField(const std::string&name,int &x){ +IFile& IFile::scanField(const std::string&name,int &x){ std::string str; scanField(name,str); if(*this) Tools::convert(str,x); return *this; } -PlumedIFile& PlumedIFile::scanField(Value* val){ +IFile& IFile::scanField(Value* val){ double ff; scanField( val->getName(), ff ); val->set( ff ); if( FieldExist("min_" + val->getName() ) ){ @@ -495,7 +495,7 @@ PlumedIFile& PlumedIFile::scanField(Value* val){ return *this; } -PlumedIFile& PlumedIFile::scanField(){ +IFile& IFile::scanField(){ if(!ignoreFields){ for(unsigned i=0;i<fields.size();i++){ plumed_assert(fields[i].read); @@ -505,17 +505,17 @@ PlumedIFile& PlumedIFile::scanField(){ return *this; } -PlumedIFile::PlumedIFile(): +IFile::IFile(): inMiddleOfField(false), ignoreFields(false) { } -PlumedIFile::~PlumedIFile(){ +IFile::~IFile(){ plumed_assert(!inMiddleOfField); } -PlumedIFile& PlumedIFile::getline(std::string &str){ +IFile& IFile::getline(std::string &str){ char tmp; str=""; fpos_t pos; @@ -531,20 +531,20 @@ PlumedIFile& PlumedIFile::getline(std::string &str){ return *this; } -unsigned PlumedIFile::findField(const std::string&name)const{ +unsigned IFile::findField(const std::string&name)const{ unsigned i; for(i=0;i<fields.size();i++) if(fields[i].name==name) break; if(i>=fields.size()) plumed_merror(name); return i; } -void PlumedIFile::reset(bool reset){ +void IFile::reset(bool reset){ eof = reset; err = reset; if(!reset) clearerr(fp); return; } -void PlumedIFile::allowIgnoredFields(){ +void IFile::allowIgnoredFields(){ ignoreFields=true; } diff --git a/src/tools/PlumedFile.h b/src/tools/File.h similarity index 75% rename from src/tools/PlumedFile.h rename to src/tools/File.h index 169ae9875adff17d286f51cb73fde5e35fd3e01a..99888dcebefb4e0ac775c70c0ad05812010095ad 100644 --- a/src/tools/PlumedFile.h +++ b/src/tools/File.h @@ -19,8 +19,8 @@ You should have received a copy of the GNU Lesser General Public License along with plumed. If not, see <http://www.gnu.org/licenses/>. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ -#ifndef __PLUMED_tools_PlumedFile_h -#define __PLUMED_tools_PlumedFile_h +#ifndef __PLUMED_tools_File_h +#define __PLUMED_tools_File_h #include <cstdio> #include <vector> @@ -37,17 +37,17 @@ class Value; /** Base class for dealing with files. -This class just provides things which are common among PlumedOFile and PlumedIFile +This class just provides things which are common among OFile and IFile */ -class PlumedFileBase{ +class FileBase{ /// Copy constructor is disabled (private and unimplemented) - PlumedFileBase(const PlumedFileBase&); + FileBase(const FileBase&); /// Assignment operator is disabled (private and unimplemented) - PlumedFileBase& operator=(const PlumedFileBase&); + FileBase& operator=(const FileBase&); protected: /// Internal tool. -/// Base for PlumedIFile::Field and PlumedOFile::Field +/// Base for IFile::Field and OFile::Field class FieldBase{ // everything is public to simplify usage public: @@ -69,8 +69,8 @@ protected: /// If true, file will not be closed in destructor bool cloned; /// Private constructor. -/// In this manner one cannot instantiate a PlumedFileBase object - PlumedFileBase(); +/// In this manner one cannot instantiate a FileBase object + FileBase(); /// Set to true when end of file is encountered bool eof; /// Set to true when error is encountered @@ -81,22 +81,22 @@ protected: bool heavyFlush; public: /// Link to an already open filed - PlumedFileBase& link(FILE*); + FileBase& link(FILE*); /// Link to a PlumedMain object /// Automatically links also the corresponding Communicator. - PlumedFileBase& link(PlumedMain&); + FileBase& link(PlumedMain&); /// Link to a Communicator object - PlumedFileBase& link(Communicator&); + FileBase& link(Communicator&); /// Link to an Action object. /// Automatically links also the corresponding PlumedMain and Communicator. - PlumedFileBase& link(Action&); + FileBase& link(Action&); /// Flushes the file to disk - PlumedFileBase& flush(); + FileBase& flush(); /// Closes the file /// Should be used only for explicitely opened files. void close(); /// Virtual destructor (allows inheritance) - virtual ~PlumedFileBase(); + virtual ~FileBase(); /// Runs a small testcase static void test(); /// Check for error/eof. @@ -104,7 +104,7 @@ public: /// Set heavyFlush flag void setHeavyFlush(){ heavyFlush=true;}; /// Opens the file (without auto-backup) - PlumedFileBase& open(const std::string&name,const std::string& mode); + FileBase& open(const std::string&name,const std::string& mode); /// Check if the file exists bool FileExist(const std::string& path); /// Check if a file is open @@ -116,14 +116,14 @@ public: Class for output files This class provides features similar to those in the standard C "FILE*" type, -but only for sequential output. See PlumedIFile for sequential input. +but only for sequential output. See IFile for sequential input. See the example here for a possible use: \verbatim -#include "PlumedFile.h" +#include "File.h" int main(){ - PLMD::PlumedOFile pof; + PLMD::OFile pof; pof.open("ciao","w"); pof.printf("%s\n","test1"); pof.setLinePrefix("plumed: "); @@ -157,16 +157,16 @@ Notes - "x2" is declared as "constant", which means that it is written using the "SET" keyword. Thus, everytime it is modified, all the headers are repeated in the output file. - printField() without arguments is used as a "newline". -- most methods return a reference to the PlumedOFile itself, to allow chaining many calls on the same line +- most methods return a reference to the OFile itself, to allow chaining many calls on the same line (this is similar to << operator in std::ostream) */ -class PlumedOFile: -public virtual PlumedFileBase{ +class OFile: +public virtual FileBase{ /// Pointer to a linked OFile. -/// see link(PlumedOFile&) - PlumedOFile* linked; +/// see link(OFile&) + OFile* linked; /// Internal buffer for printf char* buffer_string; /// Internal buffer (generic use) @@ -199,58 +199,58 @@ public virtual PlumedFileBase{ unsigned findField(const std::string&name)const; public: /// Constructor - PlumedOFile(); + OFile(); /// Destructor - ~PlumedOFile(); + ~OFile(); /// Allows overloading of link - using PlumedFileBase::link; + using FileBase::link; /// Allows overloading of open - using PlumedFileBase::open; -/// Allows linking this PlumedOFile to another one. -/// In this way, everything written to this PlumedOFile will be immediately -/// written on the linked PlumedOFile. Notice that a PlumedOFile should -/// be either opened explicitly, linked to a FILE or linked to a PlumedOFile - PlumedOFile& link(PlumedOFile&); + using FileBase::open; +/// Allows linking this OFile to another one. +/// In this way, everything written to this OFile will be immediately +/// 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&); /// Opens the file using automatic append/backup - PlumedOFile& open(const std::string&name); + 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 PlumedIFile. - PlumedOFile& setLinePrefix(const std::string&); +/// be parsed using fields in a IFile. + OFile& setLinePrefix(const std::string&); /// Set the format for writing double precision fields - PlumedOFile& fmtField(const std::string&); + OFile& fmtField(const std::string&); /// Reset the format for writing double precision fields to its default - PlumedOFile& fmtField(); + OFile& fmtField(); /// Set the value of a double precision field - PlumedOFile& printField(const std::string&,double); + OFile& printField(const std::string&,double); /// Set the value of a int field - PlumedOFile& printField(const std::string&,int); + OFile& printField(const std::string&,int); /// Set the value of a string field - PlumedOFile& printField(const std::string&,const std::string&); + OFile& printField(const std::string&,const std::string&); /// - PlumedOFile& addConstantField(const std::string&); + OFile& addConstantField(const std::string&); /// Used to setup printing of values - PlumedOFile& setupPrintValue( Value *val ); + OFile& setupPrintValue( Value *val ); /// Print a value - PlumedOFile& printField( Value* val, const double& v ); + OFile& printField( Value* val, const double& v ); /** Close a line. Typically used as \verbatim of.printField("a",a).printField("b",b).printField(); \endverbatim */ - PlumedOFile& printField(); + OFile& printField(); /** Resets the list of fields. As it is only possible to add new constant fields (addConstantField()), this method can be used to clean the field list. */ - PlumedOFile& clearFields(); + OFile& clearFields(); /// Formatted output with explicit format - a la printf int printf(const char*fmt,...); /// Formatted output with << operator template <class T> - friend PlumedOFile& operator<<(PlumedOFile&,const T &); + friend OFile& operator<<(OFile&,const T &); }; @@ -259,12 +259,12 @@ this method can be used to clean the field list. Class for input files This class provides features similar to those in the standard C "FILE*" type, -but only for sequential input. See PlumedOFile for sequential output. +but only for sequential input. See OFile for sequential output. */ -class PlumedIFile: +class IFile: /// Class identifying a single field for fielded output -public virtual PlumedFileBase{ +public virtual FileBase{ class Field: public FieldBase{ public: @@ -281,24 +281,24 @@ public virtual PlumedFileBase{ /// Set to true if you want to allow fields to be ignored in the read in file bool ignoreFields; /// Advance to next field (= read one line) - PlumedIFile& advanceField(); + IFile& advanceField(); /// Find field index by name unsigned findField(const std::string&name)const; public: /// Constructor - PlumedIFile(); + IFile(); /// Destructor - ~PlumedIFile(); + ~IFile(); /// Opens the file - PlumedIFile& open(const std::string&name); + IFile& open(const std::string&name); /// Gets the list of all fields - PlumedIFile& scanFieldList(std::vector<std::string>&); + IFile& scanFieldList(std::vector<std::string>&); /// Read a double field - PlumedIFile& scanField(const std::string&,double&); + IFile& scanField(const std::string&,double&); /// Read a int field - PlumedIFile& scanField(const std::string&,int&); + IFile& scanField(const std::string&,int&); /// Read a string field - PlumedIFile& scanField(const std::string&,std::string&); + IFile& scanField(const std::string&,std::string&); /** Ends a field-formatted line. @@ -307,22 +307,22 @@ Typically used as if.scanField("a",a).scanField("b",b).scanField(); \endverbatim */ - PlumedIFile& scanField(); + IFile& scanField(); /// Get a full line as a string - PlumedIFile& getline(std::string&); + IFile& getline(std::string&); /// Reset end of file void reset(bool); /// Check if a field exist bool FieldExist(const std::string& s); /// Read in a value - PlumedIFile& scanField(Value* val); + IFile& scanField(Value* val); /// Allow some of the fields in the input to be ignored void allowIgnoredFields(); }; /// Write using << syntax template <class T> -PlumedOFile& operator<<(PlumedOFile&of,const T &t){ +OFile& operator<<(OFile&of,const T &t){ of.oss<<t; of.printf("%s",of.oss.str().c_str()); of.oss.str(""); diff --git a/src/tools/Grid.cpp b/src/tools/Grid.cpp index 6561e20d39fad6a8f140962a5c9c317657f3492f..88820bf478618527208b50b2cc8ddb3fa088d395 100644 --- a/src/tools/Grid.cpp +++ b/src/tools/Grid.cpp @@ -28,7 +28,7 @@ #include "Grid.h" #include "Tools.h" #include "core/Value.h" -#include "PlumedFile.h" +#include "File.h" #include "PlumedException.h" #include "KernelFunctions.h" @@ -430,7 +430,7 @@ void Grid::scaleAllValuesAndDerivatives( const double& scalef ){ } } -void Grid::writeHeader(PlumedOFile& ofile){ +void Grid::writeHeader(OFile& ofile){ for(unsigned i=0;i<dimension_;++i){ ofile.addConstantField("min_" + argnames[i]); ofile.addConstantField("max_" + argnames[i]); @@ -439,7 +439,7 @@ void Grid::writeHeader(PlumedOFile& ofile){ } } -void Grid::writeToFile(PlumedOFile& ofile){ +void Grid::writeToFile(OFile& ofile){ vector<double> xx(dimension_); vector<double> der(dimension_); double f; @@ -463,7 +463,7 @@ void Grid::writeToFile(PlumedOFile& ofile){ } } -Grid* Grid::create(const std::string& funcl, std::vector<Value*> args, PlumedIFile& ifile, +Grid* Grid::create(const std::string& funcl, std::vector<Value*> args, IFile& ifile, const vector<std::string> & gmin,const vector<std::string> & gmax, const vector<unsigned> & nbin,bool dosparse, bool dospline, bool doder){ Grid* grid=Grid::create(funcl,args,ifile,dosparse,dospline,doder); @@ -481,7 +481,7 @@ Grid* Grid::create(const std::string& funcl, std::vector<Value*> args, PlumedIFi return grid; } -Grid* Grid::create(const std::string& funcl, std::vector<Value*> args, PlumedIFile& ifile, bool dosparse, bool dospline, bool doder) +Grid* Grid::create(const std::string& funcl, std::vector<Value*> args, IFile& ifile, bool dosparse, bool dospline, bool doder) { Grid* grid=NULL; unsigned nvar=args.size(); bool hasder=false; std::string pstring; @@ -597,7 +597,7 @@ void SparseGrid::addValueAndDerivatives for(unsigned int i=0;i<dimension_;++i) der_[index][i]+=der[i]; } -void SparseGrid::writeToFile(PlumedOFile& ofile){ +void SparseGrid::writeToFile(OFile& ofile){ vector<double> xx(dimension_); vector<double> der(dimension_); double f; diff --git a/src/tools/Grid.h b/src/tools/Grid.h index d3999f17a0dbb85ee17f31f935f7c35035f35505..5e639159741f36872b65ca6c013699e91a7a1462 100644 --- a/src/tools/Grid.h +++ b/src/tools/Grid.h @@ -29,8 +29,8 @@ namespace PLMD{ class Value; -class PlumedIFile; -class PlumedOFile; +class IFile; +class OFile; class KernelFunctions; /// \ingroup TOOLBOX @@ -94,12 +94,12 @@ public: std::vector<unsigned> getNeighbors(const std::vector<double> & x,const std::vector<unsigned> & neigh) const; /// write header for grid file - void writeHeader(PlumedOFile& file); + void writeHeader(OFile& file); /// read grid from file - static Grid* create(const std::string&,std::vector<Value*>,PlumedIFile&,bool,bool,bool); + static Grid* create(const std::string&,std::vector<Value*>,IFile&,bool,bool,bool); /// read grid from file and check boundaries are what is expected from input - static Grid* create(const std::string&, std::vector<Value*>, PlumedIFile&, + static Grid* create(const std::string&, std::vector<Value*>, IFile&, const std::vector<std::string>&,const std::vector<std::string>&, const std::vector<unsigned>&,bool,bool,bool); /// get grid size @@ -132,7 +132,7 @@ public: void addKernel( const KernelFunctions& kernel ); /// dump grid on file - virtual void writeToFile(PlumedOFile&); + virtual void writeToFile(OFile&); virtual ~Grid(){}; }; @@ -181,7 +181,7 @@ class SparseGrid : public Grid void addValueAndDerivatives(unsigned index, double value, std::vector<double>& der); /// dump grid on file - void writeToFile(PlumedOFile&); + void writeToFile(OFile&); virtual ~SparseGrid(){}; }; diff --git a/src/tools/KernelFunctions.cpp b/src/tools/KernelFunctions.cpp index 3cc37830c9f90060f7249ad87d178d7ba0debe3c..a2c8211e1db94067c0110bc90336a670e1bb8f41 100644 --- a/src/tools/KernelFunctions.cpp +++ b/src/tools/KernelFunctions.cpp @@ -212,7 +212,7 @@ double KernelFunctions::evaluate( const std::vector<Value*>& pos, std::vector<do return kval; } -KernelFunctions* KernelFunctions::read( PlumedIFile* ifile, const std::vector<std::string>& valnames ){ +KernelFunctions* KernelFunctions::read( IFile* ifile, const std::vector<std::string>& valnames ){ std::string sss; ifile->scanField("multivariate",sss); std::vector<double> cc( valnames.size() ), sig; if( sss=="true" ){ diff --git a/src/tools/KernelFunctions.h b/src/tools/KernelFunctions.h index 3a7b7e72840e45ad7d4c199ff0db486d50b48aaf..36e5080431b43b2d4aa5bba36f109c22ac495749 100644 --- a/src/tools/KernelFunctions.h +++ b/src/tools/KernelFunctions.h @@ -59,7 +59,7 @@ public: /// Evaluate the kernel function double evaluate( const std::vector<Value*>& pos, std::vector<double>& derivatives, bool usederiv=true ) const; /// Read a kernel function from a file - static KernelFunctions* read( PlumedIFile* ifile, const std::vector<std::string>& valnames ); + static KernelFunctions* read( IFile* ifile, const std::vector<std::string>& valnames ); }; inline diff --git a/src/tools/Log.h b/src/tools/Log.h index aa1df3fb44c23f49a5d1b1048d2c0def38e5db99..b75ca716885983a741e88b7da6e58b1aeaf898e9 100644 --- a/src/tools/Log.h +++ b/src/tools/Log.h @@ -26,7 +26,7 @@ #include <string> #include <sstream> -#include "PlumedFile.h" +#include "File.h" namespace PLMD{ @@ -39,7 +39,7 @@ class Communicator; /// lines with the "PLUMED:" prefix, useful to grep out plumed /// log from output class Log : - public PlumedOFile + public OFile { }; diff --git a/src/tools/Tools.cpp b/src/tools/Tools.cpp index 0a5c20b221a491e4f00ed5c092c20d3496d81d07..438226eb9ee0d5a85922d9a361dac9b7018e137b 100644 --- a/src/tools/Tools.cpp +++ b/src/tools/Tools.cpp @@ -23,7 +23,7 @@ #include "Tools.h" #include "AtomNumber.h" #include "PlumedException.h" -#include "PlumedFile.h" +#include "File.h" #include <cstring> #include <dirent.h> @@ -134,7 +134,7 @@ vector<string> Tools::getWords(const string & line,const char* separators,int * return words; } -bool Tools::getParsedLine(PlumedIFile& ifile,vector<string> & words){ +bool Tools::getParsedLine(IFile& ifile,vector<string> & words){ string line(""); words.clear(); bool stat; diff --git a/src/tools/Tools.h b/src/tools/Tools.h index b8a9c2c9430d879bea7b4fa88a4adea33499334c..9db36d0132c67bcea281ae0b41f4bb910965509f 100644 --- a/src/tools/Tools.h +++ b/src/tools/Tools.h @@ -33,7 +33,7 @@ namespace PLMD{ -class PlumedIFile; +class IFile; /// \ingroup TOOLBOX /// Very small non-zero number @@ -62,7 +62,7 @@ public: /// Get a parsed line from the file pointer ifile /// This function already takes care of joining continued lines and splitting the /// resulting line into an array of words - static bool getParsedLine(PlumedIFile&ifile,std::vector<std::string> & line); + static bool getParsedLine(IFile&ifile,std::vector<std::string> & line); /// Convert a string to a double, reading it static bool convert(const std::string & str,double & t); /// Convert a string to a int, reading it