[cig-commits] r13534 - cs/cigma/trunk/src

luis at geodynamics.org luis at geodynamics.org
Tue Dec 9 18:13:32 PST 2008


Author: luis
Date: 2008-12-09 18:13:32 -0800 (Tue, 09 Dec 2008)
New Revision: 13534

Modified:
   cs/cigma/trunk/src/cli_compare_cmd.cpp
   cs/cigma/trunk/src/cli_eval_cmd.cpp
   cs/cigma/trunk/src/cli_extract_cmd.cpp
   cs/cigma/trunk/src/core_eval_op.cpp
   cs/cigma/trunk/src/core_eval_op.h
   cs/cigma/trunk/src/core_readers.cpp
   cs/cigma/trunk/src/core_writers.cpp
   cs/cigma/trunk/src/io_file_reader.cpp
   cs/cigma/trunk/src/io_file_writer.cpp
   cs/cigma/trunk/src/io_hdf5_reader.cpp
   cs/cigma/trunk/src/io_hdf5_writer.cpp
Log:
Updated exception throwing code

Now we build the exception message using std::ostringstream

Modified: cs/cigma/trunk/src/cli_compare_cmd.cpp
===================================================================
--- cs/cigma/trunk/src/cli_compare_cmd.cpp	2008-12-10 02:13:30 UTC (rev 13533)
+++ cs/cigma/trunk/src/cli_compare_cmd.cpp	2008-12-10 02:13:32 UTC (rev 13534)
@@ -27,11 +27,11 @@
 void CompareCmd::defineOptions()
 {
     BaseCmd::defineOptions();
+
     opts_section = "Compare Options: ";
     opts.add_options()
-        ("help,h", "produce help message")
-        ("verbose,v", "produce verbose output")
-        ("debug,D", "print debugging information")  // XXX: make this a hidden option
+        //("verbose,v", "produce verbose output")
+        //("debug,D", "print debugging information")  // XXX: make this a hidden option
         ("mesh,m", po::value<string>(&imesh), "Integration mesh")
         ("first,a", po::value<string>(&first), "First field path")
         ("second,b", po::value<string>(&second), "Second field path")
@@ -63,14 +63,14 @@
         TRI_LOG_OFF();
     }
 
+    TRI_LOG_STR("CompareCmd::configure()");
+
     if (vm.count("verbose"))
     {
         op.verbose = true;
         op.freq = 1000;
     }
 
-    TRI_LOG_STR("CompareCmd::configure()");
-
     op.first_name = first;
     op.second_name = second;
 

Modified: cs/cigma/trunk/src/cli_eval_cmd.cpp
===================================================================
--- cs/cigma/trunk/src/cli_eval_cmd.cpp	2008-12-10 02:13:30 UTC (rev 13533)
+++ cs/cigma/trunk/src/cli_eval_cmd.cpp	2008-12-10 02:13:32 UTC (rev 13534)
@@ -31,14 +31,15 @@
 
 void EvalCmd::defineOptions()
 {
+    BaseCmd::defineOptions();
+
     opts_section = "Eval Options: ";
     opts.add_options()
-        ("help,h", "produce help message")
-        ("verbose,v", "produce verbose output")
-        ("debug,D", "print debugging information")      /* XXX: make this a hidden option */
+        //("verbose,v", "produce verbose output")
+        //("debug,D", "print debugging information")      /* XXX: make this a hidden option */
         ("function,f", po::value<string>(&function), "Function <FUNC> to evaluate")
         ("points,p", po::value<string>(&points), "Input quadrature points <QPTS-IN>")
-        ("output,o", po::value<string>(&values), "Output values of function <QVALS-OUT")
+        ("output,o", po::value<string>(&values), "Output values of function <QVALS-OUT>")
         ;
     args.add("function", 1);
     args.add("points", 1);
@@ -58,13 +59,31 @@
         TRI_LOG_OFF();
     }
 
+    TRI_LOG_STR("EvalCmd::configure()");
+
     if (vm.count("verbose"))
     {
         op.verbose = true;
     }
 
