HdfUtilities Namespace Reference

A collection of generic utilities provided to simplify use of the application's HDF API. More...


Classes

class  Hdf4FileObject
 The Hdf4FileObject is a trait object for use with the Resource template. More...
class  Hdf4FileResource
 This is a Resource class that opens and closes HDF4 files. More...
class  Hdf4DatasetObject
 This is an implementation detail of the Hdf4DatasetObject class. More...
class  Hdf4DatasetResource
 This is a Resource class that opens and closes HDF4 datasets. More...
class  Exception
 An HdfUtilitiesException is a simple exception that wraps a string. More...

Functions

template<typename T>
bool getAttribute (const Hdf4Element &element, const std::string &attributeName, T &actualValue)
std::string hdf4TypeToString (long type, size_t count)
bool readHdf4Attribute (int32 obj_id, int32 attr_index, DataVariant &var)
std::string hdf5TypeToTypeString (hid_t dataTypeId)
bool readHdf5Attribute (hid_t attrId, DataVariant &var)
std::string hdf5AttributeToString (hid_t attrId)
template<typename T>
bool writeAttribute (hid_t dataDescriptor, const std::string &attributeName, const T &attributeValue)
template<typename T>
bool writeDataset (hid_t fileDescriptor, const std::string &datasetName, const T &datasetValue)
template<typename T>
Hdf5TypeResource getHdf5Type ()
bool createGroups (const std::string &hdfPath, hid_t fileDescriptor, bool bLastItemIsGroup=false)
unsigned int getDataSize (EncodingType dataType)
std::vector< double > createWavelengthVector (void *pData, size_t numElements, EncodingType type)

Variables

static const std::string UNKNOWN_INTEGER_TYPE = "Unknown HDF5 Integer Type"
static const std::string UNKNOWN_FLOAT_TYPE = "Unknown HDF5 Float Type"
static const std::string TIME_TYPE = "HDF5 Time Type"
static const std::string ARRAY_TYPE = "HDF5 Array Type"
static const std::string BITFIELD_TYPE = "HDF5 Bitfield Type"
static const std::string OPAQUE_TYPE = "HDF5 Opaque Type"
static const std::string COMPOUND_TYPE = "HDF5 Compound Type"
static const std::string REFERENCE_TYPE = "HDF5 Reference Type"
static const std::string ENUM_TYPE = "HDF5 ENUM Type"
static const std::string VLEN_TYPE = "HDF5 VLEN Type"
static const std::string UNKNOWN_TYPE = "Unknown"


Detailed Description

A collection of generic utilities provided to simplify use of the application's HDF API.

Function Documentation

bool HdfUtilities::createGroups ( const std::string &  hdfPath,
hid_t  fileDescriptor,
bool  bLastItemIsGroup = false 
)

Creates one or more HDF5 groups with the given names.

Parameters:
hdfPath One or more group names, separated by a '/' character, to be created.
fileDescriptor A handle to the HDF5 file that the group(s) should be created in.
bLastItemIsGroup True if the last item in the string is a group, false otherwise. If this is false, the text after the final '/' in hdfPath is ignored.
Returns:
Returns true if the group(s) were created (or already existed) at the given location(s), false otherwise.

std::vector<double> HdfUtilities::createWavelengthVector ( void *  pData,
size_t  numElements,
EncodingType  type 
)

Takes a void pointer and produces a wavelength vector.

WARNING: This function cannot provide range checking! If passed invalid values, this method throws an HdfUtilities::Exception.

Parameters:
pData A pointer to memory (most frequently read in using HdfImporter::loadDatasetFromFile()) that represents the wavelength vector.
numElements The number of elements in the vector.
type The data type of the wavelength vector. Valid values are INT1SBYTE, INT1UBYTE, INT2SBYTES, INT2UBYTES, INT4SBYTES, INT4UBYTES, INT4SCOMPLEX, FLT4BYTES, FLT8BYTES. If an invalid value is passed in for this argument (ie. UNKNOWN or INT4SCOMPLEX), an HdfUtilities::Exception is thrown.
Returns:
Returns a vector containing the wavelength data.

