MyNixOS website logo
Description

Unofficial bindings for GRIB API.

Unofficial bindings to ECMWF's GRIB API library for reading WMO FM-92 GRIB edition 1 and edition 2 messages.

HGrib

Build Status

Unofficial bindings for ECMWF's GRIB API library for reading and writing WMO FM-92 GRIB edition 1 and edition 2 messages.

In this version of HGrib, a read-only monadic Haskell interface to GRIB API is provided. Raw bindings for the documented parts of GRIB API are also available. Future versions are intended to expand the higher-level Haskell interface to include, among other things, write support.

Installation

The following prerequisites are needed to build HGrib:

  • GRIB API >= 1.12 installed and discoverable by ghc (use cabal's --extra-include-dirs and --extra-lib-dirs if it's installed at a custom location); and

  • Haskell base >= 4.5; and

  • c2hs == 0.26.*.

With these requirements available, HGrib can be installed from Hackage with Cabal:

cabal install hgrib

Usage

HGrib provides a high-level monadic Haskell interface to GRIB API in Data.Grib. An example of its usage is GRIB API's get.c example re-written with HGrib:

import Control.Exception ( assert )
import Data.Grib
import Text.Printf       ( printf )

main :: IO ()
main = let filename = "test/stage/regular_latlon_surface.grib1" in
  runGribIO_ filename $ do
    setString "file" filename

    getLong "Ni" >>= liftIO . printf "numberOfPointsAlongAParallel=%d\n"
    getLong "Nj" >>= liftIO . printf "numberOfPointsAlongAMeridian=%d\n"

    getDouble "yFirst" >>=
      liftIO . printf "latitudeOfFirstGridPointInDegrees=%g\n"
    getDouble "xFirst" >>=
      liftIO . printf "longitudeOfFirstGridPointInDegrees=%g\n"
    getDouble "yLast"  >>=
      liftIO . printf "latitudeOfLastGridPointInDegrees=%g\n"
    getDouble "xLast"  >>=
      liftIO . printf "longitudeOfLastGridPointInDegrees=%g\n"
    getDouble "DyInDegrees" >>=
      liftIO . printf "jDirectionIncrementInDegrees=%g\n"
    getDouble "DxInDegrees" >>=
      liftIO . printf "iDirectionIncrementInDegrees=%g\n"

    getString "packingType" >>= liftIO . printf "packingType=%s\n"

    values <- getValues
    let numValues = length values
        average   = sum values / fromIntegral numValues
    liftIO $ printf "There are %d values, average is %g\n" numValues average

    filename' <- getString "file"
    liftIO $ assert (filename' == filename) (return ())

Raw bindings for the documented part of GRIB API is also available in Data.Grib.Raw. To be able to work with these bindings, bindings for C's fopen is provided in Data.Grib.Raw.CFile (which is re-exported by Data.Grib.Raw).

For more information, see HGrib's reference documentation generated by Haddock.

Contributing

Issues, feature and pull requests are most welcome! In particular, please give suggestions on what you would like to see in the higher-level interface and let me know if there is any undocumented part of GRIB API that you would like to have included.

Licenses

HGrib was created and is currently maintained by Mattias Jakobsson. It is released under the GNU General Public License v3.0. ECMWF's GRIB API is released under the Apache license. HGrib is in no way associated with ECMWF or the original library.

Metadata

Version

0.3.1.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows