24 #include "core/Action.h"
25 #include "core/PlumedMain.h"
26 #include "core/Value.h"
41 if(feof(
fp))
eof=
true;
42 if(ferror(
fp))
err=
true;
52 if(!*
this){
return *
this;}
54 if(words.size()>=2 && words[0]==
"#!" && words[1]==
"FIELDS"){
56 for(
unsigned i=2;i<words.size();i++){
61 }
else if(words.size()==4 && words[0]==
"#!" && words[1]==
"SET"){
69 for(
unsigned i=0;i<
fields.size();i++)
if(!
fields[i].constant) nf++;
72 if( words.size()==nf ){
74 for(
unsigned i=0;i<
fields.size();i++){
75 if(
fields[i].constant)
continue;
81 }
else if( !words.empty() ) {
82 plumed_merror(
"mismatch between number of fields in file and expected number");
97 if(!*
this)
return *
this;
99 for(
unsigned i=0;i<
fields.size();i++)
100 s.push_back(
fields[i].name);
105 std::vector<std::string> slist;
107 int mycount = (int) std::count(slist.begin(), slist.end(), s);
108 if(mycount>0)
return true;
114 if(!*
this)
return *
this;
139 std::string min, max;
151 for(
unsigned i=0;i<
fields.size();i++){
152 plumed_massert(
fields[i].read,
"field "+
fields[i].name+
" was not read: all the fields need to be read otherwise you could miss important infos" );
160 inMiddleOfField(false),
166 if(
inMiddleOfField) std::cerr<<
"WARNING: IFile closed in the middle of reading. seems strange!\n";
174 while(
llread(&tmp,1)==1 && tmp && tmp!=
'\n' && !
eof && !
err){
177 if(
err ||
eof || tmp!=
'\n'){
187 for(i=0;i<
fields.size();i++)
if(
fields[i].name==name)
break;
188 if(i>=
fields.size()) plumed_merror(name);
195 if(!reset) clearerr(
fp);
bool FieldExist(const std::string &s)
Check if a field exist.
const std::string & getName() const
Get the name of the quantity.
IFile & getline(std::string &)
Get a full line as a string.
unsigned findField(const std::string &name) const
Find field index by name.
std::vector< Field > fields
All the defined fields.
A class for holding the value of a function together with its derivatives.
bool inMiddleOfField
Flag set in the middle of a field reading.
void set(double)
Set the value of the function.
void reset(bool)
Reset end of file.
void setNotPeriodic()
Set the function not periodic.
IFile & open(const std::string &name)
Opens the file.
IFile & advanceField()
Advance to next field (= read one line)
bool eof
Set to true when end of file is encountered.
IFile & scanField()
Ends a field-formatted line.
FileBase & open(const std::string &name, const std::string &mode)
Opens the file (without auto-backup)
bool ignoreFields
Set to true if you want to allow fields to be ignored in the read in file.
size_t llread(char *, size_t)
Low-level read.
bool err
Set to true when error is encountered.
IFile & scanFieldList(std::vector< std::string > &)
Gets the list of all fields.
void setDomain(const std::string &, const std::string &)
Set the domain of the function.
void allowIgnoredFields()
Allow some of the fields in the input to be ignored.