To introduce the programming model, examples in Python and C are included below. The Python examples use 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. See the Examples from "Learning the Basics" page for complete examples that can be downloaded and run for C, FORTRAN, C++, Java and Python.
The general paradigm for working with objects in HDF5 is to:
Following are examples to create a file file.h5 using Python , and C, and FORTRAN.
Calling h5py.File with ‘w’ for the file access flag will create a new HDF5 file and overwrite an existing file with the same name. “file” is the file handle returned from opening the file. When finished with the file, it must be closed. When not specifying property lists, the default property lists are used:
The code excerpts below show the calls that need to be made to create a 4 x 6 integer dataset “dset”
dset in a file “dset
With Python, the creation of the dataspace is included as a parameter in the dataset creation method. Just one call will create a 4 x 6 integer dataset “dset”
dset. A pre-defined Big Endian 32-bit integer datatype is specified. The create_dataset method creates the dataset in the root group (the file object). The dataset is close by the Python interface.