-    TRI_LOG_STR("EvalCmd::configure()");
+    if (!vm.count("function"))
+    {
+        string msg("No function was specified (use --function option)");
+        throw cigma::Exception("EvalCmd::configure", msg, 1);
+    }
 
+    if (!vm.count("points"))
+    {
+        string msg("No points were specified (use --points option)");
+        throw cigma::Exception("EvalCmd::configure", msg, 1);
+    }
+
+    if (!vm.count("output"))
+    {
+        string msg("No output file for values was specified (use --output option)");
+        throw cigma::Exception("EvalCmd::configure", msg, 1);
+    }
+
     op.fn_name = this->function;
     op.nc_path = DataPath(this->points);
 
@@ -90,7 +109,9 @@
 
     if (op.verbose)
     {
-        cout << "Creating file " << path.filename() << endl;
+        cout << "Writing function values to the file '"
+             << path.filename() << "'"
+             << endl;
     }
 
     WriteArray(path, op.values);

Modified: cs/cigma/trunk/src/cli_extract_cmd.cpp
===================================================================
--- cs/cigma/trunk/src/cli_extract_cmd.cpp	2008-12-10 02:13:30 UTC (rev 13533)
+++ cs/cigma/trunk/src/cli_extract_cmd.cpp	2008-12-10 02:13:32 UTC (rev 13534)
@@ -1,6 +1,7 @@
 #include "cli_extract_cmd.h"
 #include "Exception.h"
 #include "DataPath.h"
+#include "Filesystem.h"
 #include "core_writers.h"
 
 #include <iostream>
@@ -11,6 +12,7 @@
 using namespace cigma;
 
 namespace po = boost::program_options;
+namespace fs = boost::filesystem;
 
 // ----------------------------------------------------------------------------
 
@@ -32,12 +34,12 @@
 
 void ExtractCmd::defineOptions()
 {
+    BaseCmd::defineOptions();
+
     opts_section = "Extract Options: ";
-
     opts.add_options()
-        ("help,h", "produce help message")
-        ("verbose,v", "produce verbose output")
-        ("debug,D", "print debugging information")
+        //("verbose,v", "produce verbose output")
+        //("debug,D", "print debugging information")
         ("rule,r", po::value<string>(&rule), "use a specific quadrature rule")
         ("rule-order,q", po::value<unsigned int>(&rule_order), "use a specific quadrature order")
         ("mesh,m", po::value<string>(&mesh), "mesh file (or path)")
@@ -67,6 +69,7 @@
 
     if (vm.count("verbose"))
     {
+        /*
         if (vm.count("rule"))
         {
             cout << "Rule: " << rule << endl;
@@ -82,13 +85,27 @@
         if (vm.count("output"))
         {
             cout << "Output Points: " << points << endl;
-        }
+        } // */
         op.verbose = true;
     }
 
-    op.quadrature_info.cell_type_name = rule;
+    if (!vm.count("mesh"))
+    {
+        string msg("No mesh was specified (use --mesh option)");
+        throw cigma::Exception("ExtractCmd::configure", msg, 1);
+    }
+
+    if (!vm.count("output"))
+    {
+        string msg("No output file for points was specified (use --output option)");
+        throw cigma::Exception("ExtractCmd::configure", msg, 1);
+    }
+
+
     op.mesh_info.p_mesh = DataPath(mesh);
 
+    op.quadrature_info.cell_type_name = rule;
+
     op.configure();
 }
 
@@ -102,8 +119,8 @@
     }
 
     TRI_LOG_STR("ExtractCmd::run()");
+    TRI_LOG(mesh);
     TRI_LOG(rule);
-    TRI_LOG(mesh);
     TRI_LOG(points);
 
     // Defer work to the appropriate ExtractOp function
@@ -118,12 +135,20 @@
     //  Close the hdf5 file
 
     DataPath path(points);
+    int status;
     
-    int status = op.run();
+    try
+    {
+        status = op.run();
+    }
+    catch (cigma::Exception& e)
+    {
+        throw e;
+    }
 
     if (op.verbose)
     {
-        cout << "Creating file " << path.filename() << endl;
+        cout << "Writing quadrature points to the file " << path.filename() << endl;
     }
     
     WriteQPoints(path, op.weights, op.points);

