Skip to content

geospace-code/h5fortran

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Build status

Object-oriented Fortran 2018 HDF5 interface

Straightforward single-file/module access to HDF5. Abstracts away the messy parts of HDF5 so that you can read/write various types/ranks of data with a single command.

Polymorphic API with read/write integer / real32/64:

  • scalar
  • 1-D .. 6-D

as well as character (string) variables and attributes. If you'd like higher-rank arrays, let us know via GitHub Issue.

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:

Build this HDF5 OO Fortran interface:

cd app
cmake ../src
make

make test

The library libh5oo is built, link it into your program as usual.

Usage

All examples assume:

use hdf5_interface, only: hdf5_file
type(hdf5_file) :: h5f
  • gzip compression may be applied for rank >= 2 arrays by setting comp_lvl to a value betwen 1 and 9. Shuffle filter is automatically applied for better compression
  • string attributes may be applied to any variable at time of writing or later.
  • chunk_size option may be set for better compression

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()

Add gzip compressed 3-D array "value2" to existing HDF5 file "test.h5"

real :: val2(1000,1000,3) = 0.

call h5f%initialize('test.h5', comp_lvl=1)

call h5f%add('/value2', val2)

call h5f%finalize()

chunk_size may optionally be set in the %add() method.

Notes

The first character of the filename should be a character, NOT whitespace to avoid file open/creation errors.