Hdf5Util Namespace Reference
Classes and functions used to implement this library » Hdf5 Utility Classes and Functions

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.
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.
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.
Attribute reading
FIELD3D_API bool | readAttribute (hid_t location, const std::string &attrName, std::string &value)
| Reads a string attribute.
FIELD3D_API bool | readAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, int &value)
| Reads an int attribute of arbitrary size.
FIELD3D_API bool | readAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, float &value)
| Reads a float attribute of arbitrary size.
FIELD3D_API bool | readAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, double &value)
| Reads a double attribute of arbitrary size.
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.
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.
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.
Attribute writing
FIELD3D_API bool | writeAttribute (hid_t location, const std::string &attrName, const std::string &value)
| Writes a string attribute.
FIELD3D_API bool | writeAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, const int &value)
| Writes an int attribute of arbitrary size.
FIELD3D_API bool | writeAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, const float &value)
| Writes a float attribute of arbitrary size.
FIELD3D_API bool | writeAttribute (hid_t location, const std::string &attrName, unsigned int attrSize, const double &value)
| Writes a double attribute of arbitrary size.
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.
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.
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.

## 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.

{
GlobalLock lock(g_hdf5Mutex);
H5T_class_t typeClass;
H5A_info_t attrInfo;
hsize_t strLen;
if (H5Aexists(location, attrName.c_str()) < 1)
throw MissingAttributeException("Couldn't find attribute " + attrName);
H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
H5ScopedAget_space attrSpace(attr);
H5ScopedAget_type attrType(attr);
if (H5Aget_info(attr, &attrInfo) < 0) {
throw MissingAttributeException("Couldn't get attribute info " + attrName);
} else {
strLen = attrInfo.data_size;
}
typeClass = H5Tget_class(attrType);
if (typeClass != H5T_STRING)
throw MissingAttributeException("Bad attribute type class for " + attrName);
H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
std::vector<char> tempString(strLen + 1);
if (H5Aread(attr, nativeType, &tempString[0]) < 0)
throw MissingAttributeException("Couldn't read attribute " + attrName);
value = string(&tempString[0]);
return true;
}
g_hdf5Mutex
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
Definition Hdf5Util.cpp:67
GlobalLock
boost::recursive_mutex::scoped_lock GlobalLock
Definition Hdf5Util.h:78
Hdf5Util::H5ScopedAget_space
Scoped object - opens an attribute data space on creation and closes it on destruction.
Definition Hdf5Util.h:288
Hdf5Util::H5ScopedAget_type
Scoped object - opens an attribute data type on creation and closes it on destruction.
Definition Hdf5Util.h:311
Hdf5Util::H5ScopedAopen
Scoped object - Opens attribute by name and closes it on destruction.
Definition Hdf5Util.h:114
Hdf5Util::H5ScopedTget_native_type
Scoped object - opens an native type id on creation and closes it on destruction.
Definition Hdf5Util.h:334

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.

{
GlobalLock lock(g_hdf5Mutex);
H5T_class_t typeClass;
if (H5Aexists(location, attrName.c_str()) < 1)
throw MissingAttributeException("Couldn't find attribute " + attrName);
H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
H5ScopedAget_space attrSpace(attr);
H5ScopedAget_type attrType(attr);
if (H5Sget_simple_extent_ndims(attrSpace) != 1)
throw MissingAttributeException("Bad attribute rank for attribute " +
attrName);
hsize_t dims[1];
H5Sget_simple_extent_dims(attrSpace, dims, NULL);
if (dims[0] != attrSize)
throw MissingAttributeException("Invalid attribute size for attribute " +
attrName);
typeClass = H5Tget_class(attrType);
if (typeClass != H5T_INTEGER)
throw MissingAttributeException("Bad attribute type class for " +
attrName);
H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
if (H5Aread(attr, nativeType, &value) < 0)
throw MissingAttributeException("Couldn't read attribute " + attrName);
return true;
}

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.

