Copyright | (c) Mattias Jakobsson 2015 |
---|---|
License | GPL-3 |
Maintainer | mjakob422@gmail.com |
Stability | unstable |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
- type GribIO = ReaderT GribEnv IO
- runGribIO :: FilePath -> GribIO a -> IO [a]
- runGribIO_ :: FilePath -> GribIO a -> IO ()
- skipMessage :: GribIO a
- skipMessageIf :: (a -> Bool) -> GribIO a -> GribIO a
- skipMessageIf_ :: (a -> Bool) -> GribIO a -> GribIO ()
- getDouble :: Key -> GribIO Double
- getLong :: Key -> GribIO Int
- getString :: Key -> GribIO String
- getValues :: GribIO [Double]
- setDouble :: Key -> Double -> GribIO ()
- setLong :: Key -> Int -> GribIO ()
- setString :: Key -> String -> GribIO ()
- setValues :: [Double] -> GribIO ()
- getFilename :: GribIO FilePath
- getIndex :: GribIO Int
- getHandle :: GribIO GribHandle
- liftIO :: MonadIO m => forall a. IO a -> m a
- data GribEnv
- data SkipMessage
The GRIB Monad
:: FilePath | a path to a GRIB file |
-> GribIO a | an action to take on each GRIB message in the file |
-> IO [a] | the results of the actions |
Run an action on each GRIB message in a file and collect the results.
This operation may fail with:
- any
IOError
raised byopenBinaryCFile
; - any
GribError
raised bygribHandleNewFromFile
; or - any other exception raised by the given
GribIO
action.
skipMessage :: GribIO a Source
Skip the current GRIB message. No result will be put in the
output list of runGribIO
for this message.
:: (a -> Bool) | a predicate that will be given the result of the action |
-> GribIO a | an action to perform |
-> GribIO a |
Skip the current GRIB message if the predicate is true. No result
will be put in the output list of runGribIO
in this case.
skipMessageIf_ :: (a -> Bool) -> GribIO a -> GribIO () Source
Like skipMessageIf
, but discard the result of the action.
Examples
Sum all grid points of the first vertical level in a GRIB message:
runGribIO "test/stage/test_uuid.grib2" $ do skipMessageIf_ (/= 1) $ getLong "topLevel" fmap sum getValues
Get values
These operations may fail with:
isGribException
GribNotFound
if the key is missing.
Set values
These operations may fail with:
isGribException
GribNotFound
if the key is missing; orisGribException
GribReadOnly
if the key is read-only.
Utilities
getFilename :: GribIO FilePath Source
Return the name of the file being read.
getHandle :: GribIO GribHandle Source
Return the current GribHandle
for use with the Raw
GRIB API bindings.
Auxiliary types
The reader environment of GribIO
containing the current
filename, a GribHandle
, and its index in the file.
data SkipMessage Source
If this exception is raised in GribIO
, the message will be
discarded. Normally, you simply call skipMessage
instead of
throwing this exception manually.