]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Allow including one input file from another.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Sun, 25 Aug 2013 05:53:26 +0000 (05:53 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Sun, 25 Aug 2013 05:53:26 +0000 (05:53 +0000)
git-svn-id: https://svn.dealii.org/trunk@30477 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/base/parameter_handler.h
deal.II/source/base/parameter_handler.cc

index 9dba3186c6912956d91d0881ea50605fdfd66fe8..e4ff71cee2a45c1b37ddc01a890579ea0958ffd3 100644 (file)
@@ -68,6 +68,13 @@ inconvenience this causes.
 <h3>Specific improvements</h3>
 
 <ol>
+  <li>
+  Fixed: The ParameterHandler class can now deal with including one parameter
+  file from another.
+  <br>
+  (Wolfgang Bangerth, 2013/08/25)
+  </li>
+
   <li>
   New: The method VectorTools::compute_normal_flux_constraints can be used to
   force a vector finite element function to be normal to the boundary.
index e14cc51e98f83986d8ef8fd3be1721986a8e2d6d..70712ea75177d5ae6fed929367ff753eafe8aadc 100644 (file)
@@ -889,7 +889,7 @@ namespace Patterns
  *     set Geometry       = [0,1]x[0,3]
  *   @endcode
  *   Input may be sorted into subsection trees in order to give the input a
- *   logical structure.
+ *   logical structure, and input files may include other files.
  *
  *   The ParameterHandler class is discussed in detail in the @ref step_19
  *   "step-19" example program, and is used in more realistic situations in
@@ -1034,9 +1034,23 @@ namespace Patterns
  *   <tt>=</tt> sign.
  *
  *
+ *   <h3>Including other input files</h3>
+ *
+ *   An input file can include other include files using the syntax
+ *   @code
+ *     ...
+ *     include some_other_file.prm
+ *     ...
+ *   @endcode
+ *   The file so referenced is searched for relative to the current
+ *   directory (not relative to the directory in which the including
+ *   parameter file is located, since this is not known to all three
+ *   versions of the read_input() function).
+ *
+ *
  *   <h3>Reading data from input sources</h3>
  *
- *   In order to read input you can use three possibilities: reading from
+ *   In order to read input there are three possibilities: reading from
  *   an <tt>std::istream</tt> object, reading from a file of which the name
  *   is given and reading from a string in memory in which the lines are
  *   separated by <tt>@\n</tt> characters. These possibilities are used as
index e91986060eb41416043df5e4a60996db3cbe02ef..a9edbef5e5c915a1c5fba7046e82bacd041d54dd 100644 (file)
@@ -2393,6 +2393,42 @@ ParameterHandler::scan_line (std::string         line,
         }
     }
 
+  // an include statement?
+  if ((line.find ("INCLUDE ") == 0) ||
+      (line.find ("include ") == 0))
+    {
+      // erase "set" statement and eliminate
+      // spaces around the '='
+      line.erase (0, 7);
+      while ((line.size() > 0) && (line[0] == ' '))
+        line.erase (0, 1);
+
+      // the remainder must then be a filename
+      if (line.size() == 0)
+        {
+          std::cerr << "Line <" << lineno
+                    << "> of file <" << input_filename
+                    << "> is an include statement but does not name a file!"
+                    << std::endl;
+
+          return false;
+        }
+
+      std::ifstream input (line);
+      if (!input)
+        {
+          std::cerr << "Line <" << lineno
+                    << "> of file <" << input_filename
+                    << "> is an include statement but the file <"
+                    << line << "> could not be opened!"
+                    << std::endl;
+
+          return false;
+        }
+      else
+        return read_input (input);
+    }
+
   // this line matched nothing known
   std::cerr << "Line <" << lineno
             << "> of file <" << input_filename

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.