47 #ifndef _INCLUDED_Field3D_Hdf5Util_H_ 48 #define _INCLUDED_Field3D_Hdf5Util_H_ 56 #include <boost/lexical_cast.hpp> 57 #include <boost/thread/mutex.hpp> 58 #include <boost/thread/recursive_mutex.hpp> 119 m_id = H5Aopen(location, name.c_str(), H5P_DEFAULT);
121 throw Exc::MissingAttributeException(
"Couldn't open attribute " + name);
126 m_id = H5Aopen(location, name.c_str(), aapl_id);
128 throw Exc::MissingAttributeException(
"Couldn't open attribute " + name);
148 m_id = H5Aopen_idx(location, idx);
150 throw Exc::MissingAttributeException(
"Couldn't open attribute at index: " +
151 boost::lexical_cast<std::string>(idx));
171 m_id = H5Gcreate(parentLocation, name.c_str(),
172 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
175 hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id)
178 m_id = H5Gcreate(parentLocation, name.c_str(),
179 lcpl_id, gcpl_id, gapl_id);
204 open(parentLocation, name);
208 open(parentLocation, name, gapl_id);
210 void open(hid_t parentLocation,
const std::string &name)
213 m_id = H5Gopen(parentLocation, name.c_str(), H5P_DEFAULT);
215 void open(hid_t parentLocation,
const std::string &name, hid_t gapl_id)
218 m_id = H5Gopen(parentLocation, name.c_str(), gapl_id);
249 m_id = H5Screate(type);
267 hid_t dtype_id, hid_t space_id, hid_t lcpl_id,
268 hid_t dcpl_id, hid_t dapl_id)
271 m_id = H5Dcreate(parentLocation, name.c_str(), dtype_id, space_id,
272 lcpl_id, dcpl_id, dapl_id);
293 m_id = H5Aget_space(dataset_id);
295 throw Exc::AttrGetSpaceException(
"Couldn't get attribute space");
316 m_id = H5Aget_type(dataset_id);
318 throw Exc::AttrGetTypeException(
"Couldn't get attribute type");
339 m_id = H5Tget_native_type(dataset_id, direction);
341 throw Exc::AttrGetNativeTypeException(
"Couldn't get native attribute type");
366 open(parentLocation, name, dapl_id);
368 void open(hid_t parentLocation,
const std::string &name, hid_t dapl_id)
371 m_id = H5Dopen(parentLocation, name.c_str(), dapl_id);
401 m_id = H5Dget_space(dataset_id);
431 m_id = H5Dget_type(dataset_id);
449 template <
typename T>
453 const std::vector<T> &data);
457 template <
typename T>
459 std::vector<T> &data);
477 unsigned int attrSize,
int &value);
482 unsigned int attrSize,
float &value);
487 unsigned int attrSize,
double &value);
492 std::vector<unsigned int> &attrSize,
498 std::vector<unsigned int> &attrSize,
504 std::vector<unsigned int> &attrSize,
518 const std::string& value);
523 unsigned int attrSize,
const int &value);
528 unsigned int attrSize,
const float &value);
533 unsigned int attrSize,
const double &value);
538 std::vector<unsigned int> &attrSize,
544 std::vector<unsigned int> &attrSize,
550 std::vector<unsigned int> &attrSize,
556 std::vector<unsigned int> &attrSize,
557 const double &value);
571 template <
typename T>
573 const std::vector<T> &data)
581 hsize_t totalSize[1];
583 totalSize[0] = data.size() * components;
590 if (dataSpace.
id() < 0)
591 throw WriteSimpleDataException(
"Couldn't create data space");
593 H5Sset_extent_simple(dataSpace.
id(), 1, totalSize, NULL);
596 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
598 if (dataSet.id() < 0)
599 throw WriteSimpleDataException(
"Couldn't create data set");
601 hid_t err = H5Dwrite(dataSet.id(), type, H5S_ALL, H5S_ALL,
602 H5P_DEFAULT, &data[0]);
605 throw WriteSimpleDataException(
"Couldn't write data");
610 template <
typename T>
612 std::vector<T> &data)
623 if (dataSet.id() < 0)
624 throw OpenDataSetException(
"Couldn't open data set: " + name);
628 H5Sget_simple_extent_dims(dataSpace.id(), dims, NULL);
630 if (dataSpace.id() < 0)
631 throw GetDataSpaceException(
"Couldn't get data space");
633 if (dataType.id() < 0)
634 throw GetDataTypeException(
"Couldn't get data type");
636 int reportedSize = dims[0] / components;
640 data.resize(reportedSize);
645 if (H5Dread(dataSet.id(), type, H5S_ALL, H5S_ALL,
646 H5P_DEFAULT, &data[0]) < 0) {
647 throw Hdf5DataReadException(
"Couldn't read simple data");
void open(hid_t dataset_id)
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Scoped object - opens an attribute data type on creation and closes it on destruction.
Contains utility functions and classes for Hdf5 files.
Scoped object - opens a dataset on creation and closes it on destruction.
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
H5ScopedGcreate(hid_t parentLocation, const std::string &name)
Scoped object - opens an native type id on creation and closes it on destruction. ...
static int dataDims()
Dimensions of the given data type. i.e. 3 for V3f, 1 for float.
Namespace for Exception objects.
Scoped object - opens a dataset on creation and closes it on destruction.
FIELD3D_API bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
boost::recursive_mutex::scoped_lock GlobalLock
H5ScopedAopen(hid_t location, const std::string &name)
H5ScopedScreate(H5S_class_t type)
H5ScopedTget_native_type(hid_t dataset_id, H5T_direction_t direction)
Scoped object - creates a group on creation and closes it on destruction.
H5ScopedGopen(hid_t parentLocation, const std::string &name)
H5ScopedAget_type(hid_t dataset_id)
void open(hid_t dataset_id)
Scoped object - Opens attribute by name and closes it on destruction.
Scoped object - Opens attribute by index and closes it on destruction.
~H5ScopedTget_native_type()
FIELD3D_API bool checkHdf5Gzip()
Checks whether gzip is available in the current hdf5 library.
H5ScopedAopenIdx(hid_t location, unsigned idx)
void open(hid_t parentLocation, const std::string &name, hid_t dapl_id)
void readSimpleData(hid_t location, const std::string &name, std::vector< T > &data)
Reads a simple linear data set from the given location.
H5ScopedGopen(hid_t parentLocation, const std::string &name, hid_t gapl_id)
void open(hid_t parentLocation, const std::string &name, hid_t gapl_id)
Scoped object - opens an attribute data space on creation and closes it on destruction.
H5ScopedAopen(hid_t location, const std::string &name, hid_t aapl_id)
Scoped object - creates a dataspace on creation and closes it on destruction.
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
Base class for all scoped Hdf5 util classes.
Contains Field, WritableField and ResizableField classes.
H5ScopedGcreate(hid_t parentLocation, const std::string &name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id)
H5ScopedDget_space(hid_t dataset_id)
Scoped object - creates a dataset on creation and closes it on destruction.
H5ScopedAget_space(hid_t dataset_id)
Scoped object - opens a group on creation and closes it on destruction.
Contains Exception base class.
void create(H5S_class_t type)
H5ScopedDget_type(hid_t dataset_id)
void open(hid_t parentLocation, const std::string &name)
Scoped object - opens a dataset on creation and closes it on destruction.
void writeSimpleData(hid_t location, const std::string &name, const std::vector< T > &data)
Writes a simple linear data set to the given location.
H5ScopedDopen(hid_t parentLocation, const std::string &name, hid_t dapl_id)
H5ScopedDcreate(hid_t parentLocation, const std::string &name, hid_t dtype_id, hid_t space_id, hid_t lcpl_id, hid_t dcpl_id, hid_t dapl_id)
hid_t id() const
Query the hid_t value.