Skip to content

twesterhout/hdf5-hs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2b4f5e4 ยท Oct 12, 2023
Feb 21, 2022
Feb 11, 2021
Nov 30, 2021
Mar 10, 2022
Mar 24, 2023
Mar 24, 2023
Oct 12, 2023
Feb 17, 2021
Jul 15, 2020
Jul 15, 2020
Dec 29, 2020
Feb 12, 2021
Oct 12, 2023
Oct 12, 2023
Mar 24, 2023
Mar 24, 2023
Mar 24, 2023

Repository files navigation

hdf5-hs GitHub CIBSD-3-Clause license

Warning: this package is a work-in-progress. The code is kind of working, but documentation and examples are lacking. Also this project was created specifically for SpinED program, so it's going to be "battle-tested" rather that a proof-of-concept.

High-level interface to HDF5 for Haskell. The idea is to provide a limited functionality, but in a user-friendly way. It relies extensively on GADTs to keep the interface polymorphic, but type-safe.

Installation

This package is very much a work-in-progress and is not (yet, hopefully) available on Hackage. Currently, the easiest way to install it is to use cabal.project and specify that you want to install hdf5-hs from Git:

source-repository-package
    type: git
    location: https://github.com/twesterhout/hdf5-hs.git

Currently, Linux and OS X operating systems are supported. (I don't have experience or access to a Windows system, but a PR would be very welcome!)

Simple example

{-# LANGUAGE OverloadedStrings #-}

import Data.HDF5 (Dataset, Group, IOMode (..))
import qualified Data.HDF5 as H5
import Data.Text (Text)

main :: IO ()
main = do
  -- Create a file
  H5.withFile "example00.h5" WriteMode $ \file -> do
    -- Create a group
    H5.makeGroup file "myGroup"
    -- Do something with the group
    -- (matchM function "proves" to GHC that the object we've just opened is indeed a group)
    H5.byName file "myGroup" . H5.matchM @Group $ \group -> do
      -- Create a dataset
      H5.writeDataset group "myDataset" [(1 :: Int) .. 25]
      -- Add a description
      H5.byName group "myDataset" . H5.matchM @Dataset $ \dataset ->
        H5.writeAttribute dataset "myAttribute" ("Contains very important data ๐Ÿ˜€" :: Text)

Related projects

There is hs-hdf5. It covers more functionality of HDF5 than this package, but the API is lower-level.