From e674133c27eae935104d6a30c128820e1fce2409 Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Wed, 23 Jan 2013 13:37:27 +0100
Subject: [PATCH] Added possibility to read one line at a time

---
 src/core/PlumedMain.cpp | 58 +++++++++++++++++++++++------------------
 src/core/PlumedMain.h   |  6 +++++
 2 files changed, 39 insertions(+), 25 deletions(-)

diff --git a/src/core/PlumedMain.cpp b/src/core/PlumedMain.cpp
index 237b79f10..aac2c6c9d 100644
--- a/src/core/PlumedMain.cpp
+++ b/src/core/PlumedMain.cpp
@@ -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){
diff --git a/src/core/PlumedMain.h b/src/core/PlumedMain.h
index b95bffcb7..c9ef949dc 100644
--- a/src/core/PlumedMain.h
+++ b/src/core/PlumedMain.h
@@ -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.
-- 
GitLab