{
GlobalLock lock(g_hdf5Mutex);
H5T_class_t typeClass;
if (H5Aexists(location, attrName.c_str()) < 1)
throw MissingAttributeException("Couldn't find attribute " + attrName);
H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
H5ScopedAget_space attrSpace(attr);
H5ScopedAget_type attrType(attr);
if (H5Sget_simple_extent_ndims(attrSpace) != 1)
throw MissingAttributeException("Bad attribute rank for attribute " +
attrName);
hsize_t dims[1];
H5Sget_simple_extent_dims(attrSpace, dims, NULL);
if (dims[0] != attrSize)
throw MissingAttributeException("Invalid attribute size for attribute " +
attrName);
typeClass = H5Tget_class(attrType);
if (typeClass != H5T_FLOAT)
throw MissingAttributeException("Bad attribute type class for " +
attrName);
H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
if (H5Aread(attr, nativeType, &value) < 0)
throw MissingAttributeException("Couldn't read attribute " + attrName);
return true;
}

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.

{
GlobalLock lock(g_hdf5Mutex);
H5T_class_t typeClass;
if (H5Aexists(location, attrName.c_str()) < 0)
throw MissingAttributeException("Couldn't find attribute " + attrName);
H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
H5ScopedAget_space attrSpace(attr);
H5ScopedAget_type attrType(attr);
if (H5Sget_simple_extent_ndims(attrSpace) != 1)
throw MissingAttributeException("Bad attribute rank for attribute " +
attrName);
hsize_t dims[1];
H5Sget_simple_extent_dims(attrSpace, dims, NULL);
if (dims[0] != attrSize)
throw MissingAttributeException("Invalid attribute size for attribute " +
attrName);
typeClass = H5Tget_class(attrType);
if (typeClass != H5T_FLOAT)
throw MissingAttributeException("Bad attribute type class for " +
attrName);
H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
if (H5Aread(attr, nativeType, &value) < 0)
throw MissingAttributeException("Couldn't read attribute " + attrName);
return true;
}

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.

{
GlobalLock lock(g_hdf5Mutex);
H5T_class_t typeClass;
size_t rank = attrSize.size();
if (H5Aexists(location, attrName.c_str()) < 0)
throw MissingAttributeException("Couldn't find attribute " + attrName);
H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
H5ScopedAget_space attrSpace(attr);
H5ScopedAget_type attrType(attr);
if (H5Sget_simple_extent_ndims(attrSpace) != (int) rank)
throw MissingAttributeException("Bad attribute rank for attribute " +
attrName);
boost::scoped_array<hsize_t> dims(new hsize_t[rank]);
H5Sget_simple_extent_dims(attrSpace, dims.get(), NULL);
for (size_t i=0; i < rank; i++) {
if (dims[i] != attrSize[i])
throw MissingAttributeException("Invalid attribute size for attribute " +
attrName);
}
typeClass = H5Tget_class(attrType);
if (typeClass != H5T_INTEGER)
throw MissingAttributeException("Bad attribute type class for " +
attrName);
H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
if (H5Aread(attr, nativeType, &value) < 0)
throw MissingAttributeException("Couldn't read attribute " + attrName);
return true;
}

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.

{
GlobalLock lock(g_hdf5Mutex);
H5T_class_t typeClass;
size_t rank = attrSize.size();
if (H5Aexists(location, attrName.c_str()) < 0)
throw MissingAttributeException("Couldn't find attribute " + attrName);
H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
H5ScopedAget_space attrSpace(attr);
H5ScopedAget_type attrType(attr);
if (H5Sget_simple_extent_ndims(attrSpace) != (int) rank)
throw MissingAttributeException("Bad attribute rank for attribute " +
attrName);
boost::scoped_array<hsize_t> dims(new hsize_t[rank]);
H5Sget_simple_extent_dims(attrSpace, dims.get(), NULL);
for (size_t i=0; i < rank; i++) {
if (dims[i] != attrSize[i])
throw MissingAttributeException("Invalid attribute size for attribute " +
attrName);
}
typeClass = H5Tget_class(attrType);
if (typeClass != H5T_FLOAT)
throw MissingAttributeException("Bad attribute type class for " +
attrName);
H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
if (H5Aread(attr, nativeType, &value) < 0)
throw MissingAttributeException("Couldn't read attribute " + attrName);
return true;
}

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.