Modified: cs/cigma/trunk/src/core_eval_op.cpp
===================================================================
--- cs/cigma/trunk/src/core_eval_op.cpp	2008-12-10 02:13:30 UTC (rev 13533)
+++ cs/cigma/trunk/src/core_eval_op.cpp	2008-12-10 02:13:32 UTC (rev 13534)
@@ -2,7 +2,9 @@
 #include "core_readers.h"
 #include "tri_logger.hpp"
 #include <boost/shared_ptr.hpp>
+#include "fn_zero.h"
 #include <iostream>
+#include <sstream>
 
 using namespace std;
 using namespace cigma;
@@ -23,30 +25,43 @@
 
     if (!function)
     {
-        assert(fn_name != ""); // XXX: throw cigma::Exception instead
         function = Function::New(fn_name.c_str());
     }
     if (!function)
     {
-        string msg("No function specified");
+        //function = ReadField(field_info);
+    }
+    if (!function)
+    {
+        string msg("No function was specified");
         throw cigma::Exception("EvalOp::configure", msg);
     }
 
     if (!coords)
     {
         coords = ReadNodeCoordinates(nc_path);
+        if (!coords)
+        {
+            string msg("No points specified");
+            throw cigma::Exception("EvalOp::configure", msg);
+        }
     }
-    if (!coords)
+
+    if (fn_name == "zero")
     {
-        string msg("No points specified");
-        throw cigma::Exception("EvalOp::configure", msg);
-                
+        ZeroFunction *fn = static_cast<ZeroFunction*>(&(*function));
+        fn->setShape(coords->n_dim(), 1);
     }
 
     if (coords->n_dim() != function->n_dim())
     {
+        ostringstream stream;
+        stream << "Dimension mismatch between"
+               << " function domain (dim " << function->n_dim() << ")"
+               << " and evaluation points (dim " << coords->n_dim() << ")"
+               << std::ends;
         string msg("Dimension mismatch for function domain and coordinates");
-        throw cigma::Exception("EvalOp::configure", msg);
+        throw cigma::Exception("EvalOp::configure", stream.str(), 3);
     }
 
 }

Modified: cs/cigma/trunk/src/core_eval_op.h
===================================================================
--- cs/cigma/trunk/src/core_eval_op.h	2008-12-10 02:13:30 UTC (rev 13533)
+++ cs/cigma/trunk/src/core_eval_op.h	2008-12-10 02:13:32 UTC (rev 13534)
@@ -2,10 +2,10 @@
 #define __CIGMA_EVAL_OP_H__
 
 #include "core_base_op.h"
-#include "DataPath.h"
+#include "core_readers.h"
+#include "core_array.h"
 #include "Function.h"
 #include "NodeCoordinates.h"
-#include "core_array.h"
 
 namespace cigma
 {
@@ -25,6 +25,7 @@
 public:
 
     std::string fn_name;
+    FieldInfo field_info;
     DataPath nc_path;
 
     boost::shared_ptr<Function> function;

Modified: cs/cigma/trunk/src/core_readers.cpp
===================================================================
--- cs/cigma/trunk/src/core_readers.cpp	2008-12-10 02:13:30 UTC (rev 13533)
+++ cs/cigma/trunk/src/core_readers.cpp	2008-12-10 02:13:32 UTC (rev 13534)
@@ -6,6 +6,7 @@
 #include "Common.h"
 #include "io_file_reader.h"
 #include <string>
+#include <sstream>
 
 using namespace std;
 using namespace cigma;
@@ -69,7 +70,11 @@
         int status = reader->getCoordinates(location.c_str(), &(nc->coords), &(nc->nno), &(nc->nsd));
         if (status < 0)
         {
-            throw cigma::Exception("ReadNodeCoordinates", "Error in HDF5 reader");
+            std::ostringstream stream;
+            stream << "Could not read node coordinates from location '"
+                   << location << "' in HDF5 file '" << filename << "'"
+                   << std::ends;
+            throw cigma::Exception("ReadNodeCoordinates", stream.str());
         }
         nc_ptr = nc;
     }