template<typename T>
bool HdfUtilities::getAttribute ( const Hdf4Element element,
const std::string &  attributeName,
T &  actualValue 
)

Reads an attribute from an Hdf4Element based on the attribute name.

Example usage:

 // assume pElement is a pDataset is a valid, non-NULL Hdf4Dataset
 unsigned short badValue;
 if (HdfUtilities::getAttribute(*pDataset, "_FillValue", badValue) == false)
 {
    // error condition
 }
 // use _FillValue here

Parameters:
element The Hdf4Element from which to read the attribute.
attributeName The name of the attribute to read in.
actualValue Contains the actual value contained in the attribute.
Returns:
TRUE if the attribute was found and contained valid data, FALSE otherwise.

Definition at line 52 of file Hdf4Utilities.h.

unsigned int HdfUtilities::getDataSize ( EncodingType  dataType  ) 

Returns the size of each data element given an EncodingType.

Throws an HdfUtilities::Exception() if an invalid data type is encountered.

Parameters:
dataType An EncodingType that represents the data. Never returns 0.
Returns:
The size of the data type passed in. Returns 0 if the type is unknown or unsupported.

template<typename T>
Hdf5TypeResource HdfUtilities::getHdf5Type (  ) 

std::string HdfUtilities::hdf4TypeToString ( long  type,
size_t  count 
)

Converts an HDF4 type to a string that can be used to create an Hdf4Attribute.

Parameters:
type The HDF4 type (ie. DFNT_CHAR).
count The number of elements whose data type is 'type'.
Returns:
A string that represents the HDF5 type in the same way that DynamicObect::get() expresses types as strings.

std::string HdfUtilities::hdf5AttributeToString ( hid_t  attrId  ) 

Given an HDF5 Attribute handle, returns a string representing that attribute.

This method only supports attributes supported by StringUtilities::toString() and StringUtilities::fromString() minus the enumerated types in TypesFile.h.

Throws an HdfUtilities::Exception if an error occurs.

Parameters:
attrId The attribute id returned by H5Aopen().
Returns:
A string representing the attribute. For 1-dimensional vector types, this returns the list of values: ie. (val1, val2, val3).

std::string HdfUtilities::hdf5TypeToTypeString ( hid_t  dataTypeId  ) 

Converts an HDF5 data type to a string.

This method simply returns a string representation of the type. It does not take the dataspace into account, ie. the dimensionality.

NOTE: You will need to statically link against the HDF5 libraries.

Parameters:
dataTypeId The value returned from H5Dget_type() or H5Aget_type().
Returns:
A string that represents the HDF5 type. The return value could be one of the following:

bool HdfUtilities::readHdf4Attribute ( int32  obj_id,
int32  attr_index,
DataVariant var 
)

Given an open HDF4 Attribute identifier retrieves the attribute and places it in a variant.

Parameters:
obj_id The object identifier that the attribute should be read from.
attr_index The index of the attribute to read.
var The variant that the attribute data will be placed in.
Returns:
True if the attribute could be read, false otherwise.

bool HdfUtilities::readHdf5Attribute ( hid_t  attrId,
DataVariant var 
)

Given an open HDF5 Attribute identifier retrieves the attribute and places it in a variant.

Parameters:
attrId A handle to the HDF attribute.
var The variant that the attribute data will be placed in.
Returns:
The number of elements (ie. 5 if a vector of 5 ints) in the attribute.

template<typename T>
bool HdfUtilities::writeAttribute ( hid_t  dataDescriptor,
const std::string &  attributeName,
const T &  attributeValue 
)

Creates an HDF5 attribute with a given name and value.

