Field3D

Contains utility functions and classes for Hdf5 files. More...

Classes

class  H5Base
 Base class for all scoped Hdf5 util classes. More...
 
class  H5ScopedAget_space
 Scoped object - opens an attribute data space on creation and closes it on destruction. More...
 
class  H5ScopedAget_type
 Scoped object - opens an attribute data type on creation and closes it on destruction. More...
 
class  H5ScopedAopen
 Scoped object - Opens attribute by name and closes it on destruction. More...
 
class  H5ScopedAopenIdx
 Scoped object - Opens attribute by index and closes it on destruction. More...
 
class  H5ScopedDcreate
 Scoped object - creates a dataset on creation and closes it on destruction. More...
 
class  H5ScopedDget_space
 Scoped object - opens a dataset on creation and closes it on destruction. More...
 
class  H5ScopedDget_type
 Scoped object - opens a dataset on creation and closes it on destruction. More...
 
class  H5ScopedDopen
 Scoped object - opens a dataset on creation and closes it on destruction. More...
 
class  H5ScopedGcreate
 Scoped object - creates a group on creation and closes it on destruction. More...
 
class  H5ScopedGopen
 Scoped object - opens a group on creation and closes it on destruction. More...
 
class  H5ScopedScreate
 Scoped object - creates a dataspace on creation and closes it on destruction. More...
 
class  H5ScopedTget_native_type
 Scoped object - opens an native type id on creation and closes it on destruction. More...
 

Functions

FIELD3D_API bool checkHdf5Gzip ()
 Checks whether gzip is available in the current hdf5 library. More...
 
bool readAttribute (hid_t location, const string &attrName, std::vector< unsigned int > &attrSize, double &value)
 
bool readAttribute (hid_t location, const string &attrName, std::vector< unsigned int > &attrSize, float &value)
 
bool readAttribute (hid_t location, const string &attrName, std::vector< unsigned int > &attrSize, int &value)
 
bool readAttribute (hid_t location, const string &attrName, string &value)
 
bool readAttribute (hid_t location, const string &attrName, unsigned int attrSize, double &value)
 
bool readAttribute (hid_t location, const string &attrName, unsigned int attrSize, float &value)
 
bool readAttribute (hid_t location, const string &attrName, unsigned int attrSize, int &value)
 
bool writeAttribute (hid_t location, const string &attrName, const string &value)
 
bool writeAttribute (hid_t location, const string &attrName, std::vector< unsigned int > &attrSize, const double &value)
 
bool writeAttribute (hid_t location, const string &attrName, std::vector< unsigned int > &attrSize, const float &value)
 
bool writeAttribute (hid_t location, const string &attrName, std::vector< unsigned int > &attrSize, const int &value)
 
bool writeAttribute (hid_t location, const string &attrName, unsigned int attrSize, const double &value)
 
bool writeAttribute (hid_t location, const string &attrName, unsigned int attrSize, const float &value)
 
bool writeAttribute (hid_t location, const string &attrName, unsigned int attrSize, const int &value)
 
Read/write simple data to hdf5 location
template<typename T >
void writeSimpleData (hid_t location, const std::string &name, const std::vector< T > &data)
 Writes a simple linear data set to the given location. More...
 
template<typename T >
void readSimpleData (hid_t location, const std::string &name, std::vector< T > &data)
 Reads a simple linear data set from the given location. More...
 
Attribute reading
FIELD3D_API bool readAttribute (hid_t location, const std::string &attrName, std::string &value)
 Reads a string attribute. More...
 
FIELD3D_API bool readAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, int &value)
 Reads an int attribute of arbitrary size. More...
 
FIELD3D_API bool readAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, float &value)
 Reads a float attribute of arbitrary size. More...
 
FIELD3D_API bool readAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, double &value)
 Reads a double attribute of arbitrary size. More...
 
FIELD3D_API bool readAttribute (hid_t location, const std::string &attrName, std::vector< unsigned int > &attrSize, int &value)
 Reads a int attribute of arbitrary size and rank. More...
 
FIELD3D_API bool readAttribute (hid_t location, const std::string &attrName, std::vector< unsigned int > &attrSize, float &value)
 Reads a float attribute of arbitrary size and rank. More...
 
FIELD3D_API bool readAttribute (hid_t location, const std::string &attrName, std::vector< unsigned int > &attrSize, double &value)
 Reads a double attribute of arbitrary size and rank. More...
 