@@ -84,13 +89,19 @@
         int status = reader->getCoordinates("", &(nc->coords), &(nc->nno), &(nc->nsd));
         if (status < 0)
         {
+            std::ostringstream stream;
+            stream << "Could not read node coordinates from text file '"
+                   << filename << "'" << std::ends;
             throw cigma::Exception("ReadNodeCoordinates", "Error in text reader");
         }
         nc_ptr = nc;
     }
     else
     {
-        throw cigma::Exception("ReadNodeCoordinates", "Could not load data path");
+        std::ostringstream stream;
+        stream << "Could not read node coordinates from path '"
+               << nc_path << "'" << std::ends;
+        throw cigma::Exception("ReadNodeCoordinates", stream.str());
     }
 
     return nc_ptr;
@@ -117,7 +128,11 @@
         int status = reader->getConnectivity(location.c_str(), &(eb->connect), &(eb->nel), &(eb->ndofs));
         if (status < 0)
         {
-            throw cigma::Exception("ReadElementBlock", "Error in HDF5 reader");
+            std::ostringstream stream;
+            stream << "Could not open element block from location '"
+                   << location << "' in HDF5 file '" << filename << "'"
+                   << std::ends;
+            throw cigma::Exception("ReadElementBlock", stream.str());
         }
         eb_ptr = eb;
     }
@@ -132,7 +147,10 @@
         int status = reader->getConnectivity("", &(eb->connect), &(eb->nel), &(eb->ndofs));
         if (status < 0)
         {
-            throw cigma::Exception("ReadElementBlock", "Error in text reader");
+            std::ostringstream stream;
+            stream << "Could not open element block from text file '"
+                   << filename << "'" << std::ends;
+            throw cigma::Exception("ReadElementBlock", stream.str());
         }
         eb_ptr = eb;
     }
@@ -164,8 +182,7 @@
     }
     catch (cigma::Exception& e)
     {
-        string msg("Could not read NodeCoordinates");
-        throw cigma::Exception("ReadMeshPart", msg);
+        throw cigma::Exception("ReadMeshPart", e.getMessage());
     }
 
     // load elements
@@ -176,8 +193,7 @@
     }
     catch (cigma::Exception& e)
     {
-        string msg("Could not read ElementBlock");
-        throw cigma::Exception("ReadMeshPart", msg);
+        throw cigma::Exception("ReadMeshPart", e.getMessage());
     }
 
     // load cell type from name
@@ -228,7 +244,7 @@
         }
         else
         {
-            throw cigma::Exception("ReadQuadrature", "No cell type specified!");
+            throw cigma::Exception("ReadQuadrature", "No rule or cell type specified");
         }
     }
     else if (quadrature_info.p_quadrature.empty())
@@ -239,19 +255,22 @@
         //
         if (quadrature_info.p_weights.empty())
         {
-            throw cigma::Exception("ReadQuadrature", "No path to quadrature weights given.");
+            throw cigma::Exception("ReadQuadrature", "No path to quadrature weights was given");
         }
 
         if (quadrature_info.p_points.empty())
         {
-            throw cigma::Exception("ReadQuadrature", "No path to quadrature points given.");
+            throw cigma::Exception("ReadQuadrature", "No path to quadrature points was given");
         }
 
         // load weights array from path
         cigma::array<double> *wts = ReadArray(quadrature_info.p_weights);
         if (wts == 0)
         {
-            throw cigma::Exception("ReadQuadrature", "failed to read quadrature weights!");
+            std::ostringstream stream;
+            stream << "Failed to read quadrature weights from path '"
+                   << quadrature_info.p_weights << "'" << std::ends;
+            throw cigma::Exception("ReadQuadrature", stream.str());
         }
         q_ptr->weights = wts->_data;
         wts->_data = 0;
@@ -261,7 +280,10 @@
         cigma::array<double> *pts = ReadArray(quadrature_info.p_points);
         if (pts == 0)
         {
-            throw cigma::Exception("ReadQuadrature", "failed to read quadrature points!");
+            std::ostringstream stream;
+            stream << "Failed to read quadrature points from path '"
+                   << quadrature_info.p_points << "'" << std::ends;
+            throw cigma::Exception("ReadQuadrature", stream.str());
         }
         q_ptr->points = pts->_data;
         pts->_data = 0;
