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

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

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

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

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 530 of file Hdf5Util.h.

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

532 {
533  using namespace Exc;
534 
535  // Calculate the total number of entries. This factors in that
536  // V3f uses 3 components per value, etc.
537  hsize_t totalSize[1];
538  int components = FieldTraits<T>::dataDims();
539  totalSize[0] = data.size() * components;
540 
541  // Get the internal data type
542  hid_t type = DataTypeTraits<T>::h5type();
543 
544  H5ScopedScreate dataSpace(H5S_SIMPLE);
545 
546  if (dataSpace.id() < 0)
547  throw WriteSimpleDataException("Couldn't create data space");
548 
549  H5Sset_extent_simple(dataSpace.id(), 1, totalSize, NULL);
550 
551  H5ScopedDcreate dataSet(location, name.c_str(), type, dataSpace.id(),
552  H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
553 
554  if (dataSet.id() < 0)
555  throw WriteSimpleDataException("Couldn't create data set");
556 
557  hid_t err = H5Dwrite(dataSet.id(), type, H5S_ALL, H5S_ALL,
558  H5P_DEFAULT, &data[0]);
559 
560  if (err < 0)
561  throw WriteSimpleDataException("Couldn't write data");
562 }
static int dataDims()
Dimensions of the given data type. i.e. 3 for V3f, 1 for float.
Namespace for Exception objects.
Definition: Exception.h:57
static hid_t h5type()
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 567 of file Hdf5Util.h.

References FieldTraits< Data_T >::dataDims(), and DataTypeTraits< T >::h5type().

569 {
570  using namespace Exc;
571 
572  int components = FieldTraits<T>::dataDims();
573  hsize_t dims[1];
574 
575  H5ScopedDopen dataSet(location, name.c_str(), H5P_DEFAULT);
576 
577  if (dataSet.id() < 0)
578  throw OpenDataSetException("Couldn't open data set: " + name);
579 
580  H5ScopedDget_space dataSpace(dataSet.id());
581  H5ScopedDget_type dataType(dataSet.id());
582  H5Sget_simple_extent_dims(dataSpace.id(), dims, NULL);
583 
584  if (dataSpace.id() < 0)
585  throw GetDataSpaceException("Couldn't get data space");
586 
587  if (dataType.id() < 0)
588  throw GetDataTypeException("Couldn't get data type");
589 
590  int reportedSize = dims[0] / components;
591 
592  // Resize target
593  data.clear();
594  data.resize(reportedSize);
595 
596  // Get the internal data type
597  hid_t type = DataTypeTraits<T>::h5type();
598 
599  if (H5Dread(dataSet.id(), type, H5S_ALL, H5S_ALL,
600  H5P_DEFAULT, &data[0]) < 0) {
601  throw Hdf5DataReadException("Couldn't read simple data");
602  }
603 }
static int dataDims()
Dimensions of the given data type. i.e. 3 for V3f, 1 for float.
Namespace for Exception objects.
Definition: Exception.h:57
static hid_t h5type()
bool Hdf5Util::readAttribute ( hid_t  location,
const std::string &  attrName,
unsigned int  attrSize,
int &  value 
)

Reads an int attribute of arbitrary size.

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

Reads a float attribute of arbitrary size.

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

Reads a double attribute of arbitrary size.

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.

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.

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.

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

Writes an int attribute of arbitrary size.

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

Writes a float attribute of arbitrary size.

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

Writes a double attribute of arbitrary size.

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.

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.

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.

bool Hdf5Util::checkHdf5Gzip ( )

Checks whether gzip is available in the current hdf5 library.

Definition at line 680 of file Hdf5Util.cpp.

Referenced by MACFieldIO::writeData(), DenseFieldIO::writeInternal(), and SparseFieldIO::writeInternal().

681 {
682  htri_t avail = H5Zfilter_avail(H5Z_FILTER_DEFLATE);
683  if (!avail)
684  return false;
685 
686  unsigned int filter_info;
687  herr_t status = H5Zget_filter_info (H5Z_FILTER_DEFLATE, &filter_info);
688 
689  if (status < 0)
690  return false;
691 
692  if (!(filter_info & H5Z_FILTER_CONFIG_ENCODE_ENABLED) ||
693  !(filter_info & H5Z_FILTER_CONFIG_DECODE_ENABLED)) {
694  return false;
695  }
696 
697  return true;
698 }