This subpage illustrates the basic use of the .h5 hierarchical data format for use with Matlab, Python and C (C++) with command line inputs and links to useful files.

C:

From Power 7 (Beatrice) node:

module load hdf5/1.8.11_serial_adv

loads the C libraries for the .h5 file manipulations.

The following webpage has example C program to create and save data structures:

https://www.hdfgroup.org/HDF5/examples/intro.html

To compile from Beatrice (this creates an empty .h5 file called dset.h5):

gcc -Wall -o h5_crtdat h5_crtdat.c -Wl,-rpath=${HDF5LIB} -lhdf5

and to run it:

./h5_crtdat

To compile h5_rdwt to write an array to the file dset.h5

gcc -Wall -o h5_rdwt h5_rdwt.c -Wl,-rpath=${HDF5LIB} -lhdf5

And to run:

./h5_rdwt

 

Matlab:

To load data from a . h5 file with dataset name 'dset'

dset=h5read('dset.h5','/dset')

To find header information about the .h5 file (eg the datasetname and data type)

fileinfo=hdf5info('dset.h5')

To write an entire dataset:

h5write(FILENAME,DATASETNAME,DATA)

Python:

h5rw.py contains wrappers for .h5 reading and writing in Python. First, import this package:

import h5rw

To read in the .h5 file:

temp=h5rw.h5read('dset.h5')

temp is a dictionary. To see the keys in this dictionary:

temp.keys()

To access the 'dset' entry in the dictionary:

temp['dset']

To write a dictionary to file:

h5rw.h5write('test.h5',temp)

 

 

  • No labels