@@ -274,12 +296,22 @@
         //
         if (!quadrature_info.p_weights.empty())
         {
-            throw cigma::Exception("ReadQuadrature", "quadrature path already specified");
+            std::ostringstream stream;
+            stream << "Don't need to overspecify weights if path '"
+                   << quadrature_info.p_quadrature
+                   << "' has already been given"
+                   << std::ends;
+            throw cigma::Exception("ReadQuadrature", stream.str());
         }
 
         if (!quadrature_info.p_points.empty())
         {
-            throw cigma::Exception("ReadQuadrature", "quadrature path already specified");
+            std::ostringstream stream;
+            stream << "Don't need to overspecify points if path '"
+                   << quadrature_info.p_quadrature
+                   << "' has already been given"
+                   << std::ends;
+            throw cigma::Exception("ReadQuadrature", stream.str());
         }
 
         // load weights & points simultaneously
@@ -350,7 +382,11 @@
         int status = reader->getDataset(location.c_str(), &(dofs_ptr->dofs), &(dofs_ptr->nno), &(dofs_ptr->rank));
         if (status < 0)
         {
-            throw cigma::Exception("ReadDofHandler", "Error in HDF5 reader");
+            std::ostringstream stream;
+            stream << "Could not read dofs from location '"
+                   << location << "' in HDF5 file '" << filename << "'"
+                   << std::ends;
+            throw cigma::Exception("ReadDofHandler", stream.str());
         }
     }
     else if (rt == FileReader::VTK_FILE_READER)
@@ -364,12 +400,16 @@
         int status = reader->getDataset("", &(dofs_ptr->dofs), &(dofs_ptr->nno), &(dofs_ptr->rank));
         if (status < 0)
         {
-            throw cigma::Exception("ReadDofHandler", "Error in text reader");
+            std::ostringstream stream;
+            stream << "Could not read dofs from text file '" << filename << "'" << std::ends;
+            throw cigma::Exception("ReadDofHandler", stream.str());
         }
     }
     else
     {
-        throw cigma::Exception("ReadDofHandler", "could not load data path");
+        std::ostringstream stream;
+        stream << "Could not read dofs from path '" << dofs_path << "'" << std::ends;
+        throw cigma::Exception("ReadDofHandler", stream.str());
     }
 
     return dofs_ptr;

Modified: cs/cigma/trunk/src/core_writers.cpp
===================================================================
--- cs/cigma/trunk/src/core_writers.cpp	2008-12-10 02:13:30 UTC (rev 13533)
+++ cs/cigma/trunk/src/core_writers.cpp	2008-12-10 02:13:32 UTC (rev 13534)
@@ -7,6 +7,7 @@
 #include <boost/shared_ptr.hpp>
 using boost::shared_ptr;
 
+#include <sstream>
 using namespace std;
 
 
@@ -20,11 +21,11 @@
     const FileWriter::WriterType wt = writer->getWriterType();
     if (wt == FileWriter::HDF5_FILE_WRITER)
     {
-        throw cigma::Exception("WriteArray", "need HDF5 writer");
+        throw cigma::Exception("WriteArray", "Need HDF5 writer");
     }
     else if (wt == FileWriter::VTK_FILE_WRITER)
     {
-        throw cigma::Exception("WriteArray", "need VTK writer");
+        throw cigma::Exception("WriteArray", "Need VTK writer");
     }
     else if (wt == FileWriter::TEXT_FILE_WRITER)
     {
@@ -32,12 +33,14 @@
         int status = writer->writeDataset("", data, x.n_points(), x.n_dim());
         if (status < 0)
         {
-            throw cigma::Exception("WriteArray", "could not write dataset to text file");
+            throw cigma::Exception("WriteArray", "Could not write dataset to text file");
         }
     }
     else
     {
-        throw cigma::Exception("WriteArray", "could not write array to path");
+        ostringstream stream;
+        stream << "Could not write array to path '" << path << "'" << std::ends;
+        throw cigma::Exception("WriteArray", stream.str());
     }
 }
 