{
GlobalLock lock(g_hdf5Mutex);
H5T_class_t typeClass;
size_t rank = attrSize.size();
if (H5Aexists(location, attrName.c_str()) < 0)
throw MissingAttributeException("Couldn't find attribute " + attrName);
H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
H5ScopedAget_space attrSpace(attr);
H5ScopedAget_type attrType(attr);
if (H5Sget_simple_extent_ndims(attrSpace) != (int) rank)
throw MissingAttributeException("Bad attribute rank for attribute " +
attrName);
boost::scoped_array<hsize_t> dims(new hsize_t[rank]);
H5Sget_simple_extent_dims(attrSpace, dims.get(), NULL);
for (size_t i=0; i < rank; i++) {
if (dims[i] != attrSize[i])
throw MissingAttributeException("Invalid attribute size for attribute " +
attrName);
}
typeClass = H5Tget_class(attrType);
if (typeClass != H5T_FLOAT)
throw MissingAttributeException("Bad attribute type class for " +
attrName);
H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
if (H5Aread(attr, nativeType, &value) < 0)
throw MissingAttributeException("Couldn't read attribute " + attrName);
return true;
}

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.

{
GlobalLock lock(g_hdf5Mutex);
hid_t attr = -1;
hid_t attrSpace;
hid_t attrType;
bool success = true;
attrSpace = H5Screate(H5S_SCALAR);
if (attrSpace == -1)
success = false;
attrType = H5Tcopy(H5T_C_S1);
if (attrType == -1)
success = false;
if (value.size()) {
// if the string is null the following will return error
// which we don't want.
if (success && H5Tset_size(attrType, value.size()) == -1){
success = false;
}
}
if (success) {
H5Tset_strpad(attrType, H5T_STR_NULLTERM);
attr = H5Acreate(location, attrName.c_str(), attrType, attrSpace,
H5P_DEFAULT, H5P_DEFAULT);
}
if (attr == -1) {
Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
success = false;
}
if (success && H5Awrite(attr, attrType, value.c_str()) == -1) {
Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
success = false;
}
H5Aclose(attr);
H5Tclose(attrType);
H5Sclose(attrSpace);
return success;
}
Msg::SevWarning
@ SevWarning
Definition Log.h:68
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

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.

{
GlobalLock lock(g_hdf5Mutex);
hid_t attr;
hid_t attrSpace;
hsize_t dims[1];
dims[0] = attrSize;
attrSpace = H5Screate(H5S_SIMPLE);
if (attrSpace < 0)
return false;
if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
return false;
attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_INT,
attrSpace, H5P_DEFAULT, H5P_DEFAULT);
if (attr < 0) {
Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
H5Aclose(attr);
H5Sclose(attrSpace);
return false;
}
if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) {
Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
H5Aclose(attr);
H5Sclose(attrSpace);
return false;
}
H5Aclose(attr);
H5Sclose(attrSpace);
return true;
}

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.

{
GlobalLock lock(g_hdf5Mutex);
hid_t attr;
hid_t attrSpace;
hsize_t dims[1];
dims[0] = attrSize;
attrSpace = H5Screate(H5S_SIMPLE);
if (attrSpace < 0)
return false;
if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
return false;
attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_FLOAT,
attrSpace, H5P_DEFAULT, H5P_DEFAULT);
if (attr < 0) {
Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
H5Aclose(attr);
H5Sclose(attrSpace);
return false;
}
if (H5Awrite(attr, H5T_NATIVE_FLOAT, &value) < 0) {
Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
H5Aclose(attr);
H5Sclose(attrSpace);
return false;
}
H5Aclose(attr);
H5Sclose(attrSpace);
return true;
}

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.

