[cig-commits] [commit] master: Robustify code. (dbbfdd4)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Tue May 20 13:51:01 PDT 2014


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

On branch  : master
Link       : https://github.com/geodynamics/aspect/compare/0586ab6f9cf6ec525c331a8c0113ca155a3f1f87...d148500eae3d92d6094ffdbb7fa3f87712d1deac

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

commit dbbfdd41cb1c6e9b205dd68bcee7a265f4f19329
Author: Wolfgang Bangerth <bangerth at math.tamu.edu>
Date:   Tue May 20 15:42:06 2014 -0500

    Robustify code.


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

dbbfdd41cb1c6e9b205dd68bcee7a265f4f19329
 source/initial_conditions/solidus.cc | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/source/initial_conditions/solidus.cc b/source/initial_conditions/solidus.cc
index 82ab9c6..83146b7 100644
--- a/source/initial_conditions/solidus.cc
+++ b/source/initial_conditions/solidus.cc
@@ -34,13 +34,15 @@ namespace aspect
     {
       data_filename=filename;
       std::ifstream in(data_filename.c_str(), std::ios::in);
-      char temp[256];
+      AssertThrow (in, ExcMessage (std::string("Can't read file <") + filename + ">"));
+
+      std::string dummy;
+
       std::string T_Unit,P_Unit;
       n_points=0;
-      if (in.fail())return;
-      in.getline(temp,256);
+      getline (in, dummy);
       in>>T_Unit>>P_Unit;
-      in.getline(temp,256);
+      getline (in, dummy);
       while (!in.eof())
         {
           double T,p;
@@ -76,7 +78,7 @@ namespace aspect
               P_or_R_array.push_back(p);
               n_points++;
             }
-          in.getline(temp,256);
+          getline (in, dummy);
         }
     }
 
@@ -265,7 +267,20 @@ namespace aspect
           prm.leave_subsection();
           prm.enter_subsection("Data");
           {
-            solidus_filename=prm.get ("Solidus filename");
+            // Get the path to the data files. If it contains a reference
+            // to $ASPECT_SOURCE_DIR, replace it by what CMake has given us
+            // as a #define
+            solidus_filename = prm.get ("Solidus filename");
+            {
+              const std::string      subst_text = "$ASPECT_SOURCE_DIR";
+              std::string::size_type position;
+              while (position = solidus_filename.find (subst_text),  position!=std::string::npos)
+                solidus_filename.replace (solidus_filename.begin()+position,
+                                          solidus_filename.begin()+position+subst_text.size(),
+                                          ASPECT_SOURCE_DIR);
+            }
+
+            // then actually read the file
             solidus_curve.read(solidus_filename);
           }
           prm.leave_subsection();



More information about the CIG-COMMITS mailing list