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

luis at geodynamics.org luis at geodynamics.org
Wed Dec 17 02:31:44 PST 2008


Author: luis
Date: 2008-12-17 02:31:42 -0800 (Wed, 17 Dec 2008)
New Revision: 13709

Modified:
   cs/cigma/trunk/src/core_list_op.cpp
Log:
Test if file exists, and throw an exception otherwise

Modified: cs/cigma/trunk/src/core_list_op.cpp
===================================================================
--- cs/cigma/trunk/src/core_list_op.cpp	2008-12-17 10:31:40 UTC (rev 13708)
+++ cs/cigma/trunk/src/core_list_op.cpp	2008-12-17 10:31:42 UTC (rev 13709)
@@ -5,25 +5,16 @@
 #include "io_hdf5_reader.h"
 #include "io_vtk_reader.h"
 
-// std
-#include <iostream>
 #include <cstdlib>
-#include <cassert>
+#include <iostream>
+#include <sstream>
 #include <string>
 
-// VTK
-//#include "vtkDataSet.h"
-//#include "vtkPointData.h"
-//#include "vtkCellData.h"
-
-
 using namespace std;
 using namespace cigma;
 namespace fs = boost::filesystem;
 
 
-// ----------------------------------------------------------------------------
-
 ListOp::ListOp()
 {
     filename = "";
@@ -33,7 +24,6 @@
 {
 }
 
-
 static int list_h5(const char *filename)
 {
     assert(filename != 0);
@@ -47,85 +37,8 @@
     return ret;
 }
 
-
 static int list_vtk(const char *filename)
 {
-    /*
-    cout << "Listing vtk file '" << filename << "'" << endl;
-
-    VtkReader vtkreader;
-    vtkreader.open(filename);
-
-    if (vtkreader.dataset != 0)
-    {
-        vtkDataSet *dataset = vtkreader.dataset;
-
-        vtkPointData *pointData = dataset->GetPointData();
-        //pointData->PrintSelf(cout, 0);
-
-        vtkCellData *cellData = dataset->GetCellData();
-        //cellData->PrintSelf(cout, 0);
-
-
-        // ---------------------------------------------------
-
-        int nno, nel;
-
-        nno = dataset->GetNumberOfPoints();
-        nel = dataset->GetNumberOfCells();
-
-        if (nno > 0)
-        {
-            cout << "Points = " << nno << endl;
-        }
-
-        if (nel > 0)
-        {
-            cout << "Cells = " << nel << endl;
-        }
-
-
-        // ---------------------------------------------------
-        int i, n;
-        int numArrays;
-        int numTuples, numComponents;
-
-        numArrays = pointData->GetNumberOfArrays();
-        if (numArrays > 0)
-        {
-            for (i = 0; i < numArrays; i++)
-            {
-                vtkDataArray *dataArray = pointData->GetArray(i);
-                const char *name = pointData->GetArrayName(i);
-                numTuples = dataArray->GetNumberOfTuples();
-                numComponents = dataArray->GetNumberOfComponents();
-                cout << "PointDataArray[" << i << "] = " << name << " ";
-                //cout << dataArray->GetClassName() << " ";
-                cout << "(" << numTuples << " x " << numComponents << ")";
-                cout << endl;
-            }
-        }
-
-        numArrays = cellData->GetNumberOfArrays();
-        if (numArrays > 0)
-        {
-            for (i = 0; i < numArrays; i++)
-            {
-                vtkDataArray *dataArray = cellData->GetArray(i);
-                const char *name = cellData->GetArrayName(i);
-                numTuples = dataArray->GetNumberOfTuples();
-                numComponents = dataArray->GetNumberOfComponents();
-                cout << "CellDataArray[" << i << "] = " << name << " ";
-                //cout << dataArray->GetClassName() << " ";
-                cout << "(" << numTuples << " x " << numComponents << ")";
-                cout << endl;
-            }
-        }
-
-    }
-    return 0;
-    */
-
     return vtk_print_contents(filename);
 }
 
@@ -145,29 +58,39 @@
 {
     TRI_LOG_STR("ListOp::run()");
 
-    // XXX: Use file magic number instead of extension?
-    // Create static methods in each of the respective readers
-
     fs::path p(filename);
     string ext = fs::extension(p);
     
-    if (is_hdf5_extension(ext.c_str()))
+    // XXX: Use file magic number instead of extension?
+    // Create static methods in each of the respective readers
+
+    if (fs::exists(p))
     {
-        return list_h5(filename.c_str());
+        if (is_hdf5_extension(ext.c_str()))
+        {
+            return list_h5(filename.c_str());
+        }
+        else if (is_vtk_extension(ext.c_str()))
+        {
+            return list_vtk(filename.c_str());
+        }
+        else
+        {
+            std::ostringstream stream;
+            stream << "Unsupported file extension "
+                   << "(found '" << ext << "')"
+                   << std::ends;
+            throw cigma::Exception("ListOp::run", stream.str(), 1);
+        }
     }
-    else if (is_vtk_extension(ext.c_str()))
-    {
-        return list_vtk(filename.c_str());
-    }
     else
     {
-        cerr << "list: Unsupported file extension "
-             << " (found '" << ext << "')"
-             << endl;
-        return -1;
+        std::ostringstream stream;
+        stream << "File '" << filename << "' does not exist!" << std::ends;
+        throw cigma::Exception("ListOp::run", stream.str(), 2);
     }
 
-    return 0; // unreachable
+    return 0;
 }
 
-// ----------------------------------------------------------------------------
+



More information about the CIG-COMMITS mailing list