Attribute writing
FIELD3D_API bool writeAttribute (hid_t location, const std::string &attrName, const std::string &value)
 Writes a string attribute. More...
 
FIELD3D_API bool writeAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, const int &value)
 Writes an int attribute of arbitrary size. More...
 
FIELD3D_API bool writeAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, const float &value)
 Writes a float attribute of arbitrary size. More...
 
FIELD3D_API bool writeAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, const double &value)
 Writes a double attribute of arbitrary size. More...
 
FIELD3D_API bool writeAttribute (hid_t location, const std::string &attrName, std::vector< unsigned int > &attrSize, const int &value)
 Writes a float attribute of arbitrary size and rank. More...
 
FIELD3D_API bool writeAttribute (hid_t location, const std::string &attrName, std::vector< unsigned int > &attrSize, const float &value)
 Writes a float attribute of arbitrary size and rank. More...
 
FIELD3D_API bool writeAttribute (hid_t location, const std::string &attrName, std::vector< unsigned int > &attrSize, const double &value)
 Writes a double attribute of arbitrary size and rank. More...
 

Detailed Description

Contains utility functions and classes for Hdf5 files.

Function Documentation

◆ readAttribute() [1/7]

bool Hdf5Util::readAttribute ( hid_t  location,
const string &  attrName,
string &  value 
)

Definition at line 78 of file Hdf5Util.cpp.

79 {
80  GlobalLock lock(g_hdf5Mutex);
81 
82  H5T_class_t typeClass;
83  H5A_info_t attrInfo;
84  hsize_t strLen;
85 
86  if (H5Aexists(location, attrName.c_str()) < 1)
87  throw MissingAttributeException("Couldn't find attribute " + attrName);
88 
89  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
90  H5ScopedAget_space attrSpace(attr);
91  H5ScopedAget_type attrType(attr);
92 
93  if (H5Aget_info(attr, &attrInfo) < 0) {
94  throw MissingAttributeException("Couldn't get attribute info " + attrName);
95  } else {
96  strLen = attrInfo.data_size;
97  }
98 
99  typeClass = H5Tget_class(attrType);
100 
101  if (typeClass != H5T_STRING)
102  throw MissingAttributeException("Bad attribute type class for " + attrName);
103 
104  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
105 
106  std::vector<char> tempString(strLen + 1);
107 
108  if (H5Aread(attr, nativeType, &tempString[0]) < 0)
109  throw MissingAttributeException("Couldn't read attribute " + attrName);
110 
111  value = string(&tempString[0]);
112 
113  return true;
114 
115 }

References g_hdf5Mutex.

◆ readAttribute() [2/7]

bool Hdf5Util::readAttribute ( hid_t  location,
const string &  attrName,
unsigned int  attrSize,
int &  value 
)

Definition at line 120 of file Hdf5Util.cpp.

122 {
123  GlobalLock lock(g_hdf5Mutex);
124 
125  H5T_class_t typeClass;
126 
127  if (H5Aexists(location, attrName.c_str()) < 1)
128  throw MissingAttributeException("Couldn't find attribute " + attrName);
129 
130  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
131  H5ScopedAget_space attrSpace(attr);
132  H5ScopedAget_type attrType(attr);
133 
134  if (H5Sget_simple_extent_ndims(attrSpace) != 1)
135  throw MissingAttributeException("Bad attribute rank for attribute " +
136  attrName);
137 
138  hsize_t dims[1];
139  H5Sget_simple_extent_dims(attrSpace, dims, NULL);
140 
141  if (dims[0] != attrSize)
142  throw MissingAttributeException("Invalid attribute size for attribute " +
143  attrName);
144 
145  typeClass = H5Tget_class(attrType);
146 
147  if (typeClass != H5T_INTEGER)
148  throw MissingAttributeException("Bad attribute type class for " +
149  attrName);
150 
151  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
152 
153  if (H5Aread(attr, nativeType, &value) < 0)
154  throw MissingAttributeException("Couldn't read attribute " + attrName);
155 
156  return true;
157 
158 }

References g_hdf5Mutex.

◆ readAttribute() [3/7]

bool Hdf5Util::readAttribute ( hid_t  location,
const string &  attrName,
unsigned int  attrSize,
float &  value 
)

Definition at line 163 of file Hdf5Util.cpp.