@@ -45,14 +48,14 @@
 {
     TRI_LOG_STR("cigma::WriteNodeCoordinates()");
     TRI_LOG(path);
-    throw cigma::Exception("WriteNodeCoordinates", "need implementation");
+    throw cigma::Exception("WriteNodeCoordinates", "Need implementation");
 }
 
 void cigma::WriteElementBlock(const DataPath& path, shared_ptr<ElementBlock> eb)
 {
     TRI_LOG_STR("cigma::WriteElementBlock()");
     TRI_LOG(path);
-    throw cigma::Exception("WriteElementBlock", "need implementation");
+    throw cigma::Exception("WriteElementBlock", "Need implementation");
 }
 
 void cigma::WriteQuadrature(const DataPath& path, shared_ptr<Quadrature> Q)
@@ -75,18 +78,26 @@
         status = hdf5_writer->writeDataset(wts_loc.c_str(), Q->weights, Q->npts, 1);
         if (status < 0)
         {
-            throw cigma::Exception("WriteQuadrature", "could not write weights to HDF5 file");
+            ostringstream stream;
+            stream << "Could not write weights to location " << pts_loc
+                   << " in HDF5 file '" << filename << "'"
+                   << std::ends;
+            throw cigma::Exception("WriteQuadrature", stream.str());
         }
 
         status = hdf5_writer->writeDataset(pts_loc.c_str(), Q->points, Q->npts, Q->ndim);
         if (status < 0)
         {
-            throw cigma::Exception("WriteQuadrature", "could not write points to HDF5 file");
+            ostringstream stream;
+            stream << "Could not write quadrature points to location " << wts_loc
+                   << " in the HDF5 file '" << filename << "'"
+                   << std::ends;
+            throw cigma::Exception("WriteQuadrature", stream.str());
         }
     }
     else if (wt == FileWriter::VTK_FILE_WRITER)
     {
-        throw cigma::Exception("WriteQuadrature", "need VTK writer");
+        throw cigma::Exception("WriteQuadrature", "Need VTK writer");
     }
     else if (wt == FileWriter::TEXT_FILE_WRITER)
     {
@@ -94,8 +105,13 @@
         FILE *fp = text_writer->fp;
         if (fp == NULL)
         {
-            throw cigma::Exception("WriteQuadrature", "could not write dataset to text file");
+            ostringstream stream;
+            stream << "Could not write quadrature points to "
+                   << "text file '" << filename << "'"
+                   << std::ends;
+            throw cigma::Exception("WriteQuadrature", stream.str());
         }
+
         const int nq = Q->n_points();
         const int dim = Q->n_dim();
         fprintf(fp, "%d %d\n", nq, 1+dim);
@@ -109,7 +125,9 @@
     }
     else
     {
-        throw cigma::Exception("WriteQuadrature", "could not write quadrature to path");
+        ostringstream stream;
+        stream << "Could not write quadrature to path '" << path << "'" << std::ends;
+        throw cigma::Exception("WriteQuadrature", stream.str());
     }
 }
 
@@ -146,7 +164,9 @@
 {
     TRI_LOG_STR("cigma::WriteDofs()");
     TRI_LOG(path);
-    throw cigma::Exception("WriteDofs", "need implementation");
+
+    // XXX: Forward appropriate request to WriteArray
+    throw cigma::Exception("WriteDofs", "Need implementation");
 }
 
 void cigma::WriteResiduals(const DataPath& path, shared_ptr<Residuals> residuals)
