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

bool checkHdf5Gzip ()
 Checks whether gzip is available in the current hdf5 library. More...
 
bool readAttribute (hid_t location, const string &attrName, string &value)
 
bool readAttribute (hid_t location, const string &attrName, unsigned int attrSize, int &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, double &value)
 
bool readAttribute (hid_t location, const string &attrName, std::vector< unsigned int > &attrSize, int &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, double &value)
 
bool writeAttribute (hid_t location, const string &attrName, const string &value)
 
bool writeAttribute (hid_t location, const string &attrName, unsigned int attrSize, const int &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 double &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, std::vector< unsigned int > &attrSize, const float &value)
 
bool writeAttribute (hid_t location, const string &attrName, std::vector< unsigned int > &attrSize, const double &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
bool readAttribute (hid_t location, const std::string &attrName, std::string &value)
 Reads a string attribute. More...
 
bool readAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, int &value)
 Reads an int attribute of arbitrary size. More...
 
bool readAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, float &value)
 Reads a float attribute of arbitrary size. More...
 
bool readAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, double &value)
 Reads a double attribute of arbitrary size. More...
 
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...
 
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...
 
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
bool writeAttribute (hid_t location, const std::string &attrName, const std::string &value)
 Writes a string attribute. More...
 
bool writeAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, const int &value)
 Writes an int attribute of arbitrary size. More...
 
bool writeAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, const float &value)
 Writes a float attribute of arbitrary size. More...
 
bool writeAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, const double &value)
 Writes a double attribute of arbitrary size. More...
 
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...
 
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...
 
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 68 of file Hdf5Util.cpp.

69 {
70  H5T_class_t typeClass;
71  H5A_info_t attrInfo;
72  hsize_t strLen;
73 
74  if (H5Aexists(location, attrName.c_str()) < 1)
75  throw MissingAttributeException("Couldn't find attribute " + attrName);
76 
77  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
78  H5ScopedAget_space attrSpace(attr);
79  H5ScopedAget_type attrType(attr);
80 
81  if (H5Aget_info(attr, &attrInfo) < 0) {
82  throw MissingAttributeException("Couldn't get attribute info " + attrName);
83  } else {
84  strLen = attrInfo.data_size;
85  }
86 
87  typeClass = H5Tget_class(attrType);
88 
89  if (typeClass != H5T_STRING)
90  throw MissingAttributeException("Bad attribute type class for " + attrName);
91 
92  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
93 
94  std::vector<char> tempString(strLen + 1);
95 
96  if (H5Aread(attr, nativeType, &tempString[0]) < 0)
97  throw MissingAttributeException("Couldn't read attribute " + attrName);
98 
99  value = string(&tempString[0]);
100 
101  return true;
102 
103 }

◆ readAttribute() [2/7]

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

Definition at line 108 of file Hdf5Util.cpp.

110 {
111  H5T_class_t typeClass;
112 
113  if (H5Aexists(location, attrName.c_str()) < 1)
114  throw MissingAttributeException("Couldn't find attribute " + attrName);
115 
116  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
117  H5ScopedAget_space attrSpace(attr);
118  H5ScopedAget_type attrType(attr);
119 
120  if (H5Sget_simple_extent_ndims(attrSpace) != 1)
121  throw MissingAttributeException("Bad attribute rank for attribute " +
122  attrName);
123 
124  hsize_t dims[1];
125  H5Sget_simple_extent_dims(attrSpace, dims, NULL);
126 
127  if (dims[0] != attrSize)
128  throw MissingAttributeException("Invalid attribute size for attribute " +
129  attrName);
130 
131  typeClass = H5Tget_class(attrType);
132 
133  if (typeClass != H5T_INTEGER)
134  throw MissingAttributeException("Bad attribute type class for " +
135  attrName);
136 
137  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
138 
139  if (H5Aread(attr, nativeType, &value) < 0)
140  throw MissingAttributeException("Couldn't read attribute " + attrName);
141 
142  return true;
143 
144 }

◆ readAttribute() [3/7]

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

Definition at line 149 of file Hdf5Util.cpp.