165 {
166  GlobalLock lock(g_hdf5Mutex);
167 
168  H5T_class_t typeClass;
169 
170  if (H5Aexists(location, attrName.c_str()) < 1)
171  throw MissingAttributeException("Couldn't find attribute " + attrName);
172 
173  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
174  H5ScopedAget_space attrSpace(attr);
175  H5ScopedAget_type attrType(attr);
176 
177  if (H5Sget_simple_extent_ndims(attrSpace) != 1)
178  throw MissingAttributeException("Bad attribute rank for attribute " +
179  attrName);
180 
181  hsize_t dims[1];
182  H5Sget_simple_extent_dims(attrSpace, dims, NULL);
183 
184  if (dims[0] != attrSize)
185  throw MissingAttributeException("Invalid attribute size for attribute " +
186  attrName);
187 
188  typeClass = H5Tget_class(attrType);
189 
190  if (typeClass != H5T_FLOAT)
191  throw MissingAttributeException("Bad attribute type class for " +
192  attrName);
193 
194  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
195 
196  if (H5Aread(attr, nativeType, &value) < 0)
197  throw MissingAttributeException("Couldn't read attribute " + attrName);
198 
199  return true;
200 }

References g_hdf5Mutex.

◆ readAttribute() [4/7]

bool Hdf5Util::readAttribute ( hid_t  location,
const string &  attrName,
unsigned int  attrSize,
double &  value 
)

Definition at line 205 of file Hdf5Util.cpp.

207 {
208  GlobalLock lock(g_hdf5Mutex);
209 
210  H5T_class_t typeClass;
211 
212  if (H5Aexists(location, attrName.c_str()) < 0)
213  throw MissingAttributeException("Couldn't find attribute " + attrName);
214 
215  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
216  H5ScopedAget_space attrSpace(attr);
217  H5ScopedAget_type attrType(attr);
218 
219  if (H5Sget_simple_extent_ndims(attrSpace) != 1)
220  throw MissingAttributeException("Bad attribute rank for attribute " +
221  attrName);
222 
223  hsize_t dims[1];
224  H5Sget_simple_extent_dims(attrSpace, dims, NULL);
225 
226  if (dims[0] != attrSize)
227  throw MissingAttributeException("Invalid attribute size for attribute " +
228  attrName);
229 
230  typeClass = H5Tget_class(attrType);
231 
232  if (typeClass != H5T_FLOAT)
233  throw MissingAttributeException("Bad attribute type class for " +
234  attrName);
235 
236  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
237 
238  if (H5Aread(attr, nativeType, &value) < 0)
239  throw MissingAttributeException("Couldn't read attribute " + attrName);
240 
241  return true;
242 }

References g_hdf5Mutex.

◆ readAttribute() [5/7]

bool Hdf5Util::readAttribute ( hid_t  location,
const string &  attrName,
std::vector< unsigned int > &  attrSize,
int &  value 
)

Definition at line 247 of file Hdf5Util.cpp.

249 {
250  GlobalLock lock(g_hdf5Mutex);
251 
252  H5T_class_t typeClass;
253  size_t rank = attrSize.size();
254 
255  if (H5Aexists(location, attrName.c_str()) < 0)
256  throw MissingAttributeException("Couldn't find attribute " + attrName);
257 
258  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
259  H5ScopedAget_space attrSpace(attr);
260  H5ScopedAget_type attrType(attr);
261 
262 
263  if (H5Sget_simple_extent_ndims(attrSpace) != (int) rank)
264  throw MissingAttributeException("Bad attribute rank for attribute " +
265  attrName);
266 
267  boost::scoped_array<hsize_t> dims(new hsize_t[rank]);
268  H5Sget_simple_extent_dims(attrSpace, dims.get(), NULL);
269 
270  for (size_t i=0; i < rank; i++) {
271  if (dims[i] != attrSize[i])
272  throw MissingAttributeException("Invalid attribute size for attribute " +
273  attrName);
274  }
275 
276  typeClass = H5Tget_class(attrType);
277 
278  if (typeClass != H5T_INTEGER)
279  throw MissingAttributeException("Bad attribute type class for " +
280  attrName);
281 
282  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
283 
284  if (H5Aread(attr, nativeType, &value) < 0)
285  throw MissingAttributeException("Couldn't read attribute " + attrName);
286 
287  return true;
288 }

References g_hdf5Mutex.

◆ readAttribute() [6/7]

bool Hdf5Util::readAttribute ( hid_t  location,
const string &  attrName,
std::vector< unsigned int > &  attrSize,
float &  value 
)

Definition at line 293 of file Hdf5Util.cpp.

