h5fortran

h5fortran: object-oriented polymorphic Fortran interface for HDF5 file IO - Published in JOSS (2021)

https://github.com/geospace-code/h5fortran

Science Score: 98.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: joss.theoj.org, zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

fortran hdf5 object-oriented-fortran
Last synced: 4 months ago · JSON representation ·

Repository

Lightweight HDF5 polymorphic Fortran: h5write() h5read()

Basic Info
Statistics
  • Stars: 110
  • Watchers: 5
  • Forks: 26
  • Open Issues: 2
  • Releases: 152
Topics
fortran hdf5 object-oriented-fortran
Created over 7 years ago · Last pushed 4 months ago
Metadata Files
Readme License Citation Codemeta

README.md

Object-oriented Fortran HDF5 interface

DOI DOI

ci ci_windows ci_build oneapi-linux ci_fpm

Simple, robust, thin HDF5 polymorphic Fortran read/write interface. Reading or writing {real64,real32,int32,int64} from scalar to 7d is as simple as

```fortran use h5fortran

call h5write('my.h5', '/x', x)

call h5read('my.h5', '/y', y) ```

For NetCDF4 see nc4fortran. h5fortran is designed for "serial" HDF5 read/write. h5fortran-mpi is a Fortran interface for "parallel" HDF5.

h5fortran is designed for easy use using static or shared linking from your project via:

Uses Fortran submodule for clean template structure. This easy-to-use, thin object-oriented modern Fortran library abstracts away the messy parts of HDF5 so that you can read / write various types/ranks of data with a single command. In distinction from other high-level HDF5 interfaces, h5fortran works to deduplicate code, using polymorphism wherever feasible and extensive test suite.

Polymorphic API with read / write dataset types int32, int64, real32, real64, character (string) with rank scalar (0-D) through 7-D. Variable-length datasets "H5S_UNLIMITED" can also be read.

HDF5 attributes are also supported for read/write types int32, int64, real32, real64, character (string) with rank scalar (0-D) through 7-D.

For character, datasets and attributes are supported for fixed length and variable length strings. Character padding uses spaces as this is the default for Fortran. Space-padded, null-terminated and null-padded strings are also supported on read. UTF8 characters are passed through on read and write using the Fortran default character kind.

  • Array slicing on read and write is supported, that is, reading or writing part of a disk HDF5 array into a variable matching the slice shape.
  • Mismatched datatypes are coerced as per standard Fortran rules. For example, reading a float HDF5 variable into an integer Fortran variable: 42.3 => 42
  • Zlib (deflate) compression / decompression -- h5fortran will work without Zlib, but will save/load uncompressed data only.
  • create HDF5 soft link variables--arbitrarily many soft-linked variable names can point to an actual variable, which need not yet exist.

Tested on systems with HDF5 1.8, 1.10, 1.12, and 1.14 including:

  • MacOS (homebrew)
  • Linux (Ubuntu, CentOS)
  • Windows Subsystem for Linux
  • Windows MSYS2
  • IBM Power with Gfortran
  • Cray (using GCC or Intel backend)

Compilers known to work (tested on CI) include:

  • GCC (gfortran) ≥ 8
  • Intel oneAPI ≥ 2021

Compilers not currently working:

  • NVidia HPC SDK 24.9: missing "rank()" intrinsic
  • AOCC missing "rank()" intrinsic and trouble with "select type()" in submodule

Build

h5fortran can be built with CMake or fpm.

CMake

Using CMake:

```sh git clone https://github.com/geospace-code/h5fortran.git

cd h5fortran

cmake -B build

cmake --build build ```

By default, h5fortran CMake doesn't specify optimization flags to help working with old compilers like GCC 7. To enable optimization, set:

sh cmake -Bbuild -DCMAKE_BUILD_TYPE=Release

For more details see Install.md.

For general use with non-CMake build systems, "h5fortran.pc" pkg-config file is also generated / installed.

To save time, if not intended to use self-tests, you can skip the build of the test suite:

sh cmake -B build -Dh5fortran_BUILD_TESTING=off

Fortran Package Manager (fpm)

sh fpm build fpm test fpm install

Build HDF5 standalone

To build the HDF5 and ZLIB libraries, use the scripts folder.

Usage

The simplest example h5fortran usage is like:

```fortran use h5fortran

call h5write('golt.h5','/x', [1,2,3,4,5,6]) ```

or

```fortran use h5fortran

real :: x2

if(.not. is_hdf5('golt.h5')) error stop 'golt.h5 is not an HDF5 file'

call h5read('golt.h5', '/x', x2) ```

For detailed examples see Examples.md.

Notes

  • The first character of the filename should be a character, NOT whitespace to avoid file open/creation errors.
  • Polymorphic array rank is implemented.

HPC

On HPC, we suggest using the HDF5 library provided by the HPC system for best performance and to avoid compiler ABI issues.

