On using hdf5 command line tools

[back]


h5ls

Prints information about a file or dataset.

h5ls <fname.h5>

h5dump

Displays HDF5 file contents.

It’s helpful to inspect the headers of a HDF5 file first. This can be done using the --header flag:

h5dump --header <fname.h5>

Suppose this gives you something like follows:

HDF5 "<fname.h5>" {
GROUP "/" {
   ATTRIBUTE "time" {
      DATATYPE  H5T_IEEE_F64LE
      DATASPACE  SCALAR
   }
   DATASET "darcy_velocity.cell.0" {
      DATATYPE  H5T_IEEE_F64LE
      DATASPACE  SIMPLE { ( 894740, 1 ) / ( 894740, 1 ) }
   }
   DATASET "darcy_velocity.cell.1" {
      DATATYPE  H5T_IEEE_F64LE
      DATASPACE  SIMPLE { ( 894740, 1 ) / ( 894740, 1 ) }
   }
   DATASET "darcy_velocity.cell.2" {
      DATATYPE  H5T_IEEE_F64LE
      DATASPACE  SIMPLE { ( 894740, 1 ) / ( 894740, 1 ) }
   }
}

To display an attribute (such as time), we use the flag -a:

h5dump -a /time <fname.h5>

This gives:

HDF5 "<fname.h5>" {
ATTRIBUTE "time" {
   DATATYPE  H5T_IEEE_F64LE
   DATASPACE  SCALAR
   DATA {
   (0): 4.7952e+07
   }
}
}

Datasets can be displayed with the -d flag:

h5dump -d /darcy_velocity.cell.0 <fname.h5>

This will return something like:

DATASET "/darcy_velocity.cell.0" {
   DATATYPE  H5T_IEEE_F64LE
   DATASPACE  SIMPLE { ( 894740, 1 ) / ( 894740, 1 ) }
   DATA {
   (0,0): 7.05594e-08,
   (1,0): 4.07452e-09,
   (2,0): 1.41819e-09,
   (3,0): 1.10755e-09,
   (4,0): 1.01312e-09,
   (5,0): 9.20153e-10,
...

We can use the --start and --count flags to look at a slice of the data. For example, to print the first 3 entries of a dataset:

h5dump -d /darcy_velocity.cell.0 --start="1,0" --count="3,1" <fname.h5>

Gives:

HDF5 "<fname.h5>" {
DATASET "/darcy_velocity.cell.0" {
   DATATYPE  H5T_IEEE_F64LE
   DATASPACE  SIMPLE { ( 894740, 1 ) / ( 894740, 1 ) }
   SUBSET {
      START ( 1, 0 );
      STRIDE ( 1, 1 );
      COUNT ( 3, 1 );
      BLOCK ( 1, 1 );
      DATA {
      (1,0): 4.07452e-09,
      (2,0): 1.41819e-09,
      (3,0): 1.10755e-09
      }
   }
}
}

See also the {man page} of h5dump.

On NERSC

On NERSC, {HDF5 Tools} can be loaded by:

module load cray-hdf5