@@ -172,12 +192,15 @@
         status = hdf5_writer->writeDataset(eps_loc.c_str(), epsilon, residuals->nel, 1);
         if (status < 0)
         {
-            throw cigma::Exception("WriteResiduals", "could not write residuals to HDF5 file");
+            ostringstream stream;
+            stream << "Could not write residuals to HDF5 file '" << filename << "'" << std::ends;
+            throw cigma::Exception("WriteResiduals", stream.str());
         }
     }
     else if (wt == FileWriter::VTK_FILE_WRITER)
     {
-        throw cigma::Exception("WriteResiduals", "need VTK writer");
+        // XXX: Build up a cell-based scalar array
+        throw cigma::Exception("WriteResiduals", "Need VTK writer");
     }
     else if (wt == FileWriter::TEXT_FILE_WRITER)
     {
@@ -185,12 +208,16 @@
         int status = writer->writeDataset("", epsilon, residuals->nel, 1);
         if (status < 0)
         {
-            throw cigma::Exception("WriteResiduals", "could not write residuals to text file");
+            ostringstream stream;
+            stream << "Could not write residuals to text file '" << filename << "'" << std::ends;
+            throw cigma::Exception("WriteResiduals", stream.str());
         }
     }
     else
     {
-        throw cigma::Exception("WriteResiduals", "could not write residuals to path");
+        ostringstream stream;
+        stream << "Could not write residuals to path '" << path << "'" << std::ends;
+        throw cigma::Exception("WriteResiduals", stream.str());
     }
 }
 

Modified: cs/cigma/trunk/src/io_file_reader.cpp
===================================================================
--- cs/cigma/trunk/src/io_file_reader.cpp	2008-12-10 02:13:30 UTC (rev 13533)
+++ cs/cigma/trunk/src/io_file_reader.cpp	2008-12-10 02:13:32 UTC (rev 13534)
@@ -5,6 +5,7 @@
 #include <string>
 #include <cstdlib>
 #include <cassert>
+#include <sstream>
 using namespace std;
 
 // boost
@@ -26,11 +27,10 @@
     int status = -1;
 
     fs::path p(filename);
+    string ext = fs::extension(p);
 
     if (fs::exists(p))
     {
-        string ext = fs::extension(p);
-
         if (is_hdf5_extension(ext.c_str()))
         {
             //*
@@ -38,7 +38,9 @@
             status = tmp->open(filename.c_str());
             if (status < 0)
             {
-                throw cigma::Exception("FileReader::New", string("Could not open HDF5 file ") + filename);
+                std::ostringstream stream;
+                stream << "Could not open HDF5 file '" << filename << "' for reading" << std::ends;
+                throw cigma::Exception("FileReader::New", stream.str());
             } // */
             
             //
@@ -52,7 +54,9 @@
             status = tmp->open(filename.c_str());
             if (status < 0)
             {
-                throw cigma::Exception("FileReader::New", string("Could not open VTK file ") + filename);
+                std::ostringstream stream;
+                stream << "Could not open VTK file '" << filename << "' for reading" << std::ends;
+                throw cigma::Exception("FileReader::New", stream.str());
             } // */
             throw cigma::Exception("FileReader::New", "Need VtkReader");
         }
@@ -62,13 +66,17 @@
             status = tmp->open(filename.c_str());
             if (status < 0)
             {
-                throw cigma::Exception("FileReader::New", string("Could not open text file ") + filename);
+                std::ostringstream stream;
+                stream << "Could not open text file '" << filename << "' for reading" << std::ends;
+                throw cigma::Exception("FileReader::New", stream.str());
             }
         }
     }
     else
     {
-        throw cigma::Exception("FileReader::New", string("Could not find file '") + filename + string("'"));
+        std::ostringstream stream;
+        stream << "File '" << filename << "' does not exist" << std::ends;
+        throw cigma::Exception("FileReader::New", stream.str());
     }
 
     return tmp;

Modified: cs/cigma/trunk/src/io_file_writer.cpp
===================================================================
--- cs/cigma/trunk/src/io_file_writer.cpp	2008-12-10 02:13:30 UTC (rev 13533)
+++ cs/cigma/trunk/src/io_file_writer.cpp	2008-12-10 02:13:32 UTC (rev 13534)
@@ -2,7 +2,6 @@
 #include "io_null_writer.h"
 #include "io_text_writer.h"
 #include "io_hdf5_writer.h"
-#include "Exception.h"
 
 /*
 #ifdef HAVE_HDF5
@@ -14,6 +13,9 @@
 #endif
 */
 
+#include "Exception.h"
+
+#include <sstream>
 #include <cassert>
 #include <cstdlib>
 