295 {
296  GlobalLock lock(g_hdf5Mutex);
297 
298  H5T_class_t typeClass;
299  size_t rank = attrSize.size();
300 
301  if (H5Aexists(location, attrName.c_str()) < 0)
302  throw MissingAttributeException("Couldn't find attribute " + attrName);
303 
304  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
305  H5ScopedAget_space attrSpace(attr);
306  H5ScopedAget_type attrType(attr);
307 
308 
309  if (H5Sget_simple_extent_ndims(attrSpace) != (int) rank)
310  throw MissingAttributeException("Bad attribute rank for attribute " +
311  attrName);
312 
313  boost::scoped_array<hsize_t> dims(new hsize_t[rank]);
314  H5Sget_simple_extent_dims(attrSpace, dims.get(), NULL);
315 
316  for (size_t i=0; i < rank; i++) {
317  if (dims[i] != attrSize[i])
318  throw MissingAttributeException("Invalid attribute size for attribute " +
319  attrName);
320  }
321 
322  typeClass = H5Tget_class(attrType);
323 
324  if (typeClass != H5T_FLOAT)
325  throw MissingAttributeException("Bad attribute type class for " +
326  attrName);
327 
328  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
329 
330  if (H5Aread(attr, nativeType, &value) < 0)
331  throw MissingAttributeException("Couldn't read attribute " + attrName);
332 
333  return true;
334 }

References g_hdf5Mutex.

◆ readAttribute() [7/7]

bool Hdf5Util::readAttribute ( hid_t  location,
const string &  attrName,
std::vector< unsigned int > &  attrSize,
double &  value 
)

Definition at line 339 of file Hdf5Util.cpp.

341 {
342  GlobalLock lock(g_hdf5Mutex);
343 
344  H5T_class_t typeClass;
345  size_t rank = attrSize.size();
346 
347  if (H5Aexists(location, attrName.c_str()) < 0)
348  throw MissingAttributeException("Couldn't find attribute " + attrName);
349 
350  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
351  H5ScopedAget_space attrSpace(attr);
352  H5ScopedAget_type attrType(attr);
353 
354 
355  if (H5Sget_simple_extent_ndims(attrSpace) != (int) rank)
356  throw MissingAttributeException("Bad attribute rank for attribute " +
357  attrName);
358 
359  boost::scoped_array<hsize_t> dims(new hsize_t[rank]);
360  H5Sget_simple_extent_dims(attrSpace, dims.get(), NULL);
361 
362  for (size_t i=0; i < rank; i++) {
363  if (dims[i] != attrSize[i])
364  throw MissingAttributeException("Invalid attribute size for attribute " +
365  attrName);
366  }
367 
368  typeClass = H5Tget_class(attrType);
369 
370  if (typeClass != H5T_FLOAT)
371  throw MissingAttributeException("Bad attribute type class for " +
372  attrName);
373 
374  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
375 
376  if (H5Aread(attr, nativeType, &value) < 0)
377  throw MissingAttributeException("Couldn't read attribute " + attrName);
378 
379  return true;
380 }

References g_hdf5Mutex.

◆ writeAttribute() [1/7]

bool Hdf5Util::writeAttribute ( hid_t  location,
const string &  attrName,
const string &  value 
)

Definition at line 385 of file Hdf5Util.cpp.

386 {
387  GlobalLock lock(g_hdf5Mutex);
388 
389  hid_t attr = -1;
390  hid_t attrSpace;
391  hid_t attrType;
392 
393  bool success = true;
394 
395  attrSpace = H5Screate(H5S_SCALAR);
396  if (attrSpace == -1)
397  success = false;
398 
399  attrType = H5Tcopy(H5T_C_S1);
400  if (attrType == -1)
401  success = false;
402 
403  if (value.size()) {
404  // if the string is null the following will return error
405  // which we don't want.
406  if (success && H5Tset_size(attrType, value.size()) == -1){
407  success = false;
408  }
409  }
410 
411  if (success) {
412  H5Tset_strpad(attrType, H5T_STR_NULLTERM);
413  attr = H5Acreate(location, attrName.c_str(), attrType, attrSpace,
414  H5P_DEFAULT, H5P_DEFAULT);
415  }
416 
417  if (attr == -1) {
418  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
419  success = false;
420  }
421 
422  if (success && H5Awrite(attr, attrType, value.c_str()) == -1) {
423  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
424  success = false;
425  }
426 
427  H5Aclose(attr);
428  H5Tclose(attrType);
429  H5Sclose(attrSpace);
430 
431  return success;
432 
433 }