151 {
152  H5T_class_t typeClass;
153 
154  if (H5Aexists(location, attrName.c_str()) < 1)
155  throw MissingAttributeException("Couldn't find attribute " + attrName);
156 
157  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
158  H5ScopedAget_space attrSpace(attr);
159  H5ScopedAget_type attrType(attr);
160 
161  if (H5Sget_simple_extent_ndims(attrSpace) != 1)
162  throw MissingAttributeException("Bad attribute rank for attribute " +
163  attrName);
164 
165  hsize_t dims[1];
166  H5Sget_simple_extent_dims(attrSpace, dims, NULL);
167 
168  if (dims[0] != attrSize)
169  throw MissingAttributeException("Invalid attribute size for attribute " +
170  attrName);
171 
172  typeClass = H5Tget_class(attrType);
173 
174  if (typeClass != H5T_FLOAT)
175  throw MissingAttributeException("Bad attribute type class for " +
176  attrName);
177 
178  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
179 
180  if (H5Aread(attr, nativeType, &value) < 0)
181  throw MissingAttributeException("Couldn't read attribute " + attrName);
182 
183  return true;
184 }

◆ readAttribute() [4/7]

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

Definition at line 189 of file Hdf5Util.cpp.

191 {
192  H5T_class_t typeClass;
193 
194  if (H5Aexists(location, attrName.c_str()) < 0)
195  throw MissingAttributeException("Couldn't find attribute " + attrName);
196 
197  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
198  H5ScopedAget_space attrSpace(attr);
199  H5ScopedAget_type attrType(attr);
200 
201  if (H5Sget_simple_extent_ndims(attrSpace) != 1)
202  throw MissingAttributeException("Bad attribute rank for attribute " +
203  attrName);
204 
205  hsize_t dims[1];
206  H5Sget_simple_extent_dims(attrSpace, dims, NULL);
207 
208  if (dims[0] != attrSize)
209  throw MissingAttributeException("Invalid attribute size for attribute " +
210  attrName);
211 
212  typeClass = H5Tget_class(attrType);
213 
214  if (typeClass != H5T_FLOAT)
215  throw MissingAttributeException("Bad attribute type class for " +
216  attrName);
217 
218  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
219 
220  if (H5Aread(attr, nativeType, &value) < 0)
221  throw MissingAttributeException("Couldn't read attribute " + attrName);
222 
223  return true;
224 }

◆ readAttribute() [5/7]

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

Definition at line 229 of file Hdf5Util.cpp.

231 {
232  H5T_class_t typeClass;
233  int rank = attrSize.size();
234 
235  if (H5Aexists(location, attrName.c_str()) < 0)
236  throw MissingAttributeException("Couldn't find attribute " + attrName);
237 
238  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
239  H5ScopedAget_space attrSpace(attr);
240  H5ScopedAget_type attrType(attr);
241 
242 
243  if (H5Sget_simple_extent_ndims(attrSpace) != rank)
244  throw MissingAttributeException("Bad attribute rank for attribute " +
245  attrName);
246 
247  hsize_t dims[rank];
248  H5Sget_simple_extent_dims(attrSpace, dims, NULL);
249 
250  for (int i=0; i < rank; i++) {
251  if (dims[i] != attrSize[i])
252  throw MissingAttributeException("Invalid attribute size for attribute " +
253  attrName);
254  }
255 
256  typeClass = H5Tget_class(attrType);
257 
258  if (typeClass != H5T_INTEGER)
259  throw MissingAttributeException("Bad attribute type class for " +
260  attrName);
261 
262  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
263 
264  if (H5Aread(attr, nativeType, &value) < 0)
265  throw MissingAttributeException("Couldn't read attribute " + attrName);
266 
267  return true;
268 }

◆ readAttribute() [6/7]

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

Definition at line 273 of file Hdf5Util.cpp.

275 {
276  H5T_class_t typeClass;
277  int rank = attrSize.size();
278 
279  if (H5Aexists(location, attrName.c_str()) < 0)
280  throw MissingAttributeException("Couldn't find attribute " + attrName);
281 
282  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
283  H5ScopedAget_space attrSpace(attr);
284  H5ScopedAget_type attrType(attr);
285 
286 
287  if (H5Sget_simple_extent_ndims(attrSpace) != rank)
288  throw MissingAttributeException("Bad attribute rank for attribute " +
289  attrName);
290 
291  hsize_t dims[rank];
292  H5Sget_simple_extent_dims(attrSpace, dims, NULL);
293 
294  for (int i=0; i < rank; i++) {
295  if (dims[i] != attrSize[i])
296  throw MissingAttributeException("Invalid attribute size for attribute " +
297  attrName);
298  }
299 
300  typeClass = H5Tget_class(attrType);
301 
302  if (typeClass != H5T_FLOAT)
303  throw MissingAttributeException("Bad attribute type class for " +
304  attrName);
305 
306  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
307 
308  if (H5Aread(attr, nativeType, &value) < 0)
309  throw MissingAttributeException("Couldn't read attribute " + attrName);
310 
311  return true;
312 }

