[cig-commits] r13635 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Tue Dec 9 18:16:38 PST 2008
Author: luis
Date: 2008-12-09 18:16:38 -0800 (Tue, 09 Dec 2008)
New Revision: 13635
Modified:
cs/cigma/trunk/src/io_hdf5.cpp
cs/cigma/trunk/src/io_hdf5.h
Log:
Updated io_hdf5.{h,cpp} to use the HAVE_HDF5 C preprocessor variable
Modified: cs/cigma/trunk/src/io_hdf5.cpp
===================================================================
--- cs/cigma/trunk/src/io_hdf5.cpp 2008-12-10 02:16:36 UTC (rev 13634)
+++ cs/cigma/trunk/src/io_hdf5.cpp 2008-12-10 02:16:38 UTC (rev 13635)
@@ -1,5 +1,7 @@
#include "io_hdf5.h"
+#ifdef HAVE_HDF5
+
/* predtypes */
/*
template <> H5::PredType predtype_from<int>() { return H5::PredType::NATIVE_INT; }
@@ -73,7 +75,7 @@
-/* open hdf5 file */
+//* open hdf5 file
H5::H5File* h5_open_file(const char *filename, const char *mode)
{
std::string m(mode);
@@ -132,9 +134,10 @@
return file;
}
+// */
-/* open hdf5 group */
+//* open hdf5 group
H5::Group* h5_open_group(H5::H5File *file, const char *loc)
{
H5::Group* group = 0;
@@ -154,9 +157,10 @@
return group;
}
+// */
-/* open hdf5 dataset */
+//* open hdf5 dataset
H5::DataSet* h5_open_dataset(H5::H5File *file, const char *loc)
{
H5::DataSet* dataset = 0;
@@ -176,9 +180,10 @@
return dataset;
}
+// */
-/* open object in hdf5 file */
+//* open object in hdf5 file
H5::H5Object* h5_open_object(H5::H5File *file, const char *loc)
{
H5::H5Object* obj = 0;
@@ -195,9 +200,10 @@
return obj;
}
+// */
-/* open attribute on hdf5 object */
+//* open attribute on hdf5 object
H5::Attribute* h5_open_attribute(H5::H5Object *obj, const char *attr_name)
{
H5::Attribute *attribute = 0;
@@ -215,4 +221,7 @@
return attribute;
}
+// */
+
+#endif /* HAVE_HDF5 */
Modified: cs/cigma/trunk/src/io_hdf5.h
===================================================================
--- cs/cigma/trunk/src/io_hdf5.h 2008-12-10 02:16:36 UTC (rev 13634)
+++ cs/cigma/trunk/src/io_hdf5.h 2008-12-10 02:16:38 UTC (rev 13635)
@@ -1,11 +1,17 @@
#ifndef __CIGMA_IO_HDF5_H__
#define __CIGMA_IO_HDF5_H__
-#include "H5Cpp.h"
-#include "Exception.h"
#include <iostream>
#include <string>
+#include "Common.h"
+
+
+#ifdef HAVE_HDF5
+
+#include "H5Cpp.h"
+
+
/**
* Function template returns an H5::DataType from given C++ type.
* See io_hdf5.cpp for specializations.
@@ -14,7 +20,7 @@
template <typename T>
H5::DataType h5_datatype_from()
{
- throw cigma::Exception("h5_datatype_from", "no mapping available for this datatype");
+ throw cigma::Exception("h5_datatype_from", "no mapping available for this HDF5 datatype");
return H5::DataType();
}
@@ -27,7 +33,7 @@
template <typename T>
H5T_class_t h5_typeclass_from()
{
- throw cigma::Exception("h5_typeclass_from", "no mapping available for this h5_typeclass");
+ throw cigma::Exception("h5_typeclass_from", "no mapping available for this HDF5 typeclass");
return H5T_NO_CLASS;
}
@@ -35,33 +41,163 @@
/**
* Load H5File from filename.
*/
-H5::H5File* h5_open_file(const char *filename, const char *mode);
+H5::H5File* h5_open_file(const char *filename, const char *mode);/*
+{
+ std::string m(mode);
+ H5::H5File *file = 0;
+ try
+ {
+ H5::Exception::dontPrint();
+ if (m == "a")
+ {
+ try
+ {
+ // open existing file in read/write mode
+ file = new H5::H5File(filename, H5F_ACC_RDWR);
+ }
+ catch (H5::FileIException e)
+ {
+ }
+
+ if (file == 0)
+ {
+ // previous attempt failed: force creation of new file
+ file = new H5::H5File(filename, H5F_ACC_TRUNC);
+ }
+ }
+ else if (m == "rw")
+ {
+ // open existing file in read/write mode (fail otherwise)
+ file = new H5::H5File(filename, H5F_ACC_RDWR);
+ }
+ else if (m == "r")
+ {
+ // opens existing file in read-only mode (fail otherwise)
+ file = new H5::H5File(filename, H5F_ACC_RDONLY);
+ }
+ else if (m == "w")
+ {
+ // creates new file
+ file = new H5::H5File(filename, H5F_ACC_TRUNC);
+ }
+ else if (m == "x")
+ {
+ // creates file, but fails if it already exists
+ file = new H5::H5File(filename, H5F_ACC_EXCL);
+ }
+ else
+ {
+ std::cerr << "Error: Unknown file mode '" << mode << "'" << std::endl;
+ }
+ }
+ catch (H5::FileIException error)
+ {
+ error.printError();
+ }
+
+ return file;
+}
+// */
+
+
/**
* Load group from location
*/
-H5::Group* h5_open_group(H5::H5File *file, const char *loc);
+H5::Group* h5_open_group(H5::H5File *file, const char *loc);/*
+{
+ H5::Group* group = 0;
+ if (file)
+ {
+ H5::Exception::dontPrint();
+ try
+ {
+ group = new H5::Group(file->openGroup(loc));
+ }
+ catch (H5::Exception error)
+ {
+ }
+ }
+
+ return group;
+}
+// */
+
+
/**
* Load dataset from location.
*/
-H5::DataSet* h5_open_dataset(H5::H5File *file, const char *loc);
+H5::DataSet* h5_open_dataset(H5::H5File *file, const char *loc);/*
+{
+ H5::DataSet* dataset = 0;
+ if (file)
+ {
+ H5::Exception::dontPrint();
+ try
+ {
+ dataset = new H5::DataSet(file->openDataSet(loc));
+ }
+ catch (H5::Exception error)
+ {
+ }
+ }
+
+ return dataset;
+}
+// */
+
+
/**
* Load object from location, whether it is a group or dataset.
*/
-H5::H5Object* h5_open_object(H5::H5File *file, const char *loc);
+H5::H5Object* h5_open_object(H5::H5File *file, const char *loc);/*
+{
+ H5::H5Object* obj = 0;
+ if (file)
+ {
+ obj = h5_open_group(file, loc);
+ if (obj == 0)
+ {
+ obj = h5_open_dataset(file, loc);
+ }
+ }
+
+ return obj;
+}
+// */
+
+
/**
* Load attribute from object
*/
-H5::Attribute* h5_open_attribute(H5::H5Object *obj, const char *attr_name);
+H5::Attribute* h5_open_attribute(H5::H5Object *obj, const char *attr_name);/*
+{
+ H5::Attribute *attribute = 0;
+ if (obj)
+ {
+ try
+ {
+ attribute = new H5::Attribute(obj->openAttribute(attr_name));
+ }
+ catch (H5::Exception error)
+ {
+ }
+ }
+ return attribute;
+}
+// */
+
+
+
/**
* Read entire dataset into memory.
* @param MT C++ memory type of data array
@@ -293,4 +429,8 @@
}
-#endif
+#endif /* HAVE_HDF5 */
+
+
+
+#endif /* __CIGMA_IO_HDF5_H__ */
More information about the CIG-COMMITS
mailing list