50 #include <boost/scoped_array.hpp>
82 H5T_class_t typeClass;
86 if (H5Aexists(location, attrName.c_str()) < 1)
87 throw MissingAttributeException(
"Couldn't find attribute " + attrName);
93 if (H5Aget_info(attr, &attrInfo) < 0) {
94 throw MissingAttributeException(
"Couldn't get attribute info " + attrName);
96 strLen = attrInfo.data_size;
99 typeClass = H5Tget_class(attrType);
101 if (typeClass != H5T_STRING)
102 throw MissingAttributeException(
"Bad attribute type class for " + attrName);
106 std::vector<char> tempString(strLen + 1);
108 if (H5Aread(attr, nativeType, &tempString[0]) < 0)
109 throw MissingAttributeException(
"Couldn't read attribute " + attrName);
111 value = string(&tempString[0]);
121 unsigned int attrSize,
int &value)
125 H5T_class_t typeClass;
127 if (H5Aexists(location, attrName.c_str()) < 1)
128 throw MissingAttributeException(
"Couldn't find attribute " + attrName);
134 if (H5Sget_simple_extent_ndims(attrSpace) != 1)
135 throw MissingAttributeException(
"Bad attribute rank for attribute " +
139 H5Sget_simple_extent_dims(attrSpace, dims, NULL);
141 if (dims[0] != attrSize)
142 throw MissingAttributeException(
"Invalid attribute size for attribute " +
145 typeClass = H5Tget_class(attrType);
147 if (typeClass != H5T_INTEGER)
148 throw MissingAttributeException(
"Bad attribute type class for " +
153 if (H5Aread(attr, nativeType, &value) < 0)
154 throw MissingAttributeException(
"Couldn't read attribute " + attrName);
164 unsigned int attrSize,
float &value)
168 H5T_class_t typeClass;
170 if (H5Aexists(location, attrName.c_str()) < 1)
171 throw MissingAttributeException(
"Couldn't find attribute " + attrName);
177 if (H5Sget_simple_extent_ndims(attrSpace) != 1)
178 throw MissingAttributeException(
"Bad attribute rank for attribute " +
182 H5Sget_simple_extent_dims(attrSpace, dims, NULL);
184 if (dims[0] != attrSize)
185 throw MissingAttributeException(
"Invalid attribute size for attribute " +
188 typeClass = H5Tget_class(attrType);
190 if (typeClass != H5T_FLOAT)
191 throw MissingAttributeException(
"Bad attribute type class for " +
196 if (H5Aread(attr, nativeType, &value) < 0)
197 throw MissingAttributeException(
"Couldn't read attribute " + attrName);
206 unsigned int attrSize,
double &value)
210 H5T_class_t typeClass;
212 if (H5Aexists(location, attrName.c_str()) < 0)
213 throw MissingAttributeException(
"Couldn't find attribute " + attrName);
219 if (H5Sget_simple_extent_ndims(attrSpace) != 1)
220 throw MissingAttributeException(
"Bad attribute rank for attribute " +
224 H5Sget_simple_extent_dims(attrSpace, dims, NULL);
226 if (dims[0] != attrSize)
227 throw MissingAttributeException(
"Invalid attribute size for attribute " +
230 typeClass = H5Tget_class(attrType);
232 if (typeClass != H5T_FLOAT)
233 throw MissingAttributeException(
"Bad attribute type class for " +
238 if (H5Aread(attr, nativeType, &value) < 0)
239 throw MissingAttributeException(
"Couldn't read attribute " + attrName);
248 std::vector<unsigned int> &attrSize,
int &value)
252 H5T_class_t typeClass;
253 size_t rank = attrSize.size();
255 if (H5Aexists(location, attrName.c_str()) < 0)
256 throw MissingAttributeException(
"Couldn't find attribute " + attrName);
263 if (H5Sget_simple_extent_ndims(attrSpace) != (
int) rank)
264 throw MissingAttributeException(
"Bad attribute rank for attribute " +
267 boost::scoped_array<hsize_t> dims(
new hsize_t[rank]);
268 H5Sget_simple_extent_dims(attrSpace, dims.get(), NULL);
270 for (
size_t i=0; i < rank; i++) {
271 if (dims[i] != attrSize[i])
272 throw MissingAttributeException(
"Invalid attribute size for attribute " +
276 typeClass = H5Tget_class(attrType);
278 if (typeClass != H5T_INTEGER)
279 throw MissingAttributeException(
"Bad attribute type class for " +
284 if (H5Aread(attr, nativeType, &value) < 0)
285 throw MissingAttributeException(
"Couldn't read attribute " + attrName);
294 std::vector<unsigned int> &attrSize,
float &value)
298 H5T_class_t typeClass;
299 size_t rank = attrSize.size();
301 if (H5Aexists(location, attrName.c_str()) < 0)
302 throw MissingAttributeException(
"Couldn't find attribute " + attrName);
309 if (H5Sget_simple_extent_ndims(attrSpace) != (
int) rank)
310 throw MissingAttributeException(
"Bad attribute rank for attribute " +
313 boost::scoped_array<hsize_t> dims(
new hsize_t[rank]);
314 H5Sget_simple_extent_dims(attrSpace, dims.get(), NULL);
316 for (
size_t i=0; i < rank; i++) {
317 if (dims[i] != attrSize[i])
318 throw MissingAttributeException(
"Invalid attribute size for attribute " +
322 typeClass = H5Tget_class(attrType);
324 if (typeClass != H5T_FLOAT)
325 throw MissingAttributeException(
"Bad attribute type class for " +
330 if (H5Aread(attr, nativeType, &value) < 0)
331 throw MissingAttributeException(
"Couldn't read attribute " + attrName);
340 std::vector<unsigned int> &attrSize,
double &value)
344 H5T_class_t typeClass;
345 size_t rank = attrSize.size();
347 if (H5Aexists(location, attrName.c_str()) < 0)
348 throw MissingAttributeException(
"Couldn't find attribute " + attrName);
355 if (H5Sget_simple_extent_ndims(attrSpace) != (
int) rank)
356 throw MissingAttributeException(
"Bad attribute rank for attribute " +
359 boost::scoped_array<hsize_t> dims(
new hsize_t[rank]);
360 H5Sget_simple_extent_dims(attrSpace, dims.get(), NULL);
362 for (
size_t i=0; i < rank; i++) {
363 if (dims[i] != attrSize[i])
364 throw MissingAttributeException(
"Invalid attribute size for attribute " +
368 typeClass = H5Tget_class(attrType);
370 if (typeClass != H5T_FLOAT)
371 throw MissingAttributeException(
"Bad attribute type class for " +
376 if (H5Aread(attr, nativeType, &value) < 0)
377 throw MissingAttributeException(
"Couldn't read attribute " + attrName);
395 attrSpace = H5Screate(H5S_SCALAR);
399 attrType = H5Tcopy(H5T_C_S1);
406 if (success && H5Tset_size(attrType, value.size()) == -1){
412 H5Tset_strpad(attrType, H5T_STR_NULLTERM);
413 attr = H5Acreate(location, attrName.c_str(), attrType, attrSpace,
414 H5P_DEFAULT, H5P_DEFAULT);
422 if (success && H5Awrite(attr, attrType, value.c_str()) == -1) {
439 unsigned int attrSize,
const int &value)
449 attrSpace = H5Screate(H5S_SIMPLE);
453 if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
456 attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_INT,
457 attrSpace, H5P_DEFAULT, H5P_DEFAULT);
465 if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) {
482 unsigned int attrSize,
const float &value)
492 attrSpace = H5Screate(H5S_SIMPLE);
496 if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
499 attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_FLOAT,
500 attrSpace, H5P_DEFAULT, H5P_DEFAULT);
508 if (H5Awrite(attr, H5T_NATIVE_FLOAT, &value) < 0) {
525 unsigned int attrSize,
const double &value)
535 attrSpace = H5Screate(H5S_SIMPLE);
539 if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
542 attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_DOUBLE,
543 attrSpace, H5P_DEFAULT, H5P_DEFAULT);
551 if (H5Awrite(attr, H5T_NATIVE_DOUBLE, &value) < 0) {
569 std::vector<unsigned int> &attrSize,
const int &value)
575 size_t rank = attrSize.size();
577 boost::scoped_array<hsize_t> current_dims(
new hsize_t[rank]);
578 boost::scoped_array<hsize_t> max_dims(
new hsize_t[rank]);
580 for (
size_t i=0; i < rank; i++)
581 current_dims[i] = attrSize[i];
583 for (
size_t i=0; i < rank; i++)
584 max_dims[i] = H5S_UNLIMITED;
586 attrSpace = H5Screate(H5S_SIMPLE);
590 if (H5Sset_extent_simple(attrSpace, (
int)rank,
591 current_dims.get(), max_dims.get()) < 0) {
595 attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_INT,
596 attrSpace, H5P_DEFAULT, H5P_DEFAULT);
604 if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) {
621 std::vector<unsigned int> &attrSize,
const float &value)
627 size_t rank = attrSize.size();
629 boost::scoped_array<hsize_t> current_dims(
new hsize_t[rank]);
630 boost::scoped_array<hsize_t> max_dims(
new hsize_t[rank]);
632 for (
size_t i=0; i < rank; i++)
633 current_dims[i] = attrSize[i];
635 for (
size_t i=0; i < rank; i++)
636 max_dims[i] = H5S_UNLIMITED;
638 attrSpace = H5Screate(H5S_SIMPLE);
642 if (H5Sset_extent_simple(attrSpace, (
int)rank,
643 current_dims.get(), max_dims.get()) < 0) {
647 attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_FLOAT,
648 attrSpace, H5P_DEFAULT, H5P_DEFAULT);
656 if (H5Awrite(attr, H5T_NATIVE_FLOAT, &value) < 0) {
673 std::vector<unsigned int> &attrSize,
const double &value)
679 size_t rank = attrSize.size();
680 boost::scoped_array<hsize_t> current_dims(
new hsize_t[rank]);
681 boost::scoped_array<hsize_t> max_dims(
new hsize_t[rank]);
683 for (
size_t i=0; i < rank; i++)
684 current_dims[i] = attrSize[i];
686 for (
size_t i=0; i < rank; i++)
687 max_dims[i] = H5S_UNLIMITED;
689 attrSpace = H5Screate(H5S_SIMPLE);
693 if (H5Sset_extent_simple(attrSpace, (
int)rank,
694 current_dims.get(), max_dims.get()) < 0) {
698 attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_DOUBLE,
699 attrSpace, H5P_DEFAULT, H5P_DEFAULT);
707 if (H5Awrite(attr, H5T_NATIVE_DOUBLE, &value) < 0) {
726 htri_t avail = H5Zfilter_avail(H5Z_FILTER_DEFLATE);
730 unsigned int filter_info;
731 herr_t status = H5Zget_filter_info (H5Z_FILTER_DEFLATE, &filter_info);
736 if (!(filter_info & H5Z_FILTER_CONFIG_ENCODE_ENABLED) ||
737 !(filter_info & H5Z_FILTER_CONFIG_DECODE_ENABLED)) {