References g_hdf5Mutex, Msg::print(), and Msg::SevWarning.

◆ writeAttribute() [2/7]

bool Hdf5Util::writeAttribute ( hid_t  location,
const string &  attrName,
unsigned int  attrSize,
const int &  value 
)

Definition at line 438 of file Hdf5Util.cpp.

440 {
441  GlobalLock lock(g_hdf5Mutex);
442 
443  hid_t attr;
444  hid_t attrSpace;
445  hsize_t dims[1];
446 
447  dims[0] = attrSize;
448 
449  attrSpace = H5Screate(H5S_SIMPLE);
450  if (attrSpace < 0)
451  return false;
452 
453  if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
454  return false;
455 
456  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_INT,
457  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
458  if (attr < 0) {
459  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
460  H5Aclose(attr);
461  H5Sclose(attrSpace);
462  return false;
463  }
464 
465  if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) {
466  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
467  H5Aclose(attr);
468  H5Sclose(attrSpace);
469  return false;
470  }
471 
472  H5Aclose(attr);
473  H5Sclose(attrSpace);
474 
475  return true;
476 }

References g_hdf5Mutex, Msg::print(), and Msg::SevWarning.

◆ writeAttribute() [3/7]

bool Hdf5Util::writeAttribute ( hid_t  location,
const string &  attrName,
unsigned int  attrSize,
const float &  value 
)

Definition at line 481 of file Hdf5Util.cpp.

483 {
484  GlobalLock lock(g_hdf5Mutex);
485 
486  hid_t attr;
487  hid_t attrSpace;
488  hsize_t dims[1];
489 
490  dims[0] = attrSize;
491 
492  attrSpace = H5Screate(H5S_SIMPLE);
493  if (attrSpace < 0)
494  return false;
495 
496  if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
497  return false;
498 
499  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_FLOAT,
500  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
501  if (attr < 0) {
502  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
503  H5Aclose(attr);
504  H5Sclose(attrSpace);
505  return false;
506  }
507 
508  if (H5Awrite(attr, H5T_NATIVE_FLOAT, &value) < 0) {
509  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
510  H5Aclose(attr);
511  H5Sclose(attrSpace);
512  return false;
513  }
514 
515  H5Aclose(attr);
516  H5Sclose(attrSpace);
517 
518  return true;
519 }

References g_hdf5Mutex, Msg::print(), and Msg::SevWarning.

◆ writeAttribute() [4/7]

bool Hdf5Util::writeAttribute ( hid_t  location,
const string &  attrName,
unsigned int  attrSize,
const double &  value 
)

Definition at line 524 of file Hdf5Util.cpp.

526 {
527  GlobalLock lock(g_hdf5Mutex);
528 
529  hid_t attr;
530  hid_t attrSpace;
531  hsize_t dims[1];
532 
533  dims[0] = attrSize;
534 
535  attrSpace = H5Screate(H5S_SIMPLE);
536  if (attrSpace < 0)
537  return false;
538 
539  if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
540  return false;
541 
542  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_DOUBLE,
543  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
544  if (attr < 0) {
545  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
546  H5Aclose(attr);
547  H5Sclose(attrSpace);
548  return false;
549  }
550 
551  if (H5Awrite(attr, H5T_NATIVE_DOUBLE, &value) < 0) {
552  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
553  H5Aclose(attr);
554  H5Sclose(attrSpace);
555  return false;
556  }
557 
558  H5Aclose(attr);
559  H5Sclose(attrSpace);
560 
561  return true;
562 }

References g_hdf5Mutex, Msg::print(), and Msg::SevWarning.

◆ writeAttribute() [5/7]

bool Hdf5Util::writeAttribute ( hid_t  location,
const string &  attrName,
std::vector< unsigned int > &  attrSize,
const int &  value 
)

Definition at line 568 of file Hdf5Util.cpp.

