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);
414 template <
typename T>
416 const std::vector<T> &data);
420 template <
typename T>
422 std::vector<T> &data);
434 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");