GithubHelp home page GithubHelp logo

richardfoltyn / hdf5-fortran-wrapper Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 56 KB

Wrapper library around the low-level HDF5 Fortran APIs to more easily store & load high-dimensional arrays

License: GNU Lesser General Public License v3.0

CMake 10.04% Fortran 89.96%

hdf5-fortran-wrapper's Introduction

HDF5 Fortran Wrapper

This small wrapper implements a simple interface to store and load high-dimensional arrays in Fortran. It is easier to use than the low-level API provided by the official HDF5 library.

Examples

Reading arrays of unknown shape (but known rank)

use hdf5_wrapper

integer (hid_t) :: loc_id
    ! Holds the ID of group or location where dataset is stored
integer :: status
real, dimension(:,:,:), allocatable :: arr

! Routine checks the data dimensions and allocates array `arr` as needed.
! Passing the error flag `status` is optional.
call hdf5_load_alloc (loc_id, "data_name", arr, status=status)

! We can also ignore optional datasets that are not present without
! raising an error.
call hdf5_load_alloc (loc_id, "data_name", arr, ignore_missing=.true.)

! Alternatively, ignore the auto-allocation feature and pre-allocate
! the array manually to some known shape.
allocate (arr(10,10,10))
call hdf5_load (loc_id, "data_name", arr)

Storing arrays

use hdf5_wrapper

integer (hid_t) :: loc_id
    ! Holds the ID of group or location where dataset is stored
integer :: status
real, dimension(5,5) :: arr
    ! Array containing data

arr = 1

! Store array
call hdf5_store (loc_id, "data_name", arr)

! Optionally, use GZIP compression (if HDF5 was compiled with gzip support).
! Passing the error flag `status` is optional.
call hdf5_store (loc_id, "data_name", arr, deflate=.true., status=status)

Installation

The library is built using CMake using something along the lines of

cd /path/to/hdf5-fortran/wrapper
mkdir build
cd build
cmake ../src
cmake --build .
cmake --install .

Usage

To integrate the library in your own CMake project, augment your CMakeLists.txt as follows. See also the minimal client in tests/client.f90.

cmake_minimum_required(VERSION 3.12)

project(H5FW_client LANGUAGES C Fortran)

# HDF5 library required for linking
find_package(HDF5 REQUIRED COMPONENTS Fortran)

# Locale the library. You may need to adapt CMAKE_PREFIX_PATH, depending
# on where the library was installed.
find_package(h5fw REQUIRED)

add_executable(client client.f90)
target_link_libraries(client h5fw::h5fw)

Author

Richard Foltyn

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

hdf5-fortran-wrapper's People

Contributors

richardfoltyn avatar

Watchers

 avatar

hdf5-fortran-wrapper's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.