{
GlobalLock lock(g_hdf5Mutex);
hid_t attr;
hid_t attrSpace;
hsize_t dims[1];
dims[0] = attrSize;
attrSpace = H5Screate(H5S_SIMPLE);
if (attrSpace < 0)
return false;
if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
return false;
attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_DOUBLE,
attrSpace, H5P_DEFAULT, H5P_DEFAULT);
if (attr < 0) {
Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
H5Aclose(attr);
H5Sclose(attrSpace);
return false;
}
if (H5Awrite(attr, H5T_NATIVE_DOUBLE, &value) < 0) {
Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
H5Aclose(attr);
H5Sclose(attrSpace);
return false;
}
H5Aclose(attr);
H5Sclose(attrSpace);
return true;
}

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.

{
GlobalLock lock(g_hdf5Mutex);
hid_t attr;
hid_t attrSpace;
size_t rank = attrSize.size();
boost::scoped_array<hsize_t> current_dims(new hsize_t[rank]);
boost::scoped_array<hsize_t> max_dims(new hsize_t[rank]);
for (size_t i=0; i < rank; i++)
current_dims[i] = attrSize[i];
for (size_t i=0; i < rank; i++)
max_dims[i] = H5S_UNLIMITED;
attrSpace = H5Screate(H5S_SIMPLE);
if (attrSpace < 0)
return false;
if (H5Sset_extent_simple(attrSpace, (int)rank,
current_dims.get(), max_dims.get()) < 0) {
return false;
}
attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_INT,
attrSpace, H5P_DEFAULT, H5P_DEFAULT);
if (attr < 0) {
Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
H5Aclose(attr);
H5Sclose(attrSpace);
return false;
}
if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) {
Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
H5Aclose(attr);
H5Sclose(attrSpace);
return false;
}
H5Aclose(attr);
H5Sclose(attrSpace);
return true;
}

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.

{
GlobalLock lock(g_hdf5Mutex);
hid_t attr;
hid_t attrSpace;
size_t rank = attrSize.size();
boost::scoped_array<hsize_t> current_dims(new hsize_t[rank]);
boost::scoped_array<hsize_t> max_dims(new hsize_t[rank]);
for (size_t i=0; i < rank; i++)
current_dims[i] = attrSize[i];
for (size_t i=0; i < rank; i++)
max_dims[i] = H5S_UNLIMITED;
attrSpace = H5Screate(H5S_SIMPLE);
if (attrSpace < 0)
return false;
if (H5Sset_extent_simple(attrSpace, (int)rank,
current_dims.get(), max_dims.get()) < 0) {
return false;
}
attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_FLOAT,
attrSpace, H5P_DEFAULT, H5P_DEFAULT);
if (attr < 0) {
Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
H5Aclose(attr);
H5Sclose(attrSpace);
return false;
}
if (H5Awrite(attr, H5T_NATIVE_FLOAT, &value) < 0) {
Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
H5Aclose(attr);
H5Sclose(attrSpace);
return false;
}
H5Aclose(attr);
H5Sclose(attrSpace);
return true;
}

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.

{
GlobalLock lock(g_hdf5Mutex);
hid_t attr;
hid_t attrSpace;
size_t rank = attrSize.size();
boost::scoped_array<hsize_t> current_dims(new hsize_t[rank]);
boost::scoped_array<hsize_t> max_dims(new hsize_t[rank]);
for (size_t i=0; i < rank; i++)
current_dims[i] = attrSize[i];
for (size_t i=0; i < rank; i++)
max_dims[i] = H5S_UNLIMITED;
attrSpace = H5Screate(H5S_SIMPLE);
if (attrSpace < 0)
return false;
if (H5Sset_extent_simple(attrSpace, (int)rank,
current_dims.get(), max_dims.get()) < 0) {
return false;
}
attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_DOUBLE,
attrSpace, H5P_DEFAULT, H5P_DEFAULT);
if (attr < 0) {
Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
H5Aclose(attr);
H5Sclose(attrSpace);
return false;
}
if (H5Awrite(attr, H5T_NATIVE_DOUBLE, &value) < 0) {
Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
H5Aclose(attr);
H5Sclose(attrSpace);
return false;
}
H5Aclose(attr);
H5Sclose(attrSpace);
return true;
}

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