Parameters:
dataDescriptor A handle to the HDF5 dataset or HDF5 group that this attribute should be attached to.
attributeName The name of the attribute that should be created on the HDF5 dataset or HDF5 group.
attributeValue The value that the created attribute should have. The value will determine the HDF5 type and HDF5 dataspace of the created attribute. Specifically, the Hdf5CustomWriter created for T will determine both the HDF5 type and HDF5 dataspace.
Returns:
Returns true if the attribute could be created with the given name and value successfully, false otherwise.

Definition at line 166 of file Hdf5Utilities.h.

template<typename T>
bool HdfUtilities::writeDataset ( hid_t  fileDescriptor,
const std::string &  datasetName,
const T &  datasetValue 
)

Creates an HDF5 dataset with a given name and value.

Parameters:
fileDescriptor A handle to the HDF5 file that this dataset should be created in.
datasetName The full path to where the HDF5 dataset should be created in the HDF5 file. This function assumes that any required groups in the path have already been created.
datasetValue The value that the created dataset should have. The value will determine the HDF5 type and HDF5 dataspace of the created dataset. Specifically, the Hdf5CustomWriter created for T will determine both the HDF5 type and HDF5 dataspace.
Returns:
Returns true if the dataset could be created at the given location in the file with the given value successfully, false otherwise.

Definition at line 222 of file Hdf5Utilities.h.


Variable Documentation

const std::string HdfUtilities::ARRAY_TYPE = "HDF5 Array Type" [static]

Represents the H5T_ARRAY type.

The HdfPlugInLib will not parse data of this type.

Definition at line 52 of file Hdf5Utilities.h.

const std::string HdfUtilities::BITFIELD_TYPE = "HDF5 Bitfield Type" [static]

Represents the H5T_BITFIELD type.

The HdfPlugInLib will not parse data of this type.

Definition at line 57 of file Hdf5Utilities.h.

const std::string HdfUtilities::COMPOUND_TYPE = "HDF5 Compound Type" [static]

Represents the H5T_COMPOUND type.

The HdfPlugInLib will not parse data of this type.

Definition at line 67 of file Hdf5Utilities.h.

const std::string HdfUtilities::ENUM_TYPE = "HDF5 ENUM Type" [static]

Represents the H5T_ENUM type.

The HdfPlugInLib will not parse data of this type.

Definition at line 77 of file Hdf5Utilities.h.

const std::string HdfUtilities::OPAQUE_TYPE = "HDF5 Opaque Type" [static]

Represents the H5T_OPAQUE type.

The HdfPlugInLib will not parse data of this type.

Definition at line 62 of file Hdf5Utilities.h.

const std::string HdfUtilities::REFERENCE_TYPE = "HDF5 Reference Type" [static]

Represents the H5T_REFERENCE type.

The HdfPlugInLib will not parse data of this type.

Definition at line 72 of file Hdf5Utilities.h.

const std::string HdfUtilities::TIME_TYPE = "HDF5 Time Type" [static]

Represents the H5T_TIME type.

The HdfPlugInLib will not parse data of this type.

Definition at line 47 of file Hdf5Utilities.h.

const std::string HdfUtilities::UNKNOWN_FLOAT_TYPE = "Unknown HDF5 Float Type" [static]

Represents a version of H5T_FLOAT type that the HdfPlugInLib does not know how to parse.

Definition at line 42 of file Hdf5Utilities.h.

const std::string HdfUtilities::UNKNOWN_INTEGER_TYPE = "Unknown HDF5 Integer Type" [static]

Represents a version of H5T_INTEGER type that the HdfPlugInLib does not know how to parse.

Definition at line 37 of file Hdf5Utilities.h.

const std::string HdfUtilities::UNKNOWN_TYPE = "Unknown" [static]

Represents an unknown type found in the Hdf file.

The HdfPlugInLib will not parse data of this type.

Definition at line 26 of file HdfUtilities.h.

const std::string HdfUtilities::VLEN_TYPE = "HDF5 VLEN Type" [static]

Represents the H5T_VLEN type.

The HdfPlugInLib will not parse data of this type.

Definition at line 82 of file Hdf5Utilities.h.


Software Development Kit - Opticks 4.8.0 Build 15482