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

luis at geodynamics.org luis at geodynamics.org
Wed Sep 24 04:10:42 PDT 2008


Author: luis
Date: 2008-09-24 04:10:41 -0700 (Wed, 24 Sep 2008)
New Revision: 12953

Added:
   cs/cigma/trunk/src/core_base_op.cpp
   cs/cigma/trunk/src/core_base_op.h
   cs/cigma/trunk/src/core_list_op.cpp
   cs/cigma/trunk/src/core_list_op.h
Log:
Core operations to include in static library

Added: cs/cigma/trunk/src/core_base_op.cpp
===================================================================
--- cs/cigma/trunk/src/core_base_op.cpp	                        (rev 0)
+++ cs/cigma/trunk/src/core_base_op.cpp	2008-09-24 11:10:41 UTC (rev 12953)
@@ -0,0 +1,15 @@
+#include "core_base_op.h"
+using namespace cigma;
+
+// ----------------------------------------------------------------------------
+
+BaseOp::BaseOp()
+{
+    verbose = false;
+}
+
+BaseOp::~BaseOp()
+{
+}
+
+// ----------------------------------------------------------------------------

Added: cs/cigma/trunk/src/core_base_op.h
===================================================================
--- cs/cigma/trunk/src/core_base_op.h	                        (rev 0)
+++ cs/cigma/trunk/src/core_base_op.h	2008-09-24 11:10:41 UTC (rev 12953)
@@ -0,0 +1,23 @@
+#ifndef __CIGMA_BASE_OP_H__
+#define __CIGMA_BASE_OP_H__
+
+#include <boost/noncopyable.hpp>
+#include "ProgressTimer.h"
+
+namespace cigma
+{
+    class BaseOp;
+}
+
+class cigma::BaseOp : private boost::noncopyable
+{
+public:
+    BaseOp();
+    virtual ~BaseOp();
+
+public:
+    bool verbose;
+    ProgressTimer timer;
+};
+
+#endif

Added: cs/cigma/trunk/src/core_list_op.cpp
===================================================================
--- cs/cigma/trunk/src/core_list_op.cpp	                        (rev 0)
+++ cs/cigma/trunk/src/core_list_op.cpp	2008-09-24 11:10:41 UTC (rev 12953)
@@ -0,0 +1,158 @@
+#include "core_list_op.h"
+#include "Filesystem.h"
+//#include "io_vtk_reader.h"
+
+// std
+#include <iostream>
+#include <cstdlib>
+#include <cassert>
+#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 = "";
+}
+
+ListOp::~ListOp()
+{
+}
+
+// ----------------------------------------------------------------------------
+
+
+static int list_h5(const char *filename)
+{
+    assert(filename != 0);
+
+    string cmd = string("h5ls -r ").append(filename);
+    int ret = system(cmd.c_str());
+    if (ret < 0)
+    {
+        cerr << "list: Could not find h5ls in your PATH" << endl;
+    }
+    return ret;
+}
+
+static int list_vtk(const char *filename)
+{
+    cout << "Listing vtk file '" << filename << "'" << endl;
+
+/*
+    assert(filename != 0);
+
+    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;
+}
+
+
+int ListOp::listContents()
+{
+    assert(filename != "");
+
+    // XXX: use file magic number instead of extension?
+
+    fs::path p(filename);
+    string ext = fs::extension(p);
+    
+    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
+    {
+        cerr << "list: Unsupported file extension "
+             << " (found '" << ext << "')"
+             << endl;
+        return -1;
+    }
+
+    return 0; // unreachable
+}
+
+// ----------------------------------------------------------------------------

Added: cs/cigma/trunk/src/core_list_op.h
===================================================================
--- cs/cigma/trunk/src/core_list_op.h	                        (rev 0)
+++ cs/cigma/trunk/src/core_list_op.h	2008-09-24 11:10:41 UTC (rev 12953)
@@ -0,0 +1,24 @@
+#ifndef __CIGMA_LIST_OP_H__
+#define __CIGMA_LIST_OP_H__
+
+#include "core_base_op.h"
+
+namespace cigma
+{
+    class ListOp;
+}
+
+class cigma::ListOp : public cigma::BaseOp
+{
+public:
+
+    ListOp();
+    ~ListOp();
+
+    int listContents();
+
+public:
+    std::string filename;
+};
+
+#endif



More information about the cig-commits mailing list