Page tree

With HDF5 there are a number of steps required to create a dataset or attribute. The HDF5 Lite interface condenses these steps into a single call.

Even with the High Level APIs, the more general HDF5 create and close functions may or will still need to be used. In particular, please refer to the introductory tutorial topic on creating a file. You may also want to review the topic on creating a dataset.

Covered here are the different HDF5 Lite calls available for writing to and reading from Datasets and Attributes.

 

 

Writing a Dataset

To create and write a dataset, use the general function H5LTmake_dataset:

  H5LTmake_dataset (file_id, dset_name, rank, dims, H5T_NATIVE_INT, data);

This function accepts a parameter file_id, obtained from the basic HDF5 library function, H5Fcreate, a dataset name, the number of dimensions in the dataset, an array containing the dimensions, the HDF5 datatype (H5T_NATIVE_INT) for the data, and the data.

PROGRAMMING EXAMPLE

The following example demonstrates how to create and write a dataset using the HDF5 Lite function H5LTmake_dataset.

C Example

There are other Lite functions that allow the writing of a dataset. These functions are type specific; there is one of them for each of the most common HDF5 datatypes. These functions are listed below. For example, to write an integer array of data, use the H5LTmake_dataset_int function:

  H5LTmake_dataset_int (file_id, DSET3_NAME, rank, dims, data_int_in);

The parameters of this function are similar to H5LTmake_dataset, except that it does not include the parameter for the datatype.The common types that have specific make functions are the following predefined native datatypes:

C language type FunctionHDF5 type
stringH5LTmake_dataset_stringH5T_C_S1
charH5LTmake_dataset_charH5T_NATIVE_CHAR
shortH5LTmake_dataset_shortH5T_NATIVE_SHORT
intH5LTmake_dataset_intH5T_NATIVE_INT
longH5LTmake_dataset_longH5T_NATIVE_LONG
floatH5LTmake_dataset_floatH5T_NATIVE_FLOAT
doubleH5LTmake_dataset_doubleH5T_NATIVE_DOUBLE

Reading a Dataset

To read back the data there are the opposite functions: a generic read function that accepts an HDF5 type parameter,  

   H5LTread_dataset (file_id, dset_name, H5T_NATIVE_INT, data);

and the more specific functions for the more common types. The following call achieves the same results as the above call:

   H5LTread_dataset_int (file_id, dset_name, data);

In the case of the read functions, obtain the HDF5 file identifier from the basic library function, H5Fopen.

PROGRAMMING EXAMPLE

The following example demonstrates how to read a dataset using the HDF5 Lite function H5LTread_dataset_int:

C Example

Similar to the make dataset functions, the common types that have specific read functions are the following:

C language type FunctionHDF5 type
stringH5LTread_dataset_stringH5T_C_S1
charH5LTread_dataset_charH5T_NATIVE_CHAR
shortH5LTread_dataset_shortH5T_NATIVE_SHORT
intH5LTread_dataset_intH5T_NATIVE_INT
longH5LTread_dataset_longH5T_NATIVE_LONG
floatH5LTread_dataset_floatH5T_NATIVE_FLOAT
doubleH5LTread_dataset_doubleH5T_NATIVE_DOUBLE

 

 

 

Writing an Attribute

Similar to the Lite write dataset functions, there are several Lite write attribute functions, one for each HDF5 datatype. For example, to write an integer attribute, the function H5LTset_attribute_int is used. The use of this function is:

   H5LTset_attribute_int (file_id, dset_name, attr_name, data, size);

This function accepts a parameter, file_id, obtained from the basic HDF5 library function H5Fcreate or H5Fopen, the object (dataset or group) name in which we want to create the attribute, the data and its array size.

Reading Attributes

To read an attribute, the steps are similar, except they are read functions:

   H5LTget_attribute_int (file_id, dset_name, attr_name, data);

PROGRAMMING EXAMPLE

The following example demonstrates how to write and read an attribute using the HDF5 Lite functions H5LTset_attribute_int and H5LTget_attribute_int.

C Example

The more common Lite functions that allow the creating of attributes are listed below. These functions are type specific; there is one for each of the most common HDF5 datatypes. There are similar functions for reading.

C language type FunctionHDF5 type
stringH5LTset_attribute_stringH5T_C_S1
charH5LTset_attribute_charH5T_NATIVE_CHAR
shortH5LTset_attribute_shortH5T_NATIVE_SHORT
intH5LTset_attribute_intH5T_NATIVE_INT
longH5LTset_attribute_longH5T_NATIVE_LONG
floatH5LTset_attribute_floatH5T_NATIVE_FLOAT
doubleH5LTset_attribute_doubleH5T_NATIVE_DOUBLE

 

 

--- Last Modified: October 22, 2020 | 01:23 PM