[cig-commits] [commit] master: Added code which enables to use breakline (//) in the input file. (aadd89b)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Mon May 19 18:16:19 PDT 2014


Repository : https://github.com/geodynamics/aspect

On branch  : master
Link       : https://github.com/geodynamics/aspect/compare/49421dcfc1bae9b9234e1f6a01b2da3198b8295c...a47d240e63234d5806d4fdb38f78b57c78948cf7

>---------------------------------------------------------------

commit aadd89b4a72ccebfbb93599f17744d404215f9e4
Author: MFraters <menno.fraters at hotmail.com>
Date:   Tue May 20 00:56:06 2014 +0200

    Added code which enables to use breakline (//) in the input file.


>---------------------------------------------------------------

aadd89b4a72ccebfbb93599f17744d404215f9e4
 source/main.cc | 43 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)

diff --git a/source/main.cc b/source/main.cc
index 73a8186..3e99e62 100644
--- a/source/main.cc
+++ b/source/main.cc
@@ -157,6 +157,43 @@ void possibly_load_shared_libs (const std::string &parameter_filename)
 }
 
 
+/** Look up break line sign (//) at the end of a line and merge this line with the next one  */
+std::string
+expand_backslashes (const std::string &filename)
+{
+  std::string result;
+
+  unsigned int need_empty_lines = 0;
+
+  std::ifstream input (filename.c_str());
+  while (input)
+    {
+      // get one line and strip spaces at the front and back
+      std::string line;
+      std::getline(input, line);
+      while ((line.size() > 0)
+             && (line[line.size() - 1] == ' ' || line[line.size() - 1] == '\t'))
+        line.erase(line.size() - 1, std::string::npos);
+
+      if ((line.size() > 0) && (line[line.size()-1] == '\\'))
+        {
+          result += line.substr(0, line.size()-2);;
+          ++need_empty_lines;
+        }
+      else
+        {
+          result += line;
+          result += '\n';
+
+          for (; need_empty_lines>0; --need_empty_lines)
+            result += '\n';
+        }
+    }
+
+  return result;
+}
+
+
 int main (int argc, char *argv[])
 {
   using namespace dealii;
@@ -236,14 +273,14 @@ int main (int argc, char *argv[])
       // is only read at run-time
       ParameterHandler prm;
 
-      std::ifstream parameter_file(parameter_filename.c_str());
+      const std::string input_file = expand_backslashes (parameter_filename);
       switch (dim)
         {
           case 2:
           {
             aspect::Simulator<2>::declare_parameters(prm);
 
-            const bool success = prm.read_input(parameter_file);
+            const bool success = prm.read_input_from_string(input_file.c_str());
             AssertThrow(success, ExcMessage ("Invalid input parameter file."));
 
             aspect::Simulator<2> flow_problem(MPI_COMM_WORLD, prm);
@@ -256,7 +293,7 @@ int main (int argc, char *argv[])
           {
             aspect::Simulator<3>::declare_parameters(prm);
 
-            const bool success = prm.read_input(parameter_file);
+            const bool success = prm.read_input_from_string(input_file.c_str());
             AssertThrow(success, ExcMessage ("Invalid input parameter file."));
 
             aspect::Simulator<3> flow_problem(MPI_COMM_WORLD, prm);



More information about the CIG-COMMITS mailing list