47 #ifndef _INCLUDED_Field3D_Hdf5Util_H_
48 #define _INCLUDED_Field3D_Hdf5Util_H_
56 #include <boost/lexical_cast.hpp>
108 m_id = H5Aopen(location, name.c_str(), H5P_DEFAULT);
110 throw Exc::MissingAttributeException(
"Couldn't open attribute " + name);
114 m_id = H5Aopen(location, name.c_str(), aapl_id);
116 throw Exc::MissingAttributeException(
"Couldn't open attribute " + name);
134 m_id = H5Aopen_idx(location, idx);
136 throw Exc::MissingAttributeException(
"Couldn't open attribute at index: " +
137 boost::lexical_cast<std::string>(idx));
155 m_id = H5Gcreate(parentLocation, name.c_str(),
156 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
159 hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id)
161 m_id = H5Gcreate(parentLocation, name.c_str(),
162 lcpl_id, gcpl_id, gapl_id);
186 open(parentLocation, name);
190 open(parentLocation, name, gapl_id);
192 void open(hid_t parentLocation,
const std::string &name)
194 m_id = H5Gopen(parentLocation, name.c_str(), H5P_DEFAULT);
196 void open(hid_t parentLocation,
const std::string &name, hid_t gapl_id)
198 m_id = H5Gopen(parentLocation, name.c_str(), gapl_id);
227 m_id = H5Screate(type);
244 hid_t dtype_id, hid_t space_id, hid_t lcpl_id,
245 hid_t dcpl_id, hid_t dapl_id)
247 m_id = H5Dcreate(parentLocation, name.c_str(), dtype_id, space_id,
248 lcpl_id, dcpl_id, dapl_id);
267 m_id = H5Aget_space(dataset_id);
269 throw Exc::AttrGetSpaceException(
"Couldn't get attribute space");
288 m_id = H5Aget_type(dataset_id);
290 throw Exc::AttrGetTypeException(
"Couldn't get attribute type");
309 m_id = H5Tget_native_type(dataset_id, direction);
311 throw Exc::AttrGetNativeTypeException(
"Couldn't get native attribute type");
335 open(parentLocation, name, dapl_id);
337 void open(hid_t parentLocation,
const std::string &name, hid_t dapl_id)
339 m_id = H5Dopen(parentLocation, name.c_str(), dapl_id);
367 m_id = H5Dget_space(dataset_id);
395 m_id = H5Dget_type(dataset_id);
412 template <
typename T>
416 const std::vector<T> &data);
420 template <
typename T>
422 std::vector<T> &data);
432 bool readAttribute(hid_t location,
const std::string& attrName,
439 bool readAttribute(hid_t location,
const std::string& attrName,
440 unsigned int attrSize,
int &value);
444 bool readAttribute(hid_t location,
const std::string& attrName,
445 unsigned int attrSize,
float &value);
449 bool readAttribute(hid_t location,
const std::string& attrName,
450 unsigned int attrSize,
double &value);
454 bool readAttribute(hid_t location,
const std::string& attrName,
455 std::vector<unsigned int> &attrSize,
int &value);
459 bool readAttribute(hid_t location,
const std::string& attrName,
460 std::vector<unsigned int> &attrSize,
float &value);
464 bool readAttribute(hid_t location,
const std::string& attrName,
465 std::vector<unsigned int> &attrSize,
double &value);
479 const std::string& value);
484 unsigned int attrSize,
const int &value);
489 unsigned int attrSize,
const float &value);
494 unsigned int attrSize,
const double &value);
499 std::vector<unsigned int> &attrSize,
const int &value);
505 std::vector<unsigned int> &attrSize,
const int &value);
510 std::vector<unsigned int> &attrSize,
const float &value);
515 std::vector<unsigned int> &attrSize,
const double &value);
529 template <
typename T>
531 const std::vector<T> &data)
537 hsize_t totalSize[1];
539 totalSize[0] = data.size() * components;
546 if (dataSpace.
id() < 0)
547 throw WriteSimpleDataException(
"Couldn't create data space");
549 H5Sset_extent_simple(dataSpace.
id(), 1, totalSize, NULL);
552 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
554 if (dataSet.id() < 0)
555 throw WriteSimpleDataException(
"Couldn't create data set");
557 hid_t err = H5Dwrite(dataSet.id(), type, H5S_ALL, H5S_ALL,
558 H5P_DEFAULT, &data[0]);
561 throw WriteSimpleDataException(
"Couldn't write data");
566 template <
typename T>
568 std::vector<T> &data)
577 if (dataSet.id() < 0)
578 throw OpenDataSetException(
"Couldn't open data set: " + name);
582 H5Sget_simple_extent_dims(dataSpace.id(), dims, NULL);
584 if (dataSpace.id() < 0)
585 throw GetDataSpaceException(
"Couldn't get data space");
587 if (dataType.id() < 0)
588 throw GetDataTypeException(
"Couldn't get data type");
590 int reportedSize = dims[0] / components;
594 data.resize(reportedSize);
599 if (H5Dread(dataSet.id(), type, H5S_ALL, H5S_ALL,
600 H5P_DEFAULT, &data[0]) < 0) {
601 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.
Scoped object - opens a dataset on creation and closes it on destruction.
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.
Scoped object - opens a dataset on creation and closes it on destruction.
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()
bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
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)
bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
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.
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.
#define FIELD3D_NAMESPACE_OPEN