[ HDF5 High Level Tutorial Top ] [ Next ] [ Prev ]

H5LT: HDF5 Lite
Dataset functions

Writing a dataset

To create and write a dataset we can use the general function H5LTmake_dataset. The use of this function is 

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

This function accepts a parameter file_id, obtained with 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. 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.

NOTE: To download a tar file of all of the examples, including a Makefile, please go to the Index page.

There are other Lite functions that allow the writing of a dataset. These functions are type specific, that is, there is each one of them for the most common HDF5 datatypes. These functions are listed below. For example, if we want to write an integer array of data, we can 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 have the parameter for the datatype.The common types that have specific make functions are the following predefined native datatypes

C language type  Function HDF5 type
char H5LTmake_dataset_char H5T_NATIVE_CHAR
short H5LTmake_dataset_short H5T_NATIVE_SHORT
int H5LTmake_dataset_int H5T_NATIVE_INT
long H5LTmake_dataset_long H5T_NATIVE_LONG
float H5LTmake_dataset_float H5T_NATIVE_FLOAT
double H5LTmake_dataset_double H5T_NATIVE_DOUBLE

Reading a dataset

To read back the data there are the opposite functions: a generic read function that accepts a 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, we must obtain the HDF5 file identifier with the basic library function H5Fopen.

Programming Example

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

Similarly to the make dataset functions, the common types that have specific read functions are the following predefined native datatypes
C language type  Function HDF5 type
char H5LTread_dataset_char H5T_NATIVE_CHAR
short H5LTread_dataset_short H5T_NATIVE_SHORT
int H5LTread_dataset_int H5T_NATIVE_INT
long H5LTread_dataset_long H5T_NATIVE_LONG
float H5LTread_dataset_float H5T_NATIVE_FLOAT
double H5LTread_dataset_double H5T_NATIVE_DOUBLE

 


HDF Help Desk
Last modified: November 18, 2002