Object-oriented Fortran 2018 HDF5 interface
March 19, 2018 · View on GitHub
Object-oriented Fortran 2018 HDF5 interface
Very simple single-file/module access to HDF5. More advanced object-oriented Fortran HDF5 access also available, but not compatible with HDF5 1.10 like this program.
Read/write integer / real32/64:
- scalar
- 1-D
- 2-D
- 3-D
via polymorphism.
Tested on systems including Mac OS X (via homebrew), Ubuntu 16.04/18.04 (gfortran ≥ 5.4.1) with HDF5 1.8 and 1.10 and Windows Subsystem for Linux.
Build
Requirements:
-
modern Fortran 2018 compiler (such as gfortran ≥ 5.4.1, etc.)
-
HDF5 library (1.8 or 1.10)
-
Mac:
brew install gcc hdf5 -
Linux:
apt install gfortran libhdf5-dev -
Windows: at this time, Scoop didn't have HDF5, possibly due to difficulties with HDF5 and gfortran on Windows, so consider using Windows Subsystem for Linux
and then:
cd app
cmake ../src
make
make test
Usage
Here are a few examples. All of them assume:
use hdf5_interface, only: hdf5_file
type(hdf5_file) :: h5f
Create new HDF5 file, with variable "value1"
call h5f%initialize('test.h5',status='new',action='w')
call h5f%add('/value1', 123.)
call h5f%finalize()
Add variable "value1" to existing HDF5 file "test.h5"
call h5f%initialize('test.h5',status='old',action='rw')
call h5f%add('/value1', 123.)
call h5f%finalize()