{"id":19872178,"url":"https://github.com/geospace-code/h5fortran","last_synced_at":"2026-02-04T11:15:29.740Z","repository":{"id":39836065,"uuid":"128736984","full_name":"geospace-code/h5fortran","owner":"geospace-code","description":"Lightweight HDF5 polymorphic Fortran: h5write() h5read()","archived":false,"fork":false,"pushed_at":"2025-06-24T20:26:32.000Z","size":3978,"stargazers_count":109,"open_issues_count":5,"forks_count":25,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-06-27T01:03:24.541Z","etag":null,"topics":["fortran","hdf5","object-oriented-fortran"],"latest_commit_sha":null,"homepage":"https://geospace-code.github.io/h5fortran","language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/geospace-code.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json","zenodo":null},"funding":{"github":["scivision"],"ko_fi":"scivision"}},"created_at":"2018-04-09T08:09:06.000Z","updated_at":"2025-06-24T20:26:35.000Z","dependencies_parsed_at":"2025-01-11T16:33:21.681Z","dependency_job_id":"f5d28c97-3c8e-492b-b7f7-c80d9fba330c","html_url":"https://github.com/geospace-code/h5fortran","commit_stats":null,"previous_names":[],"tags_count":152,"template":false,"template_full_name":null,"purl":"pkg:github/geospace-code/h5fortran","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geospace-code%2Fh5fortran","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geospace-code%2Fh5fortran/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geospace-code%2Fh5fortran/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geospace-code%2Fh5fortran/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geospace-code","download_url":"https://codeload.github.com/geospace-code/h5fortran/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geospace-code%2Fh5fortran/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262347266,"owners_count":23296871,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fortran","hdf5","object-oriented-fortran"],"created_at":"2024-11-12T16:14:43.712Z","updated_at":"2026-02-04T11:15:29.734Z","avatar_url":"https://github.com/geospace-code.png","language":"Fortran","funding_links":["https://github.com/sponsors/scivision","https://ko-fi.com/scivision"],"categories":[],"sub_categories":[],"readme":"# Object-oriented Fortran HDF5 interface\n\n[![DOI](https://joss.theoj.org/papers/10.21105/joss.02842/status.svg)](https://doi.org/10.21105/joss.02842)\n[![DOI](https://zenodo.org/badge/128736984.svg)](https://zenodo.org/badge/latestdoi/128736984)\n\n[![ci](https://github.com/geospace-code/h5fortran/actions/workflows/ci.yml/badge.svg)](https://github.com/geospace-code/h5fortran/actions/workflows/ci.yml)\n[![ci_windows](https://github.com/geospace-code/h5fortran/actions/workflows/ci_windows.yml/badge.svg)](https://github.com/geospace-code/h5fortran/actions/workflows/ci_windows.yml)\n[![ci_build](https://github.com/geospace-code/h5fortran/actions/workflows/ci_build.yml/badge.svg)](https://github.com/geospace-code/h5fortran/actions/workflows/ci_build.yml)\n[![oneapi-linux](https://github.com/geospace-code/h5fortran/actions/workflows/oneapi-linux.yml/badge.svg)](https://github.com/geospace-code/h5fortran/actions/workflows/oneapi-linux.yml)\n[![ci_fpm](https://github.com/geospace-code/h5fortran/actions/workflows/ci_fpm.yml/badge.svg)](https://github.com/geospace-code/h5fortran/actions/workflows/ci_fpm.yml)\n\nSimple, robust, thin HDF5 polymorphic Fortran read/write interface.\nReading or writing {real64,real32,int32,int64} from scalar to 7d is as simple as\n\n```fortran\nuse h5fortran\n\ncall h5write('my.h5', '/x', x)\n\ncall h5read('my.h5', '/y', y)\n```\n\nFor NetCDF4 see\n[nc4fortran](https://github.com/geospace-code/nc4fortran/).\nh5fortran is designed for \"serial\" HDF5 read/write.\n[h5fortran-mpi](https://github.com/geospace-code/h5fortran-mpi) is a Fortran interface for \"parallel\" HDF5.\n\nh5fortran is designed for easy use using static or shared linking from your project via:\n\n* `cmake --install`\n* CMake [ExternalProject (example)](https://gist.github.com/scivision/dd0e7aa18ba1397b0274c82603e4650c)\n* CMake [FetchContent (example)](https://gist.github.com/scivision/671633df71c5aaef7866d0c3a1504116)\n* CMake + Git submodule\n* Fortran Package Manager (fpm)\n\nUses Fortran `submodule` for clean template structure.\nThis 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.\nIn distinction from other high-level HDF5 interfaces, h5fortran works to deduplicate code, using polymorphism wherever feasible and extensive test suite.\n\nPolymorphic\n[API](./API.md)\nwith read / write **dataset** types int32, int64, real32, real64, character (string) with rank scalar (0-D) through 7-D.\nVariable-length datasets \"H5S_UNLIMITED\" can also be read.\n\nHDF5 **attributes** are also supported for read/write types int32, int64, real32, real64, character (string) with rank scalar (0-D) through 7-D.\n\nFor **character**, datasets and attributes are supported for fixed length and variable length strings.\nCharacter padding uses spaces as this is the default for Fortran.\nSpace-padded, null-terminated and null-padded strings are also supported on read.\nUTF8 characters are passed through on read and write using the Fortran default character kind.\n\n* **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.\n* Mismatched datatypes are coerced as per standard Fortran rules. For example, reading a float HDF5 variable into an integer Fortran variable:  42.3 =\u003e 42\n* Zlib (deflate) compression / decompression -- h5fortran will work without Zlib, but will save/load uncompressed data only.\n* create HDF5 soft link variables--arbitrarily many soft-linked variable names can point to an actual variable, which need not yet exist.\n\nTested on systems with HDF5 1.8, 1.10, 1.12, and 1.14 including:\n\n* MacOS (homebrew)\n* Linux (Ubuntu, CentOS)\n* Windows Subsystem for Linux\n* Windows MSYS2\n* IBM Power with Gfortran\n* Cray (using GCC or Intel backend)\n\nCompilers known to work (tested on CI) include:\n\n* GCC (gfortran) \u0026ge; 8\n* Intel oneAPI \u0026ge; 2021\n\nCompilers not currently working:\n\n* NVidia HPC SDK 24.9: missing \"rank()\" intrinsic\n* AOCC missing \"rank()\" intrinsic and trouble with \"select type()\" in submodule\n\n## Build\n\nh5fortran can be built with CMake or [fpm](https://fpm.fortran-lang.org/).\n\n### CMake\n\nUsing CMake:\n\n```sh\ngit clone https://github.com/geospace-code/h5fortran.git\n\ncd h5fortran\n\ncmake -B build\n\ncmake --build build\n```\n\nBy default, h5fortran CMake doesn't specify optimization flags to help working with old compilers like GCC 7.\nTo enable optimization, set:\n\n```sh\ncmake -Bbuild -DCMAKE_BUILD_TYPE=Release\n```\n\nTo not try to find HDF5, instead building HDF5 from source, set:\n\n```sh\ncmake -B build -Dh5fortran_find=false\n```\n\nFor more details see [Install.md](./Install.md).\n\nFor general use with non-CMake build systems, \"h5fortran.pc\" pkg-config file is also generated / installed.\n\nTo save time, if not intended to use self-tests, you can skip the build of the test suite:\n\n```sh\ncmake -B build -Dh5fortran_BUILD_TESTING=off\n```\n\n### Fortran Package Manager (fpm)\n\n```sh\nfpm build\nfpm test\nfpm install\n```\n\n## Build HDF5 standalone\n\nTo build the HDF5 and ZLIB libraries, use the [scripts](./scripts/) folder.\n\n## Usage\n\nThe simplest [example](./example/) h5fortran usage is like:\n\n```fortran\nuse h5fortran\n\ncall h5write('golt.h5','/x', [1,2,3,4,5,6])\n```\n\nor\n\n```fortran\nuse h5fortran\n\nreal :: x2\n\nif(.not. is_hdf5('golt.h5')) error stop 'golt.h5 is not an HDF5 file'\n\ncall h5read('golt.h5', '/x', x2)\n```\n\nFor detailed [examples](./example/) see [Examples.md](./Examples.md).\n\n## Notes\n\n* The first character of the filename should be a character, NOT whitespace to avoid file open/creation errors.\n* Polymorphic array rank is implemented.\n\n### HPC\n\nOn HPC, we suggest using the HDF5 library provided by the HPC system for best performance and to avoid compiler ABI issues.\n\n### h5fortran: missing HDF5 features\n\n* arrays of rank \u003e 7: prototyped in reader_nd.f90, writer_nd.f90. Fortran 2008 arrays are up to rank 15, but only recent compilers support.\n* complex64 / complex128: enabled by HDF5 \u0026ge; 2.0, but not yet implemented in h5fortran.\n* non-default character kind -- we do pass-through UTF8\n* logical / boolean: not supported natively by HDF5. h5py implements as [enum](https://docs.h5py.org/en/stable/faq.html#what-datatypes-are-supported).\n* variable length dataset writing\n\nWe 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.\nThe current h5fortran implementation (Fortran `select type` for H5Dwrite/H5Dread) does work with sliced actual arguments.\n\nHDF5 Fortran 2003\n[features](https://docs.hdfgroup.org/archive/support/HDF5/doc/fortran/NewFeatures_F2003.pdf)\n\n## Alternatives\n\n* [h5pp](https://github.com/DavidAce/h5pp) C++ HDF5 interface\n* [HighFive](https://github.com/BlueBrain/HighFive) C++ header-only HDF5 interface\n\n## Acknowledgements\n\nh5fortran was funded in part by NASA NNH19ZDA001N-HDEE grant 80NSSC20K0176.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeospace-code%2Fh5fortran","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeospace-code%2Fh5fortran","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeospace-code%2Fh5fortran/lists"}