Hdf5 Utility Classes and Functions
Classes and functions used to implement this library

## Namespaces

namespace | Hdf5Util
| Contains utility functions and classes for Hdf5 files.

## Classes

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

## Functions

FIELD3D_API bool | Hdf5Util::checkHdf5Gzip ()
| Checks whether gzip is available in the current hdf5 library.

## Read/write simple data to hdf5 location

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

## Function Documentation

## writeSimpleData()

template<typename T>

void Hdf5Util::writeSimpleData | ( | hid_t | location,
|  | const std::string & | name,
|  | const std::vector< T > & | data )

Writes a simple linear data set to the given location.

Definition at line 572 of file Hdf5Util.h.

{
using namespace Exc;
GlobalLock lock(g_hdf5Mutex);
// Calculate the total number of entries. This factors in that
// V3f uses 3 components per value, etc.
hsize_t totalSize[1];
int components = FieldTraits<T>::dataDims();
totalSize[0] = data.size() * components;
// Get the internal data type
hid_t type = DataTypeTraits<T>::h5type();
H5ScopedScreate dataSpace(H5S_SIMPLE);
if (dataSpace.id() < 0)
throw WriteSimpleDataException("Couldn't create data space");
H5Sset_extent_simple(dataSpace.id(), 1, totalSize, NULL);
H5ScopedDcreate dataSet(location, name.c_str(), type, dataSpace.id(),
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if (dataSet.id() < 0)
throw WriteSimpleDataException("Couldn't create data set");
hid_t err = H5Dwrite(dataSet.id(), type, H5S_ALL, H5S_ALL,
H5P_DEFAULT, &data[0]);
if (err < 0)
throw WriteSimpleDataException("Couldn't write data");
}
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
FieldTraits::dataDims
static int dataDims()
Definition Traits.h:178
Hdf5Util::H5ScopedDcreate
Scoped object - creates a dataset on creation and closes it on destruction.
Definition Hdf5Util.h:264
Hdf5Util::H5ScopedScreate
Scoped object - creates a dataspace on creation and closes it on destruction.
Definition Hdf5Util.h:235
Exc
Namespace for Exception objects.
Definition Exception.h:57
DataTypeTraits::h5type
static hid_t h5type()

References FieldTraits< Data_T >::dataDims(), g_hdf5Mutex, DataTypeTraits< T >::h5type(), and Hdf5Util::H5Base::id().

## readSimpleData()

template<typename T>

void Hdf5Util::readSimpleData | ( | hid_t | location,
|  | const std::string & | name,
|  | std::vector< T > & | data )

Reads a simple linear data set from the given location.

Definition at line 611 of file Hdf5Util.h.

{
using namespace Exc;
GlobalLock lock(g_hdf5Mutex);
int components = FieldTraits<T>::dataDims();
hsize_t dims[1];
H5ScopedDopen dataSet(location, name.c_str(), H5P_DEFAULT);
if (dataSet.id() < 0)
throw OpenDataSetException("Couldn't open data set: " + name);
H5ScopedDget_space dataSpace(dataSet.id());
H5ScopedDget_type dataType(dataSet.id());
H5Sget_simple_extent_dims(dataSpace.id(), dims, NULL);
if (dataSpace.id() < 0)
throw GetDataSpaceException("Couldn't get data space");
if (dataType.id() < 0)
throw GetDataTypeException("Couldn't get data type");
int reportedSize = dims[0] / components;
// Resize target
data.clear();
data.resize(reportedSize);
// Get the internal data type
hid_t type = DataTypeTraits<T>::h5type();
if (H5Dread(dataSet.id(), type, H5S_ALL, H5S_ALL,
H5P_DEFAULT, &data[0]) < 0) {
throw Hdf5DataReadException("Couldn't read simple data");
}
}
Hdf5Util::H5ScopedDget_space
Scoped object - opens a dataset on creation and closes it on destruction.
Definition Hdf5Util.h:387
Hdf5Util::H5ScopedDget_type
Scoped object - opens a dataset on creation and closes it on destruction.
Definition Hdf5Util.h:417
Hdf5Util::H5ScopedDopen
Scoped object - opens a dataset on creation and closes it on destruction.
Definition Hdf5Util.h:357

References FieldTraits< Data_T >::dataDims(), g_hdf5Mutex, DataTypeTraits< T >::h5type(), and Hdf5Util::H5Base::id().

## readAttribute() [1/7]

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

Reads a string attribute.

References FIELD3D_API.

Referenced by Field3DInputFileHDF5::open(), Field3DInputFileHDF5::parseLayer(), InputFileHDF5::parseLayers(), FrustumFieldMappingIO::read(), MatrixFieldMappingIO::read(), NullFieldMappingIO::read(), readFieldMapping(), Field3DInputFileHDF5::readGroupMembership(), Field3DInputFileHDF5::readLayer(), Field3DInputFileHDF5::readMetadata(), Field3DInputFileHDF5::readMetadata(), Field3DInputFileHDF5::readProxyLayer(), and Field3DInputFileHDF5::readProxyLayer().

## readAttribute() [2/7]

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

Reads an int attribute of arbitrary size.

References FIELD3D_API.

## readAttribute() [3/7]

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

Reads a float attribute of arbitrary size.

References FIELD3D_API.

## readAttribute() [4/7]

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

Reads a double attribute of arbitrary size.

References FIELD3D_API.

## readAttribute() [5/7]

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

Reads a int attribute of arbitrary size and rank.

References FIELD3D_API.

## readAttribute() [6/7]

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

Reads a float attribute of arbitrary size and rank.

References FIELD3D_API.

## readAttribute() [7/7]

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

Reads a double attribute of arbitrary size and rank.

References FIELD3D_API.

## writeAttribute() [1/7]

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

Writes a string attribute.

References FIELD3D_API.

Referenced by Field3DOutputFileHDF5::create(), Field3DOutputFileHDF5::createNewPartition(), FrustumFieldMappingIO::write(), MatrixFieldMappingIO::write(), NullFieldMappingIO::write(), writeField(), writeFieldMapping(), Field3DOutputFile::writeGroupMembership(), Field3DOutputFileHDF5::writeGroupMembership(), Field3DOutputFileHDF5::writeLayer(), Field3DOutputFileHDF5::writeMetadata(), and Field3DOutputFileHDF5::writeMetadata().

## writeAttribute() [2/7]

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

Writes an int attribute of arbitrary size.

References FIELD3D_API.

## writeAttribute() [3/7]

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

Writes a float attribute of arbitrary size.

References FIELD3D_API.

## writeAttribute() [4/7]

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

Writes a double attribute of arbitrary size.

References FIELD3D_API.

## writeAttribute() [5/7]

FIELD3D_API bool Hdf5Util::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.

References FIELD3D_API.

## writeAttribute() [6/7]

FIELD3D_API bool Hdf5Util::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.

References FIELD3D_API.

## writeAttribute() [7/7]

FIELD3D_API bool Hdf5Util::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.

References FIELD3D_API.

## checkHdf5Gzip()

bool Hdf5Util::checkHdf5Gzip | ( |  | ) |

Checks whether gzip is available in the current hdf5 library.

Definition at line 722 of file Hdf5Util.cpp.

{
GlobalLock lock(g_hdf5Mutex);
htri_t avail = H5Zfilter_avail(H5Z_FILTER_DEFLATE);
if (!avail)
return false;
unsigned int filter_info;
herr_t status = H5Zget_filter_info (H5Z_FILTER_DEFLATE, &filter_info);
if (status < 0)
return false;
if (!(filter_info & H5Z_FILTER_CONFIG_ENCODE_ENABLED) ||
!(filter_info & H5Z_FILTER_CONFIG_DECODE_ENABLED)) {
return false;
}
return true;
}

References g_hdf5Mutex.