◆ readAttribute() [7/7]

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

Definition at line 317 of file Hdf5Util.cpp.

319 {
320 
321  H5T_class_t typeClass;
322  int rank = attrSize.size();
323 
324  if (H5Aexists(location, attrName.c_str()) < 0)
325  throw MissingAttributeException("Couldn't find attribute " + attrName);
326 
327  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
328  H5ScopedAget_space attrSpace(attr);
329  H5ScopedAget_type attrType(attr);
330 
331 
332  if (H5Sget_simple_extent_ndims(attrSpace) != rank)
333  throw MissingAttributeException("Bad attribute rank for attribute " +
334  attrName);
335 
336  hsize_t dims[rank];
337  H5Sget_simple_extent_dims(attrSpace, dims, NULL);
338 
339  for (int i=0; i < rank; i++) {
340  if (dims[i] != attrSize[i])
341  throw MissingAttributeException("Invalid attribute size for attribute " +
342  attrName);
343  }
344 
345  typeClass = H5Tget_class(attrType);
346 
347  if (typeClass != H5T_FLOAT)
348  throw MissingAttributeException("Bad attribute type class for " +
349  attrName);
350 
351  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
352 
353  if (H5Aread(attr, nativeType, &value) < 0)
354  throw MissingAttributeException("Couldn't read attribute " + attrName);
355 
356  return true;
357 }

◆ writeAttribute() [1/7]

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

Definition at line 362 of file Hdf5Util.cpp.

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

363 {
364  hid_t attr = -1;
365  hid_t attrSpace;
366  hid_t attrType;
367 
368  bool success = true;
369 
370  attrSpace = H5Screate(H5S_SCALAR);
371  if (attrSpace == -1)
372  success = false;
373 
374  attrType = H5Tcopy(H5T_C_S1);
375  if (attrType == -1)
376  success = false;
377 
378  if (value.size()) {
379  // if the string is null the following will return error
380  // which we don't want.
381  if (success && H5Tset_size(attrType, value.size()) == -1){
382  success = false;
383  }
384  }
385 
386  if (success) {
387  H5Tset_strpad(attrType, H5T_STR_NULLTERM);
388  attr = H5Acreate(location, attrName.c_str(), attrType, attrSpace,
389  H5P_DEFAULT, H5P_DEFAULT);
390  }
391 
392  if (attr == -1) {
393  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
394  success = false;
395  }
396 
397  if (success && H5Awrite(attr, attrType, value.c_str()) == -1) {
398  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
399  success = false;
400  }
401 
402  H5Aclose(attr);
403  H5Tclose(attrType);
404  H5Sclose(attrSpace);
405 
406  return success;
407 
408 }
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62

◆ writeAttribute() [2/7]

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

Definition at line 413 of file Hdf5Util.cpp.

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

415 {
416  hid_t attr;
417  hid_t attrSpace;
418  hsize_t dims[1];
419 
420  dims[0] = attrSize;
421 
422  attrSpace = H5Screate(H5S_SIMPLE);
423  if (attrSpace < 0)
424  return false;
425 
426  if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
427  return false;
428 
429  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_INT,
430  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
431  if (attr < 0) {
432  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
433  H5Aclose(attr);
434  H5Sclose(attrSpace);
435  return false;
436  }
437 
438  if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) {
439  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
440  H5Aclose(attr);
441  H5Sclose(attrSpace);
442  return false;
443  }
444 
445  H5Aclose(attr);
446  H5Sclose(attrSpace);
447 
448  return true;
449 }
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62

◆ writeAttribute() [3/7]

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

Definition at line 454 of file Hdf5Util.cpp.

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

456 {
457  hid_t attr;
458  hid_t attrSpace;
459  hsize_t dims[1];
460 
461  dims[0] = attrSize;
462 
463  attrSpace = H5Screate(H5S_SIMPLE);
464  if (attrSpace < 0)
465  return false;
466 
467  if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
468  return false;
469 
470  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_FLOAT,
471  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
472  if (attr < 0) {
473  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
474  H5Aclose(attr);
475  H5Sclose(attrSpace);
476  return false;
477  }
478 
479  if (H5Awrite(attr, H5T_NATIVE_FLOAT, &value) < 0) {
480  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
481  H5Aclose(attr);
482  H5Sclose(attrSpace);
483  return false;
484  }
485 
486  H5Aclose(attr);
487  H5Sclose(attrSpace);
488 
489  return true;
490 }
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62

◆ writeAttribute() [4/7]

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

Definition at line 495 of file Hdf5Util.cpp.

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