@@ -29,30 +31,44 @@
     int status = -1;
 
     fs::path p(filename);
+    string ext = fs::extension(p);
 
     if (fs::exists(p))
     {
-        // file exists...overwrite it?
+        // The file exists...don't allow overwriting unless mode is "w"
+        // XXX: how to make exception for HDF5 and NetCDF files?
         if (mode != "w")
         {
-            throw cigma::Exception("FileWriter::New", "Overwriting existing file");
+            std::ostringstream stream;
+            stream << "Overwriting existing file '" << filename << "'" << std::ends;
+            throw cigma::Exception("FileWriter::New", stream.str());
         }
     }
 
-    string ext = fs::extension(p);
-
     if (is_hdf5_extension(ext.c_str()))
     {
         tmp.reset(new HDF5_Writer());
         status = tmp->open(filename.c_str());
         if (status < 0)
         {
-            throw cigma::Exception("FileWriter::New", string("Could not open file ") + filename);
+            std::ostringstream stream;
+            stream << "Could not open HDF5 file '" << filename << "' for writing" << std::ends;
+            throw cigma::Exception("FileWriter::New", stream.str());
         }
     }
     else if (is_vtk_extension(ext.c_str()))
     {
         throw cigma::Exception("FileWriter::New", "Need VTK writer");
+        /*
+        tmp.reset(new VtkWriter());
+        status = tmp->open(filename.c_str());
+        if (status < 0)
+        {
+            std::ostringstream stream;
+            stream << "Could not open VTK file '" << filename << "' for writing" << std::ends;
+            throw cigma::Exception("FileWriter::New", stream.str());
+        }
+        // */
     }
     else if (is_text_extension(ext.c_str()))
     {
@@ -60,7 +76,9 @@
         status = tmp->open(filename.c_str());
         if (status < 0)
         {
-            throw cigma::Exception("FileWriter::New", string("Could not open file ") + filename);
+            std::ostringstream stream;
+            stream << "Could not open text file '" << filename << "' for writing" << std::ends;
+            throw cigma::Exception("FileWriter::New", stream.str());
         }
     }
 

Modified: cs/cigma/trunk/src/io_hdf5_reader.cpp
===================================================================
--- cs/cigma/trunk/src/io_hdf5_reader.cpp	2008-12-10 02:13:30 UTC (rev 13533)
+++ cs/cigma/trunk/src/io_hdf5_reader.cpp	2008-12-10 02:13:32 UTC (rev 13534)
@@ -94,7 +94,7 @@
             array = new MT[size];
             dataset.read(array, predtype_from<MT>());
         }
-        catch(H5::DataSetIException error)
+        catch (H5::DataSetIException error)
         {
             cerr << "Dataset '" << loc << "' could not be read." << endl;
             delete array;
@@ -120,6 +120,11 @@
         error.printError();
         return -1;
     }
+    catch (H5::Exception error)
+    {
+        //error.printError();
+        return -1;
+    }
     return 0;
 }
 

Modified: cs/cigma/trunk/src/io_hdf5_writer.cpp
===================================================================
--- cs/cigma/trunk/src/io_hdf5_writer.cpp	2008-12-10 02:13:30 UTC (rev 13533)
+++ cs/cigma/trunk/src/io_hdf5_writer.cpp	2008-12-10 02:13:32 UTC (rev 13534)
@@ -26,6 +26,11 @@
     try
     {
         H5::Exception::dontPrint();
+
+        // XXX: add mode to argument list
+        // if (mode is rdwr) { file = new H5::H5File(filename, H5F_ACC_RDWR); }
+        // if (mode is create) { file = new H5::H5File(filename, H5F_ACC_CREAT); }
+        // if (mode is trunc) { file = new H5::H5File(filename, H5F_ACC_TRUNC); }
         file = new H5::H5File(filename, H5F_ACC_TRUNC);
     }
     catch (H5::FileIException error)
@@ -74,6 +79,11 @@
         error.printError();
         return -1;
     }
+    catch (H5::Exception error)
+    {
+        //error.printError();
+        return -1;
+    }
     return 0;
 }
 



More information about the CIG-COMMITS mailing list