The HDF5 Application Programming Interface is extensive, but a few functions do most of the work.
To To introduce the programming model, examples in Python and C are included below. The HDF5 Python APIs (h5py) are included for their simplicity of use. However, they were not created and are not maintained by The HDF Group.
The general paradigm for working with objects in HDF5 is to:
- Open the object.
- Access the object.
- Close the object.
The library imposes an order on the operations by argument dependencies. For example, a file must be opened before a dataset because the dataset open call requires a file handle as an argument. Objects can be closed in any order. However, once an object is closed it no longer can be accessed.
- C routines begin with the prefix “H5“
H5*” where * is a single letter indicating the object on which the operation is to be performed. FORTRAN routines are similar; they begin with “h5“
h5*” and end with “
f”. For example:
H5Fopen (C) and
H5Dopen (C) and h5fdopen
H5Sclose (C) and
The HDF5 Python APIs use methods associated with specific objects.
- For portability, the HDF5 library has its own defined types. Some common types that you will see in the example code are:
hid_t is used for object handles
hsize_t is used for dimensions
herr_tis used for many return values
- Language specific files must be included in applications:
import h5py” / “
USE HDF5" and call
h5close_f to initialize and close the HDF5 FORTRAN interface
Steps to create a file:
To create an HDF5 file you must: