Creating Compound DatatypesA compound datatype is similar to a struct in C or a common block in FORTRAN. It is a collection of one or more datatypes and can include compound datatypes. To create and use a compound datatype you need to be familiar with various properties of the compound datatype:
- It is of class compound.
- It has a fixed total size, in bytes.
- It consists of one or more members (defined in any order) with unique names and occupying non-overlapping regions within the datum.
- Each member has its own datatype.
- Each member is referenced by an index number between zero and N-1, where N is the number of members in the compound datatype.
- Each member has a name which is unique among its siblings in a compound datatype.
- Each member has a fixed byte offset, which locates the first byte (smallest byte address) of that member in the compound datatype.
- Each member can be a small array of up to four dimensions.
High Level APIsThe High Level HDF5 Table APIs (H5TB) include functions to easily create tables in HDF5, using a compound datatype. Please be sure to review them, in addition to this tutorial.
DescriptionThis example shows how to create a dataset with a compound datatype, write data to it, and then read data back.
- H5Tcreate / h5tcreate_f creates a new datatype of the specified class with the specified number of bytes. To create a compound datatype, H5T_COMPOUND is specified for the class.
H5Tinsert / h5tinsert_f adds a member to the compound datatype specified by the datatype identifier.
The library defines the HOFFSET macro that can be used to compute the offset of a member within a struct:
HOFFSET ( s, m )This macro computes the offset of member m within a struct variable s.
H5Tclose / h5tclose_f releases a datatype.
- - Last modified: 21 December 2016