Field3D

Namespaces

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

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

Attribute reading

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

Attribute writing

FIELD3D_API bool Hdf5Util::writeAttribute (hid_t location, const std::string &attrName, const std::string &value)
 Writes a string attribute. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

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.

574 {
575  using namespace Exc;
576 
577  GlobalLock lock(g_hdf5Mutex);
578 
579  // Calculate the total number of entries. This factors in that
580  // V3f uses 3 components per value, etc.
581  hsize_t totalSize[1];
582  int components = FieldTraits<T>::dataDims();
583  totalSize[0] = data.size() * components;
584 
585  // Get the internal data type
586  hid_t type = DataTypeTraits<T>::h5type();
587 
588  H5ScopedScreate dataSpace(H5S_SIMPLE);
589 
590  if (dataSpace.id() < 0)
591  throw WriteSimpleDataException("Couldn't create data space");
592 
593  H5Sset_extent_simple(dataSpace.id(), 1, totalSize, NULL);
594 
595  H5ScopedDcreate dataSet(location, name.c_str(), type, dataSpace.id(),
596  H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
597 
598  if (dataSet.id() < 0)
599  throw WriteSimpleDataException("Couldn't create data set");
600 
601  hid_t err = H5Dwrite(dataSet.id(), type, H5S_ALL, H5S_ALL,
602  H5P_DEFAULT, &data[0]);
603 
604  if (err < 0)
605  throw WriteSimpleDataException("Couldn't write data");
606 }

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.

613 {
614  using namespace Exc;
615 
616  GlobalLock lock(g_hdf5Mutex);
617 
618  int components = FieldTraits<T>::dataDims();
619  hsize_t dims[1];
620 
621  H5ScopedDopen dataSet(location, name.c_str(), H5P_DEFAULT);
622 
623  if (dataSet.id() < 0)
624  throw OpenDataSetException("Couldn't open data set: " + name);
625 
626  H5ScopedDget_space dataSpace(dataSet.id());
627  H5ScopedDget_type dataType(dataSet.id());
628  H5Sget_simple_extent_dims(dataSpace.id(), dims, NULL);
629 
630  if (dataSpace.id() < 0)
631  throw GetDataSpaceException("Couldn't get data space");
632 
633  if (dataType.id() < 0)
634  throw GetDataTypeException("Couldn't get data type");
635 
636  int reportedSize = dims[0] / components;
637 
638  // Resize target
639  data.clear();
640  data.resize(reportedSize);
641 
642  // Get the internal data type
643  hid_t type = DataTypeTraits<T>::h5type();
644 
645  if (H5Dread(dataSet.id(), type, H5S_ALL, H5S_ALL,
646  H5P_DEFAULT, &data[0]) < 0) {
647  throw Hdf5DataReadException("Couldn't read simple data");
648  }
649 }

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

◆ readAttribute() [1/7]

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

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

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

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

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

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

◆ writeAttribute() [1/7]

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

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

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

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

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

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

◆ checkHdf5Gzip()

bool Hdf5Util::checkHdf5Gzip ( )

Checks whether gzip is available in the current hdf5 library.

Definition at line 722 of file Hdf5Util.cpp.

723 {
724  GlobalLock lock(g_hdf5Mutex);
725 
726  htri_t avail = H5Zfilter_avail(H5Z_FILTER_DEFLATE);
727  if (!avail)
728  return false;
729 
730  unsigned int filter_info;
731  herr_t status = H5Zget_filter_info (H5Z_FILTER_DEFLATE, &filter_info);
732 
733  if (status < 0)
734  return false;
735 
736  if (!(filter_info & H5Z_FILTER_CONFIG_ENCODE_ENABLED) ||
737  !(filter_info & H5Z_FILTER_CONFIG_DECODE_ENABLED)) {
738  return false;
739  }
740 
741  return true;
742 }

References g_hdf5Mutex.

DataTypeTraits::h5type
static hid_t h5type()
g_hdf5Mutex
boost::recursive_mutex g_hdf5Mutex
Definition: Hdf5Util.cpp:67
g_hdf5Mutex
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
Definition: Hdf5Util.cpp:67
Exc
Namespace for Exception objects.
Definition: Exception.h:57
GlobalLock
boost::recursive_mutex::scoped_lock GlobalLock
Definition: Hdf5Util.h:78
FieldTraits::dataDims
static int dataDims()
Definition: Traits.h:178