497 {
498  hid_t attr;
499  hid_t attrSpace;
500  hsize_t dims[1];
501 
502  dims[0] = attrSize;
503 
504  attrSpace = H5Screate(H5S_SIMPLE);
505  if (attrSpace < 0)
506  return false;
507 
508  if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
509  return false;
510 
511  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_DOUBLE,
512  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
513  if (attr < 0) {
514  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
515  H5Aclose(attr);
516  H5Sclose(attrSpace);
517  return false;
518  }
519 
520  if (H5Awrite(attr, H5T_NATIVE_DOUBLE, &value) < 0) {
521  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
522  H5Aclose(attr);
523  H5Sclose(attrSpace);
524  return false;
525  }
526 
527  H5Aclose(attr);
528  H5Sclose(attrSpace);
529 
530  return true;
531 }
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62

◆ writeAttribute() [5/7]

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

Definition at line 537 of file Hdf5Util.cpp.

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

539 {
540  hid_t attr;
541  hid_t attrSpace;
542  size_t rank = attrSize.size();
543  hsize_t current_dims[rank];
544  hsize_t max_dims[rank];
545 
546  for (size_t i=0; i < rank; i++)
547  current_dims[i] = attrSize[i];
548 
549  for (size_t i=0; i < rank; i++)
550  max_dims[i] = H5S_UNLIMITED;
551 
552  attrSpace = H5Screate(H5S_SIMPLE);
553  if (attrSpace < 0)
554  return false;
555 
556  if (H5Sset_extent_simple(attrSpace, rank, current_dims, max_dims) < 0) {
557  return false;
558  }
559 
560  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_INT,
561  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
562  if (attr < 0) {
563  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
564  H5Aclose(attr);
565  H5Sclose(attrSpace);
566  return false;
567  }
568 
569  if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) {
570  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
571  H5Aclose(attr);
572  H5Sclose(attrSpace);
573  return false;
574  }
575 
576  H5Aclose(attr);
577  H5Sclose(attrSpace);
578 
579  return true;
580 }
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62

◆ writeAttribute() [6/7]

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

Definition at line 585 of file Hdf5Util.cpp.

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

587 {
588  hid_t attr;
589  hid_t attrSpace;
590  size_t rank = attrSize.size();
591  hsize_t current_dims[rank];
592  hsize_t max_dims[rank];
593 
594  for (size_t i=0; i < rank; i++)
595  current_dims[i] = attrSize[i];
596 
597  for (size_t i=0; i < rank; i++)
598  max_dims[i] = H5S_UNLIMITED;
599 
600  attrSpace = H5Screate(H5S_SIMPLE);
601  if (attrSpace < 0)
602  return false;
603 
604  if (H5Sset_extent_simple(attrSpace, rank, current_dims, max_dims) < 0) {
605  return false;
606  }
607 
608  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_FLOAT,
609  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
610  if (attr < 0) {
611  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
612  H5Aclose(attr);
613  H5Sclose(attrSpace);
614  return false;
615  }
616 
617  if (H5Awrite(attr, H5T_NATIVE_FLOAT, &value) < 0) {
618  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
619  H5Aclose(attr);
620  H5Sclose(attrSpace);
621  return false;
622  }
623 
624  H5Aclose(attr);
625  H5Sclose(attrSpace);
626 
627  return true;
628 }
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62

◆ writeAttribute() [7/7]

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

Definition at line 633 of file Hdf5Util.cpp.

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

635 {
636  hid_t attr;
637  hid_t attrSpace;
638  size_t rank = attrSize.size();
639  hsize_t current_dims[rank];
640  hsize_t max_dims[rank];
641 
642  for (size_t i=0; i < rank; i++)
643  current_dims[i] = attrSize[i];
644 
645  for (size_t i=0; i < rank; i++)
646  max_dims[i] = H5S_UNLIMITED;
647 
648  attrSpace = H5Screate(H5S_SIMPLE);
649  if (attrSpace < 0)
650  return false;
651 
652  if (H5Sset_extent_simple(attrSpace, rank, current_dims, max_dims) < 0) {
653  return false;
654  }
655 
656  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_DOUBLE,
657  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
658  if (attr < 0) {
659  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
660  H5Aclose(attr);
661  H5Sclose(attrSpace);
662  return false;
663  }
664 
665  if (H5Awrite(attr, H5T_NATIVE_DOUBLE, &value) < 0) {
666  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
667  H5Aclose(attr);
668  H5Sclose(attrSpace);
669  return false;
670  }
671 
672  H5Aclose(attr);
673  H5Sclose(attrSpace);
674 
675  return true;
676 }
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62