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");