570 {
571  GlobalLock lock(g_hdf5Mutex);
572 
573  hid_t attr;
574  hid_t attrSpace;
575  size_t rank = attrSize.size();
576 
577  boost::scoped_array<hsize_t> current_dims(new hsize_t[rank]);
578  boost::scoped_array<hsize_t> max_dims(new hsize_t[rank]);
579 
580  for (size_t i=0; i < rank; i++)
581  current_dims[i] = attrSize[i];
582 
583  for (size_t i=0; i < rank; i++)
584  max_dims[i] = H5S_UNLIMITED;
585 
586  attrSpace = H5Screate(H5S_SIMPLE);
587  if (attrSpace < 0)
588  return false;
589 
590  if (H5Sset_extent_simple(attrSpace, (int)rank,
591  current_dims.get(), max_dims.get()) < 0) {
592  return false;
593  }
594 
595  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_INT,
596  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
597  if (attr < 0) {
598  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
599  H5Aclose(attr);
600  H5Sclose(attrSpace);
601  return false;
602  }
603 
604  if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) {
605  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
606  H5Aclose(attr);
607  H5Sclose(attrSpace);
608  return false;
609  }
610 
611  H5Aclose(attr);
612  H5Sclose(attrSpace);
613 
614  return true;
615 }

References g_hdf5Mutex, Msg::print(), and Msg::SevWarning.

◆ writeAttribute() [6/7]

bool Hdf5Util::writeAttribute ( hid_t  location,
const string &  attrName,
std::vector< unsigned int > &  attrSize,
const float &  value 
)

Definition at line 620 of file Hdf5Util.cpp.

622 {
623  GlobalLock lock(g_hdf5Mutex);
624 
625  hid_t attr;
626  hid_t attrSpace;
627  size_t rank = attrSize.size();
628 
629  boost::scoped_array<hsize_t> current_dims(new hsize_t[rank]);
630  boost::scoped_array<hsize_t> max_dims(new hsize_t[rank]);
631 
632  for (size_t i=0; i < rank; i++)
633  current_dims[i] = attrSize[i];
634 
635  for (size_t i=0; i < rank; i++)
636  max_dims[i] = H5S_UNLIMITED;
637 
638  attrSpace = H5Screate(H5S_SIMPLE);
639  if (attrSpace < 0)
640  return false;
641 
642  if (H5Sset_extent_simple(attrSpace, (int)rank,
643  current_dims.get(), max_dims.get()) < 0) {
644  return false;
645  }
646 
647  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_FLOAT,
648  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
649  if (attr < 0) {
650  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
651  H5Aclose(attr);
652  H5Sclose(attrSpace);
653  return false;
654  }
655 
656  if (H5Awrite(attr, H5T_NATIVE_FLOAT, &value) < 0) {
657  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
658  H5Aclose(attr);
659  H5Sclose(attrSpace);
660  return false;
661  }
662 
663  H5Aclose(attr);
664  H5Sclose(attrSpace);
665 
666  return true;
667 }

References g_hdf5Mutex, Msg::print(), and Msg::SevWarning.

◆ writeAttribute() [7/7]

bool Hdf5Util::writeAttribute ( hid_t  location,
const string &  attrName,
std::vector< unsigned int > &  attrSize,
const double &  value 
)

Definition at line 672 of file Hdf5Util.cpp.

674 {
675  GlobalLock lock(g_hdf5Mutex);
676 
677  hid_t attr;
678  hid_t attrSpace;
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]);
682 
683  for (size_t i=0; i < rank; i++)
684  current_dims[i] = attrSize[i];
685 
686  for (size_t i=0; i < rank; i++)
687  max_dims[i] = H5S_UNLIMITED;
688 
689  attrSpace = H5Screate(H5S_SIMPLE);
690  if (attrSpace < 0)
691  return false;
692 
693  if (H5Sset_extent_simple(attrSpace, (int)rank,
694  current_dims.get(), max_dims.get()) < 0) {
695  return false;
696  }
697 
698  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_DOUBLE,
699  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
700  if (attr < 0) {
701  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
702  H5Aclose(attr);
703  H5Sclose(attrSpace);
704  return false;
705  }
706 
707  if (H5Awrite(attr, H5T_NATIVE_DOUBLE, &value) < 0) {
708  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
709  H5Aclose(attr);
710  H5Sclose(attrSpace);
711  return false;
712  }
713 
714  H5Aclose(attr);
715  H5Sclose(attrSpace);
716 
717  return true;
718 }

References g_hdf5Mutex, Msg::print(), and Msg::SevWarning.

Msg::SevWarning
Definition: Log.h:68
g_hdf5Mutex
boost::recursive_mutex g_hdf5Mutex
Definition: Hdf5Util.cpp:67
GlobalLock
boost::recursive_mutex::scoped_lock GlobalLock
Definition: Hdf5Util.h:78
Msg::print
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition: Log.cpp:70