hgrib: Unofficial bindings for GRIB API

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

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


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.3.1.0
Change log CHANGELOG.md
Dependencies base (>=4.8 && <4.9), hgrib [details]
License GPL-3.0-only
Copyright (c) 2015 Mattias Jakobsson
Author Mattias Jakobsson
Maintainer mjakob422@gmail.com
Category Data
Home page https://github.com/mjakob/hgrib
Bug tracker https://github.com/mjakob/hgrib/issues
Source repo head: git clone https://github.com/mjakob/hgrib.git -b develop
this: git clone https://github.com/mjakob/hgrib.git(tag 0.1.0.0)
Uploaded by mjakob at 2015-09-01T11:09:28Z

Modules

[Index]

Flags

Manual Flags

NameDescriptionDefault
build_examples

Build GRIB API example programs

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for hgrib-0.1.0.0

[back to package description]

HGrib

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

In this version of HGrib, only raw bindings for the documented part of GRIB API is available. The next versions are intended to include, in chronological order,

Installation

The following prerequisites are needed to build HGrib:

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

cabal install hgrib

Usage

Right now, only raw bindings for the documented part of GRIB API is available in Data.Grib.Raw. Much of the documentation is copied into HGrib's reference documentation generated by Haddock. 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). An example of usage is GRIB API's get.c example re-written with HGrib's bindings:

import Control.Exception (assert)
import Data.Grib.Raw
import Foreign           (allocaArray, allocaBytes)
import Text.Printf       (printf)


filename :: FilePath
filename = "test/stage/regular_latlon_surface.grib1"

assertIO :: Bool -> IO ()
assertIO = flip assert $ return ()

main :: IO ()
main = do
  h <- withBinaryCFile filename ReadMode $
         gribHandleNewFromFile defaultGribContext

  _ <- gribSetString h "file" filename

  gribGetLong h "Ni" >>= printf "numberOfPointsAlongAParallel=%d\n"
  gribGetLong h "Nj" >>= printf "numberOfPointsAlongAMeridian=%d\n"

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

  len <- gribGetLength h "packingType"
  allocaBytes len $ \bufr -> do
    packingType <- gribGetString h "packingType" bufr len
    printf "packingType=%s (%d)\n" packingType (length packingType + 1)

  size <- gribGetSize h "values"
  allocaArray size $ \array -> do
    values <- gribGetDoubleArray h "values" array size
    let average = sum values / (fromIntegral . length $ values)
    printf "There are %d values, average is %g\n" size average

  len' <- gribGetLength h "file"
  assertIO $ len' == 1 + length filename
  allocaBytes len' $ \bufr' -> do
    file <- gribGetString h "file" bufr' len'
    assertIO $ file == filename

Contributing

Issues and pull requests are most welcome!

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.