h5fortran: missing HDF5 features

  • arrays of rank > 7: prototyped in readernd.f90, writernd.f90. Fortran 2008 arrays are up to rank 15, but only recent compilers support.
  • complex64 / complex128: enabled by HDF5 ≥ 2.0, but not yet implemented in h5fortran.
  • non-default character kind -- we do pass-through UTF8
  • logical / boolean: not supported natively by HDF5. h5py implements as enum.
  • variable length dataset writing

We didn't use type(c_ptr) and c_loc() internally for datasets as we observed problems when the actual argument is sliced on read/write. The current h5fortran implementation (Fortran select type for H5Dwrite/H5Dread) does work with sliced actual arguments.

HDF5 Fortran 2003 features

Alternatives

  • h5pp C++ HDF5 interface
  • HighFive C++ header-only HDF5 interface

Acknowledgements

h5fortran was funded in part by NASA NNH19ZDA001N-HDEE grant 80NSSC20K0176.

Owner

  • Name: Geospace code
  • Login: geospace-code
  • Kind: organization
  • Location: 1 au

GNSS and other geospace analysis programs

JOSS Publication

h5fortran: object-oriented polymorphic Fortran interface for HDF5 file IO
Published
June 25, 2021
Volume 6, Issue 62, Page 2842
Authors
Michael Hirsch ORCID
Boston University
Editor
Pierre de Buyl ORCID

Citation (CITATION.cff)

cff-version: 1.2.0
authors:
  - family-names: Hirsch
    given-names: Michael
    orcid: https://orcid.org/0000-0002-1637-6526
title: h5fortran
doi: 10.5281/zenodo.3562521

CodeMeta (codemeta.json)

{
  "@context": "https://doi.org/10.5063/schema/codemeta-3.0",
  "@type": "SoftwareSourceCode",
  "codeRepository": "https://github.com/geospace-code/h5fortran",
  "continuousIntegration": "https://github.com/geospace-code/h5fortran/actions",
  "downloadUrl": "https://github.com/geospace-code/h5fortran/releases",
  "issueTracker": "https://github.com/geospace-code/h5fortran/issues",
  "name": "h5fortran",
  "identifier": "10.5281/zenodo.3757269",
  "description": "Lightweight object-oriented HDF5 Fortran interface",
  "applicationCategory": "file I/O",
  "developmentStatus": "active",
  "funder": {
    "@type": "Organization",
    "name": "NASA"
  },
  "keywords": [
    "hdf5",
    "object-oriented"
  ],
  "programmingLanguage": [
    "Fortran"
  ],
  "author": [
    {
      "@type": "Organization",
      "name": "SciVision"
    }
  ]
}

GitHub Events

Total
  • Issues event: 2
  • Watch event: 13
  • Issue comment event: 8
  • Pull request event: 2
  • Fork event: 3
Last Year
  • Issues event: 2
  • Watch event: 13
  • Issue comment event: 8
  • Pull request event: 2
  • Fork event: 3

Committers

Last synced: 5 months ago

All Time
  • Total Commits: 1,172
  • Total Committers: 3
  • Avg Commits per committer: 390.667
  • Development Distribution Score (DDS): 0.003
Past Year
  • Commits: 55
  • Committers: 1
  • Avg Commits per committer: 55.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Michael Hirsch s****n 1,168
fccf x****c@q****m 3
Pierre de Buyl p****l@p****e 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 39
  • Total pull requests: 8
  • Average time to close issues: 3 months
  • Average time to close pull requests: about 2 months
  • Total issue authors: 17
  • Total pull request authors: 5
  • Average comments per issue: 3.77
  • Average comments per pull request: 1.63
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 4
  • Pull requests: 4
  • Average time to close issues: 3 months
  • Average time to close pull requests: 4 months
  • Issue authors: 4
  • Pull request authors: 1
  • Average comments per issue: 2.5
  • Average comments per pull request: 1.75
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • bast (8)
  • milancurcic (7)
  • nyckmaia (5)
  • barracuda156 (3)
  • scivision (3)
  • gekowa (2)
  • jdh13 (1)
  • mghaderizefreh (1)
  • mathomp4 (1)
  • jvdp1 (1)
  • Koushikphy (1)
  • mattzett (1)
  • Nicholaswogan (1)
  • yunjielu977 (1)
  • 14NGiestas (1)
Pull Request Authors
  • 14NGiestas (4)
  • zoziha (1)
  • gekowa (1)
  • jvdp1 (1)
  • pdebuyl (1)
Top Labels
Issue Labels
bug (8) enhancement (4) question (2) documentation (2) compiler (2)
Pull Request Labels

Dependencies

.github/workflows/ci.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
  • msys2/setup-msys2 v2 composite
.github/workflows/ci_build.yml actions
  • actions/checkout v3 composite
.github/workflows/ci_fpm.yml actions
  • actions/checkout v3 composite
  • fortran-lang/setup-fpm v4 composite
.github/workflows/oneapi-linux.yml actions
  • actions/checkout v3 composite
.github/workflows/ci_windows.yml actions
  • actions/checkout v4 composite
  • msys2/setup-msys2 v2 composite
.github/workflows/composite-cmake/action.yml actions
.github/workflows/composite-unix/action.yml actions
  • actions/setup-python v5 composite
pyproject.toml pypi