By: Christian Bustamante
https://cbustamante.co/
This package provides a Fortran wrapper for HDF5 (.h5 files). It provides a simpler interface that allows easy writing and reading of h5 files for double precision and integer arrays of up to six dimensions. On top of the Fortran wrapper, the package provides a Matlab function that simplifies the process of reading entire h5 files. As opposed to having to read variable by variables, this function reads all variables and put them in a Matlab structure.
Using this package requires a Fortran compiler and the HDF5 library.
- Fortran compiler: tested and built with
ifort
version 19.0.5.281 for Linux and Windows. It has also been tested ingfortran
. - HDF5 libraries: tested and built using HDF5 1.10.5, but it has also been used with other library versions.
The following source files are provided with the package:
Lib_Rwhdf5.f90
: Fortran wrapper that defines interfaces for reading and writing h5 files.Lib_Kind.f90
: declares double precision and integer types.exampleh5.f90
: example that illustrates the usage of the package. It writes two arrays intodata.h5
.Makefile
: used to buildexampleh5.f90
. It depends ontree.dep
that specifies the compilation order.Read_HDF5.m
: Matlab function that reads and h5 file.example_readh5.m
: example that illustrates how to use the functionRead_HDF5.m
to readdata.h5
.
After having the HDF5 library installed, load the two provided Fortran modules into your program.
use lib_kind
use lib_rwhdf5
implicit none
The Fortran wrapper provides four major subroutines and one integer type:
- Subroutines
hdf5_openf
andhdf5_closef
are used to open and close an h5 file. These are only needed when writing into an h5 file (not when reading). - Subroutines
hdf5_read
andhdf5_write
are used to read and write data into an h5 file. The write subroutine should be used after an h5 file has been created withhdf5_openf
. The file should be closed after all variables have been written to it. - Integer type
hid_t
: needed to "label" an h5 file when opened.
Finally, note that the Makefile
specifies the HDF5_PATH
variable that needs to be adjusted depending on where the include
and lib
folders of the HDF5 library have been installed.
MIT license.