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

luis at geodynamics.org luis at geodynamics.org
Wed Jan 16 11:32:26 PST 2008


Author: luis
Date: 2008-01-16 11:32:25 -0800 (Wed, 16 Jan 2008)
New Revision: 9073

Added:
   cs/benchmark/cigma/trunk/src/HdfReader.cpp
   cs/benchmark/cigma/trunk/src/HdfReader.h
   cs/benchmark/cigma/trunk/src/tests/TestHdfReader.cpp
Log:
Add HdfReader for provide read-access to the cigma hdf5 files

Added: cs/benchmark/cigma/trunk/src/HdfReader.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/HdfReader.cpp	                        (rev 0)
+++ cs/benchmark/cigma/trunk/src/HdfReader.cpp	2008-01-16 19:32:25 UTC (rev 9073)
@@ -0,0 +1,78 @@
+#include "HdfReader.h"
+#include "h5io.h"
+#include <cstdlib>
+#include <cassert>
+
+// ---------------------------------------------------------------------------
+
+cigma::HdfReader::HdfReader()
+{
+}
+
+cigma::HdfReader::~HdfReader()
+{
+}
+
+// ---------------------------------------------------------------------------
+
+
+void cigma::HdfReader::
+open(std::string filename)
+{
+    file_id = h5io_file_open(filename.c_str(), "r");
+    assert(file_id >= 0);
+}
+
+
+void cigma::HdfReader::
+close()
+{
+}
+
+// ---------------------------------------------------------------------------
+
+void cigma::HdfReader::
+get_coordinates(double **coordinates, int *nno, int *nsd)
+{
+    int rank;
+    const char *path = coords_path.c_str();
+    coords_id = h5io_dset_open(file_id, path, &coords_type, &rank, NULL, NULL);
+    assert(coords_id >= 0);
+    assert(rank == 2);
+
+    int ierr;
+    ierr = h5io_dset_read2(file_id, path, coords_type,
+                           (void **)coordinates, nno, nsd);
+    assert(ierr >= 0);
+}
+
+void cigma::HdfReader::
+get_connectivity(int **connectivity, int *nel, int *ndofs)
+{
+    int rank;
+    const char *path = connect_path.c_str();
+    connect_id = h5io_dset_open(file_id, path, &connect_type, &rank, NULL, NULL);
+    assert(connect_id >= 0);
+    assert(rank == 2);
+
+    int ierr;
+    ierr = h5io_dset_read2(file_id, path, connect_type,
+                           (void **)connectivity, nel, ndofs);
+}
+
+void cigma::HdfReader::
+get_point_data(const char *name, double **data, int *num, int *dim)
+{
+    int rank;
+    const char *path = dataset_path.c_str();
+    dataset_id = h5io_dset_open(file_id, path, &dataset_type, &rank, NULL, NULL);
+    assert(dataset_id >= 0);
+    assert(rank == 2);
+
+    int ierr;
+    ierr = h5io_dset_read2(file_id, path, dataset_type,
+                           (void **)data, num, dim);
+}
+
+
+// ---------------------------------------------------------------------------

Added: cs/benchmark/cigma/trunk/src/HdfReader.h
===================================================================
--- cs/benchmark/cigma/trunk/src/HdfReader.h	                        (rev 0)
+++ cs/benchmark/cigma/trunk/src/HdfReader.h	2008-01-16 19:32:25 UTC (rev 9073)
@@ -0,0 +1,53 @@
+#ifndef __HDF_READER_H__
+#define __HDF_READER_H__
+
+#include <string>
+#include "hdf5.h"
+#include "Reader.h"
+
+namespace cigma
+{
+    class HdfReader;
+}
+
+class cigma::HdfReader : public Reader
+{
+public:
+    HdfReader();
+    ~HdfReader();
+
+public:
+    void open(std::string filename);
+    void close();
+
+public:
+    void set_coordinates_path(const char *loc);
+    void set_connectivity_path(const char *loc);
+    void set_dataset_path(const char *loc);
+
+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);
+
+public:
+    std::string coords_path;
+    std::string connect_path;
+    std::string dataset_path;
+
+    hid_t file_id;
+    hid_t coords_id;
+    hid_t connect_id;
+    hid_t dataset_id;
+
+    hid_t coords_type;
+    hid_t connect_type;
+    hid_t dataset_type;
+
+    //int *coords_shape;
+    //int *connect_shape;
+    //int *dataset_shape;
+};
+
+
+#endif

Added: cs/benchmark/cigma/trunk/src/tests/TestHdfReader.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/tests/TestHdfReader.cpp	                        (rev 0)
+++ cs/benchmark/cigma/trunk/src/tests/TestHdfReader.cpp	2008-01-16 19:32:25 UTC (rev 9073)
@@ -0,0 +1,20 @@
+#include <iostream>
+#include <cstdlib>
+#include <cassert>
+#include "../TextWriter.h"
+#include "../HdfReader.h"
+
+using namespace cigma;
+
+int main(void)
+{
+    TextWriter *writer = new TextWriter();
+    writer->fp = stdout;
+
+    {
+
+    }
+
+    writer->fp = NULL;
+    delete writer;
+}



More information about the cig-commits mailing list