70 H5T_class_t typeClass;
74 if (H5Aexists(location, attrName.c_str()) < 1)
75 throw MissingAttributeException(
"Couldn't find attribute " + attrName);
81 if (H5Aget_info(attr, &attrInfo) < 0) {
82 throw MissingAttributeException(
"Couldn't get attribute info " + attrName);
84 strLen = attrInfo.data_size;
87 typeClass = H5Tget_class(attrType);
89 if (typeClass != H5T_STRING)
90 throw MissingAttributeException(
"Bad attribute type class for " + attrName);
94 std::vector<char> tempString(strLen + 1);
96 if (H5Aread(attr, nativeType, &tempString[0]) < 0)
97 throw MissingAttributeException(
"Couldn't read attribute " + attrName);
99 value = string(&tempString[0]);
109 unsigned int attrSize,
int &value)
111 H5T_class_t typeClass;
113 if (H5Aexists(location, attrName.c_str()) < 1)
114 throw MissingAttributeException(
"Couldn't find attribute " + attrName);
120 if (H5Sget_simple_extent_ndims(attrSpace) != 1)
121 throw MissingAttributeException(
"Bad attribute rank for attribute " +
125 H5Sget_simple_extent_dims(attrSpace, dims, NULL);
127 if (dims[0] != attrSize)
128 throw MissingAttributeException(
"Invalid attribute size for attribute " +
131 typeClass = H5Tget_class(attrType);
133 if (typeClass != H5T_INTEGER)
134 throw MissingAttributeException(
"Bad attribute type class for " +
139 if (H5Aread(attr, nativeType, &value) < 0)
140 throw MissingAttributeException(
"Couldn't read attribute " + attrName);
150 unsigned int attrSize,
float &value)
152 H5T_class_t typeClass;
154 if (H5Aexists(location, attrName.c_str()) < 1)
155 throw MissingAttributeException(
"Couldn't find attribute " + attrName);
161 if (H5Sget_simple_extent_ndims(attrSpace) != 1)
162 throw MissingAttributeException(
"Bad attribute rank for attribute " +
166 H5Sget_simple_extent_dims(attrSpace, dims, NULL);
168 if (dims[0] != attrSize)
169 throw MissingAttributeException(
"Invalid attribute size for attribute " +
172 typeClass = H5Tget_class(attrType);
174 if (typeClass != H5T_FLOAT)
175 throw MissingAttributeException(
"Bad attribute type class for " +
180 if (H5Aread(attr, nativeType, &value) < 0)
181 throw MissingAttributeException(
"Couldn't read attribute " + attrName);
190 unsigned int attrSize,
double &value)
192 H5T_class_t typeClass;
194 if (H5Aexists(location, attrName.c_str()) < 0)
195 throw MissingAttributeException(
"Couldn't find attribute " + attrName);
201 if (H5Sget_simple_extent_ndims(attrSpace) != 1)
202 throw MissingAttributeException(
"Bad attribute rank for attribute " +
206 H5Sget_simple_extent_dims(attrSpace, dims, NULL);
208 if (dims[0] != attrSize)
209 throw MissingAttributeException(
"Invalid attribute size for attribute " +
212 typeClass = H5Tget_class(attrType);
214 if (typeClass != H5T_FLOAT)
215 throw MissingAttributeException(
"Bad attribute type class for " +
220 if (H5Aread(attr, nativeType, &value) < 0)
221 throw MissingAttributeException(
"Couldn't read attribute " + attrName);
230 std::vector<unsigned int> &attrSize,
int &value)
232 H5T_class_t typeClass;
233 int rank = attrSize.size();
235 if (H5Aexists(location, attrName.c_str()) < 0)
236 throw MissingAttributeException(
"Couldn't find attribute " + attrName);
243 if (H5Sget_simple_extent_ndims(attrSpace) != rank)
244 throw MissingAttributeException(
"Bad attribute rank for attribute " +
248 H5Sget_simple_extent_dims(attrSpace, dims, NULL);
250 for (
int i=0; i < rank; i++) {
251 if (dims[i] != attrSize[i])
252 throw MissingAttributeException(
"Invalid attribute size for attribute " +
256 typeClass = H5Tget_class(attrType);
258 if (typeClass != H5T_INTEGER)
259 throw MissingAttributeException(
"Bad attribute type class for " +
264 if (H5Aread(attr, nativeType, &value) < 0)
265 throw MissingAttributeException(
"Couldn't read attribute " + attrName);
274 std::vector<unsigned int> &attrSize,
float &value)
276 H5T_class_t typeClass;
277 int rank = attrSize.size();
279 if (H5Aexists(location, attrName.c_str()) < 0)
280 throw MissingAttributeException(
"Couldn't find attribute " + attrName);
287 if (H5Sget_simple_extent_ndims(attrSpace) != rank)
288 throw MissingAttributeException(
"Bad attribute rank for attribute " +
292 H5Sget_simple_extent_dims(attrSpace, dims, NULL);
294 for (
int i=0; i < rank; i++) {
295 if (dims[i] != attrSize[i])
296 throw MissingAttributeException(
"Invalid attribute size for attribute " +
300 typeClass = H5Tget_class(attrType);
302 if (typeClass != H5T_FLOAT)
303 throw MissingAttributeException(
"Bad attribute type class for " +
308 if (H5Aread(attr, nativeType, &value) < 0)
309 throw MissingAttributeException(
"Couldn't read attribute " + attrName);
318 std::vector<unsigned int> &attrSize,
double &value)
321 H5T_class_t typeClass;
322 int rank = attrSize.size();
324 if (H5Aexists(location, attrName.c_str()) < 0)
325 throw MissingAttributeException(
"Couldn't find attribute " + attrName);
332 if (H5Sget_simple_extent_ndims(attrSpace) != rank)
333 throw MissingAttributeException(
"Bad attribute rank for attribute " +
337 H5Sget_simple_extent_dims(attrSpace, dims, NULL);
339 for (
int i=0; i < rank; i++) {
340 if (dims[i] != attrSize[i])
341 throw MissingAttributeException(
"Invalid attribute size for attribute " +
345 typeClass = H5Tget_class(attrType);
347 if (typeClass != H5T_FLOAT)
348 throw MissingAttributeException(
"Bad attribute type class for " +
353 if (H5Aread(attr, nativeType, &value) < 0)
354 throw MissingAttributeException(
"Couldn't read attribute " + attrName);
370 attrSpace = H5Screate(H5S_SCALAR);
374 attrType = H5Tcopy(H5T_C_S1);
381 if (success && H5Tset_size(attrType, value.size()) == -1){
387 H5Tset_strpad(attrType, H5T_STR_NULLTERM);
388 attr = H5Acreate(location, attrName.c_str(), attrType, attrSpace,
389 H5P_DEFAULT, H5P_DEFAULT);
397 if (success && H5Awrite(attr, attrType, value.c_str()) == -1) {
414 unsigned int attrSize,
const int &value)
422 attrSpace = H5Screate(H5S_SIMPLE);
426 if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
429 attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_INT,
430 attrSpace, H5P_DEFAULT, H5P_DEFAULT);
438 if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) {
455 unsigned int attrSize,
const float &value)
463 attrSpace = H5Screate(H5S_SIMPLE);
467 if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
470 attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_FLOAT,
471 attrSpace, H5P_DEFAULT, H5P_DEFAULT);
479 if (H5Awrite(attr, H5T_NATIVE_FLOAT, &value) < 0) {
496 unsigned int attrSize,
const double &value)
504 attrSpace = H5Screate(H5S_SIMPLE);
508 if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
511 attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_DOUBLE,
512 attrSpace, H5P_DEFAULT, H5P_DEFAULT);
520 if (H5Awrite(attr, H5T_NATIVE_DOUBLE, &value) < 0) {
538 std::vector<unsigned int> &attrSize,
const int &value)
542 size_t rank = attrSize.size();
543 hsize_t current_dims[rank];
544 hsize_t max_dims[rank];
546 for (
size_t i=0; i < rank; i++)
547 current_dims[i] = attrSize[i];
549 for (
size_t i=0; i < rank; i++)
550 max_dims[i] = H5S_UNLIMITED;
552 attrSpace = H5Screate(H5S_SIMPLE);
556 if (H5Sset_extent_simple(attrSpace, rank, current_dims, max_dims) < 0) {
560 attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_INT,
561 attrSpace, H5P_DEFAULT, H5P_DEFAULT);
569 if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) {
586 std::vector<unsigned int> &attrSize,
const float &value)
590 size_t rank = attrSize.size();
591 hsize_t current_dims[rank];
592 hsize_t max_dims[rank];
594 for (
size_t i=0; i < rank; i++)
595 current_dims[i] = attrSize[i];
597 for (
size_t i=0; i < rank; i++)
598 max_dims[i] = H5S_UNLIMITED;
600 attrSpace = H5Screate(H5S_SIMPLE);
604 if (H5Sset_extent_simple(attrSpace, rank, current_dims, max_dims) < 0) {
608 attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_FLOAT,
609 attrSpace, H5P_DEFAULT, H5P_DEFAULT);
617 if (H5Awrite(attr, H5T_NATIVE_FLOAT, &value) < 0) {
634 std::vector<unsigned int> &attrSize,
const double &value)
638 size_t rank = attrSize.size();
639 hsize_t current_dims[rank];
640 hsize_t max_dims[rank];
642 for (
size_t i=0; i < rank; i++)
643 current_dims[i] = attrSize[i];
645 for (
size_t i=0; i < rank; i++)
646 max_dims[i] = H5S_UNLIMITED;
648 attrSpace = H5Screate(H5S_SIMPLE);
652 if (H5Sset_extent_simple(attrSpace, rank, current_dims, max_dims) < 0) {
656 attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_DOUBLE,
657 attrSpace, H5P_DEFAULT, H5P_DEFAULT);
665 if (H5Awrite(attr, H5T_NATIVE_DOUBLE, &value) < 0) {
682 htri_t avail = H5Zfilter_avail(H5Z_FILTER_DEFLATE);
686 unsigned int filter_info;
687 herr_t status = H5Zget_filter_info (H5Z_FILTER_DEFLATE, &filter_info);
692 if (!(filter_info & H5Z_FILTER_CONFIG_ENCODE_ENABLED) ||
693 !(filter_info & H5Z_FILTER_CONFIG_DECODE_ENABLED)) {
Scoped object - opens an attribute data type on creation and closes it on destruction.
Scoped object - opens an native type id on creation and closes it on destruction. ...
#define FIELD3D_NAMESPACE_SOURCE_CLOSE
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
bool readAttribute(hid_t location, const string &attrName, std::vector< unsigned int > &attrSize, double &value)
Contains various utility functions for Hdf5.
Scoped object - Opens attribute by name and closes it on destruction.
bool checkHdf5Gzip()
Checks whether gzip is available in the current hdf5 library.
Scoped object - opens an attribute data space on creation and closes it on destruction.
bool writeAttribute(hid_t location, const string &attrName, std::vector< unsigned int > &attrSize, const double &value)
#define FIELD3D_NAMESPACE_OPEN