Similarly 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 we use the unction H5LTset_attribute_int.
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 with 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.
To read an attribute, the steps are similar, instead we use the read functions. To read the previously written attribute we use
H5LTget_attribute_int( file_id, dset_name, attr_name, data);
The following example demonstrates how to write and read an attribute using
the HDF5 Lite functions H5LTset_attributer_int
and
H5LTget_attributer_int
. The corresponding HDF5
file that is generated is also referenced here. You can use an HDF5 file browser
to access this file by clicking on the link below.
ex_lite3.c
ex_lite3.h5
NOTE: To download a tar file of all of the examples, including a Makefile, please go to the Index page.
The other Lite functions that allow the writing of attributes are listed below. These functions are type specific, that is, there is each one of them for the most common HDF5 datatypes. There are similar reading functions.
C language type | Function | HDF5 type |
char |
H5LTset_attribute_string |
H5T_C_S1 |
char |
H5LTset_attribute_char |
H5T_NATIVE_CHAR |
short |
H5LTset_attribute_short |
H5T_NATIVE_SHORT |
int |
H5LTset_attribute_int |
H5T_NATIVE_INT |
long |
H5LTset_attribute_long |
H5T_NATIVE_LONG |
float |
H5LTset_attribute_float |
H5T_NATIVE_FLOAT |
double |
H5LTset_attribute_double |
H5T_NATIVE_DOUBLE |