hdf images hdf images

This web site is no longer maintained (but will remain online).
Please see The HDF Group's new Support Portal for the latest information.

HDF5 Tutorial:   Learning The Basics
Discovering the Contents of an HDF5 File

Contents:


Discovering what is in an HDF5 file

Until now, three ways have been mentioned that can be used to read an existing HDF5 file:

HDFView and h5dump are standalone tools which cannot be called within an application, and using H5Dopen and H5Dread require that you know the name of the HDF5 dataset. How would an application that has no prior knowledge of an HDF5 file, be able to determine or discover the contents of it, much like HDFView and h5dump?

The answer is that there are ways to discover the contents of an HDF5 file, by using the H5G, H5L and H5O APIs:

Using just the H5G interface, you can drill your way down, starting from the root group, opening groups and objects until you reach all objects. Functions that enable this are:

There are also specific H5O and H5L interface routines that simplify the process:

Programming Examples

Using H5Literate, H5Lvisit and H5Ovisit:

Under HDF5 Examples you will find Examples by API, where examples of using H5Literate and H5Ovisit/H5Lvisit are included.

The h5ex_g_traverse example traverses a file using H5Literate:

The h5ex_g_visit example traverses a file using H5Ovisit and H5Lvisit:

Using the H5G API:

To use the H5G interface exclusively you would begin with the root group, open it, get the number of objects (NumObj) in the group (see H5Gget_num_objs), and then loop through all of the objects in the group (from 0 to (NumObj - 1)), accessing each by index (see H5Gget_objname_by_idx and H5Gget_objtype_by_idx). If an object is another group, you would then open that group and repeat the process until all objects have been accessed.

The example below gives an idea of what could be done. Simply pass in the name of the HDF5 file as a parameter to this program:


- - Last modified: 21 December 2016