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

Added possibility to read one line at a time

parent a80e3d96
No related branches found
No related tags found
No related merge requests found
......@@ -380,37 +380,45 @@ void PlumedMain::readInputFile(std::string str){
ifile.open(str);
std::vector<std::string> words;
exchangePatterns.setFlag(exchangePatterns.NONE);
while(Tools::getParsedLine(ifile,words)){
if(words.empty())continue;
else if(words[0]=="ENDPLUMED") break;
else if(words[0]=="_SET_SUFFIX"){
plumed_assert(words.size()==2);
setSuffix(words[1]);
}
else if(words[0]=="RANDOM_EXCHANGES"){
exchangePatterns.setFlag(exchangePatterns.RANDOM);
// I convert the seed to -seed because I think it is more general to use a positive seed in input
if(words.size()>2&&words[1]=="SEED") {int seed; Tools::convert(words[2],seed); exchangePatterns.setSeed(-seed); }
} else {
Tools::interpretLabel(words);
Action* action=actionRegister().create(ActionOptions(*this,words));
if(!action){
log<<"ERROR\n";
log<<"I cannot understand line:";
for(unsigned i=0;i<words.size();++i) log<<" "<<words[i];
log<<"\n";
exit(1);
};
action->checkRead();
actionSet.push_back(action);
};
};
while(Tools::getParsedLine(ifile,words)) readInputWords(words);
log.printf("END FILE: %s\n",str.c_str());
log.flush();
pilots=actionSet.select<ActionPilot*>();
}
void PlumedMain::readInputWords(const std::vector<std::string> & words){
plumed_assert(initialized);
if(words.empty())return;
else if(words[0]=="ENDPLUMED") return;
else if(words[0]=="_SET_SUFFIX"){
plumed_assert(words.size()==2);
setSuffix(words[1]);
}
else if(words[0]=="RANDOM_EXCHANGES"){
exchangePatterns.setFlag(exchangePatterns.RANDOM);
// I convert the seed to -seed because I think it is more general to use a positive seed in input
if(words.size()>2&&words[1]=="SEED") {int seed; Tools::convert(words[2],seed); exchangePatterns.setSeed(-seed); }
} else {
std::vector<std::string> interpreted(words);
Tools::interpretLabel(interpreted);
Action* action=actionRegister().create(ActionOptions(*this,interpreted));
if(!action){
log<<"ERROR\n";
log<<"I cannot understand line:";
for(unsigned i=0;i<interpreted.size();++i) log<<" "<<interpreted[i];
log<<"\n";
exit(1);
};
action->checkRead();
actionSet.push_back(action);
};
pilots=actionSet.select<ActionPilot*>();
}
////////////////////////////////////////////////////////////////////////
void PlumedMain::exit(int c){
......
......@@ -160,6 +160,12 @@ public:
\param str name of the file
*/
void readInputFile(std::string str);
/**
Read an input string.
\param str name of the string
*/
void readInputWords(const std::vector<std::string> & str);
/**
Initialize the object.
Should be called once.
......
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