[cig-commits] r9160 - in cs/benchmark/cigma/trunk/src: . tests

luis at geodynamics.org luis at geodynamics.org
Mon Jan 28 20:04:24 PST 2008


Author: luis
Date: 2008-01-28 20:04:24 -0800 (Mon, 28 Jan 2008)
New Revision: 9160

Modified:
   cs/benchmark/cigma/trunk/src/HdfReader.cpp
   cs/benchmark/cigma/trunk/src/HdfReader.h
   cs/benchmark/cigma/trunk/src/tests/TestHdfReader.cpp
Log:
Added test for HdfReader

Modified: cs/benchmark/cigma/trunk/src/HdfReader.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/HdfReader.cpp	2008-01-29 04:04:22 UTC (rev 9159)
+++ cs/benchmark/cigma/trunk/src/HdfReader.cpp	2008-01-29 04:04:24 UTC (rev 9160)
@@ -27,11 +27,33 @@
 void cigma::HdfReader::
 close()
 {
+    herr_t status = H5Fclose(file_id);
 }
 
 // ---------------------------------------------------------------------------
 
+
 void cigma::HdfReader::
+set_coordinates_path(const char *loc)
+{
+    coords_path = loc;
+}
+
+void cigma::HdfReader::
+set_connectivity_path(const char *loc)
+{
+    connect_path = loc;
+}
+
+void cigma::HdfReader::
+set_dataset_path(const char *loc)
+{
+    dataset_path = loc;
+}
+
+// ---------------------------------------------------------------------------
+
+void cigma::HdfReader::
 get_coordinates(double **coordinates, int *nno, int *nsd)
 {
     int rank;
@@ -41,7 +63,7 @@
     assert(rank == 2);
 
     int ierr;
-    ierr = h5io_dset_read2(file_id, path, coords_type,
+    ierr = h5io_dset_read2(file_id, path, H5T_NATIVE_DOUBLE,
                            (void **)coordinates, nno, nsd);
     assert(ierr >= 0);
 }
@@ -56,12 +78,12 @@
     assert(rank == 2);
 
     int ierr;
-    ierr = h5io_dset_read2(file_id, path, connect_type,
+    ierr = h5io_dset_read2(file_id, path, H5T_NATIVE_INT,
                            (void **)connectivity, nel, ndofs);
 }
 
 void cigma::HdfReader::
-get_point_data(const char *name, double **data, int *num, int *dim)
+get_dataset(double **data, int *num, int *dim)
 {
     int rank;
     const char *path = dataset_path.c_str();
@@ -70,7 +92,7 @@
     assert(rank == 2);
 
     int ierr;
-    ierr = h5io_dset_read2(file_id, path, dataset_type,
+    ierr = h5io_dset_read2(file_id, path, H5T_NATIVE_DOUBLE,
                            (void **)data, num, dim);
 }
 

Modified: cs/benchmark/cigma/trunk/src/HdfReader.h
===================================================================
--- cs/benchmark/cigma/trunk/src/HdfReader.h	2008-01-29 04:04:22 UTC (rev 9159)
+++ cs/benchmark/cigma/trunk/src/HdfReader.h	2008-01-29 04:04:24 UTC (rev 9160)
@@ -28,7 +28,7 @@
 public:
     void get_coordinates(double **coordinates, int *nno, int *nsd);
     void get_connectivity(int **connectivity, int *nel, int *ndofs);
-    void get_point_data(const char *name, double **data, int *num, int *dim);
+    void get_dataset(double **data, int *num, int *dim);
 
 public:
     std::string coords_path;
@@ -43,10 +43,6 @@
     hid_t coords_type;
     hid_t connect_type;
     hid_t dataset_type;
-
-    //int *coords_shape;
-    //int *connect_shape;
-    //int *dataset_shape;
 };
 
 

Modified: cs/benchmark/cigma/trunk/src/tests/TestHdfReader.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/tests/TestHdfReader.cpp	2008-01-29 04:04:22 UTC (rev 9159)
+++ cs/benchmark/cigma/trunk/src/tests/TestHdfReader.cpp	2008-01-29 04:04:24 UTC (rev 9160)
@@ -1,20 +1,160 @@
 #include <iostream>
 #include <cstdlib>
 #include <cassert>
+#include <string>
+#include "../AnyOption.h"
+#include "../StringUtils.h"
 #include "../TextWriter.h"
 #include "../HdfReader.h"
 
+using namespace std;
 using namespace cigma;
 
-int main(void)
+int main(int argc, char *argv[])
 {
-    TextWriter *writer = new TextWriter();
-    writer->fp = stdout;
+    AnyOption *opt = new AnyOption();
+    const char *in;
+    
+    string inputstr;
+    string ext;
 
+    string filename;
+    string coords_file;
+    string connect_file;
+    string field_file;
+
+    string coords_loc;
+    string connect_loc;
+    string field_loc;
+
+    string field_name;
+
+
+    opt->setFlag("help", 'h');
+    opt->setOption("input");
+    opt->setOption("coords");
+    opt->setOption("connect");
+    opt->setOption("field");
+
+    opt->addUsage("Usage:");
+    opt->addUsage("    TestHdfReader [options]");
+    opt->addUsage("      --help         ");
+    opt->addUsage("      --input        Input file");
+    opt->addUsage("      --coords       Location of mesh coordinates");
+    opt->addUsage("      --connect      Location of mesh connectivity");
+    opt->addUsage("      --field        Location of field data");
+
+    opt->processCommandArgs(argc, argv);
+
+    /*
+    if (!opt->hasOptions())
     {
+        opt->printUsage();
+        exit(1);
+    } // */
 
+    if (opt->getFlag("help"))
+    {
+        opt->printUsage();
+        exit(0);
     }
 
+
+    const bool debug = true;
+
+
+    in = opt->getValue("input");
+    if (in == 0)
+    {
+        in = "/home/luis/benchmarks/bmssnog.h5";
+        if (!debug)
+        {
+            cerr << "Please specify the option --input" << endl;
+            exit(1);
+        }
+    }
+    filename = in;
+
+
+    in = opt->getValue("coords");
+    if (in == 0)
+    {
+        in = "/mesh/bmssnog_tet4_0250m/coordinates";
+        if (!debug)
+        {
+            cerr << "Please specify the option --coords" << endl;
+            exit(1);
+        }
+    }
+    coords_loc = in;
+    //inputstr = in;
+    //parse_dataset_path(inputstr, coords_loc, coords_file, ext);
+
+    in = opt->getValue("connect");
+    if (in == 0)
+    {
+        in = "/mesh/bmssnog_tet4_0250m/connectivity";
+        if (!debug)
+        {
+            cerr << "Please specify the option --connect" << endl;
+            exit(1);
+        }
+    }
+    connect_loc = in;
+    //inputstr = in;
+    //parse_dataset_path(inputstr, connect_loc, connect_file, ext);
+
+    in = opt->getValue("field");
+    if (in == 0)
+    {
+        in = "/geofest/bmssnog_tet4_0250m/variables/displacement/step00000";
+        if (!debug)
+        {
+            cerr << "Please specify the option --field" << endl;
+            exit(1);
+        }
+    }
+    field_loc = in;
+    //inputstr = in;
+    //parse_dataset_path(inputstr, field_loc, field_file, ext);
+
+
+    TextWriter *writer = new TextWriter();
+    writer->fp = stdout;
+
+    HdfReader *reader = new HdfReader();
+
+
+    reader->open(filename);
+
+    reader->set_coordinates_path(coords_loc.c_str());
+    reader->set_connectivity_path(connect_loc.c_str());
+    reader->set_dataset_path(field_loc.c_str());
+
+    int nno, nsd;
+    double *coords;
+    reader->get_coordinates(&coords, &nno, &nsd);
+
+    int nel, ndofs;
+    int *connect;
+    reader->get_connectivity(&connect, &nel, &ndofs);
+
+
+    int dset_dims[2];
+    double *dset_data;
+    reader->get_dataset(&dset_data, &dset_dims[0], &dset_dims[1]);
+    
+    cout << "Reading " << filename << endl;
+    cout << "Coordinates: " << coords_loc << " (" << nno << " x " << nsd << ")" << endl;
+    cout << "Connectivity: " << connect_loc << " (" << nel << " x " << ndofs << ")" << endl;
+    cout << "Field: " << field_loc << " (" << dset_dims[0] << " x " << dset_dims[1] << ")" << endl;
+
+
+    sleep(100);
+
+
+    delete reader;
+
     writer->fp = NULL;
     delete writer;
 }



More information about the cig-commits mailing list