hgrib 0.1.0.0 → 0.2.0.0
raw patch · 25 files changed
+264/−336 lines, 25 filesdep ~basedep ~directoryPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, directory
API changes (from Hackage documentation)
- Data.Grib.Raw.Context: gribContextSetBufferMemoryProc :: (GribContext) -> (GribMallocProc) -> (GribFreeProc) -> (GribReallocProc) -> IO ()
- Data.Grib.Raw.Context: gribContextSetLoggingProc :: (GribContext) -> (GribLogProc) -> IO ()
- Data.Grib.Raw.Context: gribContextSetMemoryProc :: (GribContext) -> (GribMallocProc) -> (GribFreeProc) -> (GribReallocProc) -> IO ()
- Data.Grib.Raw.Context: gribContextSetPersistentMemoryProc :: (GribContext) -> (GribMallocProc) -> (GribFreeProc) -> IO ()
- Data.Grib.Raw.Context: gribContextSetPrintProc :: (GribContext) -> (GribPrintProc) -> IO ()
- Data.Grib.Raw.Context: type GribDataEofProc = FunPtr (((GribContext) -> ((Ptr ()) -> (IO CInt))))
- Data.Grib.Raw.Context: type GribDataReadProc = FunPtr (((GribContext) -> ((Ptr ()) -> (CULong -> ((Ptr ()) -> (IO CULong))))))
- Data.Grib.Raw.Context: type GribDataSeekProc = FunPtr (((GribContext) -> (CLong -> (CInt -> ((Ptr ()) -> (IO CLong))))))
- Data.Grib.Raw.Context: type GribDataTellProc = FunPtr (((GribContext) -> ((Ptr ()) -> (IO CLong))))
- Data.Grib.Raw.Context: type GribDataWriteProc = FunPtr (((GribContext) -> ((Ptr ()) -> (CULong -> ((Ptr ()) -> (IO CULong))))))
- Data.Grib.Raw.Context: type GribFreeProc = FunPtr (((GribContext) -> ((Ptr ()) -> (IO ()))))
- Data.Grib.Raw.Context: type GribLogProc = FunPtr (((GribContext) -> (CInt -> ((Ptr CChar) -> (IO ())))))
- Data.Grib.Raw.Context: type GribMallocProc = FunPtr (((GribContext) -> (CULong -> (IO (Ptr ())))))
- Data.Grib.Raw.Context: type GribPrintProc = FunPtr (((GribContext) -> ((Ptr ()) -> ((Ptr CChar) -> (IO ())))))
- Data.Grib.Raw.Context: type GribReallocProc = FunPtr (((GribContext) -> ((Ptr ()) -> (CULong -> (IO (Ptr ()))))))
+ Data.Grib.Raw.Context: gribGetApiVersion :: Int
Files
- CHANGELOG.md +33/−0
- README.md +11/−13
- examples/get.hs +1/−1
- hgrib.cabal +13/−8
- src/Data/Grib/Raw.hs +3/−1
- src/Data/Grib/Raw/CFile.chs +9/−7
- src/Data/Grib/Raw/Context.chs +24/−149
- src/Data/Grib/Raw/Exception.chs +2/−2
- src/Data/Grib/Raw/Handle.chs +18/−16
- src/Data/Grib/Raw/Index.chs +20/−18
- src/Data/Grib/Raw/Iterator.chs +13/−9
- src/Data/Grib/Raw/KeysIterator.chs +14/−14
- src/Data/Grib/Raw/Marshal.hs +13/−10
- src/Data/Grib/Raw/Nearest.chs +13/−13
- src/Data/Grib/Raw/Types.hs +2/−2
- src/Data/Grib/Raw/Value.chs +27/−25
- test/Data/Grib/Raw/CFileSpec.hs +7/−7
- test/Data/Grib/Raw/ContextSpec.hs +3/−3
- test/Data/Grib/Raw/HandleSpec.hs +3/−4
- test/Data/Grib/Raw/IndexSpec.hs +7/−13
- test/Data/Grib/Raw/IteratorSpec.hs +1/−1
- test/Data/Grib/Raw/KeysIteratorSpec.hs +10/−8
- test/Data/Grib/Raw/NearestSpec.hs +1/−1
- test/Data/Grib/Raw/Test.hs +12/−5
- test/Data/Grib/Raw/ValueSpec.hs +4/−6
CHANGELOG.md view
@@ -1,5 +1,38 @@ # HGrib Change Log +## 0.2.0.0++* Extended the compatible version range of GRIB API and the Haskell+ base library.++* Added a `gribGetApiVersion` function to `Data.Grib.Raw`.++* Included the `Data.Grib.Raw.Exception` module in `Data.Grib.Raw` and+ removed the marshal function `withGribMultiHandle`.++* Removed++ * `gribContextSetMemoryProc`+ * `gribContextSetPersistentMemoryProc`+ * `gribContextSetBufferMemoryProc`+ * `gribContextSetPrintingProc`+ * `gribContextSetLoggingProc`++ and corresponding foreign function type definitions from+ `Data.Grib.Raw` to be able to mark all remaining functions _unsafe_+ from a FFI perspective.++* Marked all foreign imports _unsafe_.++* Integrated the source code repository with [Travis CI][].++* Abandoned the plans to include the full GRIB API in `grib_api.h`+ (but requests to include specific parts are welcome).++ ## 0.1.0.0 * Initial release.+++[Travis CI]: https://travis-ci.org/mjakob/hgrib
README.md view
@@ -1,29 +1,26 @@ # HGrib +[](https://travis-ci.org/mjakob/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][GRIB Docs] part of GRIB API is available. The next-versions are intended to include, in chronological order,-- * Raw bindings for the full API in the [grib_api.h][GRIB Header] C- header file.-- * A higher-level Haskell interface.+In this version of HGrib, raw bindings for the [documented][GRIB Docs]+part of GRIB API is available. Future versions are intended to+include a higher-level Haskell interface. ## Installation The following prerequisites are needed to build HGrib: - * [GRIB API][] == 1.14.0 installed and discoverable by ghc (use+ * [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.8.*+ * Haskell [base][] >= 4.5; and - * [c2hs][] == 0.26.*+ * [c2hs][] == 0.26.*. With these requirements available, HGrib can be installed from [Hackage][] with [Cabal][]:@@ -94,7 +91,9 @@ ## Contributing -Issues and pull requests are most welcome!+Issues and pull requests are most welcome! In particular, let me know+if there is any undocumented part of GRIB API that you would like to+have included. ## Licenses@@ -115,7 +114,6 @@ [GRIB API]: https://software.ecmwf.int/wiki/display/GRIB/Home [GRIB Docs]: https://software.ecmwf.int/wiki/display/GRIB/Module+Index [GRIB Get]: https://software.ecmwf.int/wiki/display/GRIB/get.c-[GRIB Header]: https://software.ecmwf.int/wiki/display/GRIB/grib_api.h+File+Reference [Hackage]: http://hackage.haskell.org/ [Haddock]: https://www.haskell.org/haddock/ [HGRIB Docs]: https://hackage.haskell.org/package/hgrib
examples/get.hs view
@@ -15,7 +15,7 @@ h <- withBinaryCFile filename ReadMode $ gribHandleNewFromFile defaultGribContext - _ <- gribSetString h "file" filename+ gribSetString h "file" filename gribGetLong h "Ni" >>= printf "numberOfPointsAlongAParallel=%d\n" gribGetLong h "Nj" >>= printf "numberOfPointsAlongAMeridian=%d\n"
hgrib.cabal view
@@ -1,7 +1,7 @@ -- Package description for HGrib. name: hgrib-version: 0.1.0.0+version: 0.2.0.0 synopsis: Unofficial bindings for GRIB API description: Unofficial bindings to ECMWF's GRIB API library for reading WMO@@ -31,27 +31,32 @@ source-repository this type: git location: https://github.com/mjakob/hgrib.git- tag: 0.1.0.0+ tag: 0.2.0.0 library default-language: Haskell2010 hs-source-dirs: src exposed-modules: Data.Grib.Raw+ Data.Grib.Raw.Exception++ -- These modules need to go above any modules importing them via c2hs: Data.Grib.Raw.CFile Data.Grib.Raw.Context- Data.Grib.Raw.Exception Data.Grib.Raw.Handle++ -- These modules can import any of the modules above via c2hs: Data.Grib.Raw.Index Data.Grib.Raw.Iterator Data.Grib.Raw.KeysIterator Data.Grib.Raw.Nearest Data.Grib.Raw.Types Data.Grib.Raw.Value+ other-modules: Data.Grib.Raw.Marshal build-depends:- base == 4.8.*+ base >= 4.5 && < 4.9 build-tools: c2hs == 0.26.* extra-libraries:@@ -75,8 +80,8 @@ Data.Grib.Raw.Test Data.Grib.Raw.ValueSpec build-depends:- base == 4.8.*- , directory == 1.2.*+ base >= 4.5 && < 4.9+ , directory >= 1.1 && < 1.3 , hgrib , hspec == 2.1.* ghc-options:@@ -92,9 +97,9 @@ main-is: get.hs hs-source-dirs: examples build-depends:- base == 4.8.*+ base >= 4.5 && < 4.9 , hgrib ghc-options:- -Wall+ -Wall -fno-warn-unused-do-bind if !flag(build_examples) buildable: False
src/Data/Grib/Raw.hs view
@@ -16,6 +16,7 @@ module Data.Grib.Raw ( module Data.Grib.Raw.CFile , module Data.Grib.Raw.Context+ , module Data.Grib.Raw.Exception , module Data.Grib.Raw.Handle , module Data.Grib.Raw.Index , module Data.Grib.Raw.Iterator@@ -27,7 +28,8 @@ import Data.Grib.Raw.CFile import Data.Grib.Raw.Context-import Data.Grib.Raw.Handle hiding (withGribHandle)+import Data.Grib.Raw.Exception+import Data.Grib.Raw.Handle hiding (withGribHandle, withGribMultiHandle) import Data.Grib.Raw.Index hiding (withGribIndex) import Data.Grib.Raw.Iterator import Data.Grib.Raw.KeysIterator
src/Data/Grib/Raw/CFile.chs view
@@ -18,10 +18,11 @@ , IOMode(..) ) where -import Control.Exception (bracket)-import Control.Monad (when)-import Foreign.C-import System.IO (IOMode(..))+import Control.Exception ( bracket )+import Control.Monad ( when )+import Foreign.C ( CInt, CFile, throwErrno, throwErrnoPathIfNull+ , withCString )+import System.IO ( IOMode(..) ) #include <stdio.h>@@ -44,9 +45,10 @@ -- file 'System.IO.Handle'. openBinaryCFile :: FilePath -> IOMode -> IO CFilePtr openBinaryCFile name mode =- withCString name $ \c_name ->+ withCString name $ \c_name -> withCString mode_str $ \c_mode ->- throwErrnoPathIfNull "openBinaryCFile" name ({#call fopen #} c_name c_mode)+ throwErrnoPathIfNull "openBinaryCFile" name $+ {#call unsafe fopen #} c_name c_mode where mode_str = case mode of ReadMode -> "rb" WriteMode -> "wb"@@ -54,7 +56,7 @@ ReadWriteMode -> "r+b" -- |Close an open 'Foreign.C.CFile'.-{#fun fclose as closeCFile { `CFilePtr' } -> `()' checkStatus*- #}+{#fun unsafe fclose as closeCFile { `CFilePtr' } -> `()' checkStatus*- #} where checkStatus r = when (r == eof) $ throwErrno "closeCFile" -- |Like 'System.IO.withBinaryFile', but use a 'CFilePtr' instead of a file
src/Data/Grib/Raw/Context.chs view
@@ -25,11 +25,6 @@ , gribContextGetDefault , gribContextNew , gribContextDelete- , gribContextSetMemoryProc- , gribContextSetPersistentMemoryProc- , gribContextSetBufferMemoryProc- , gribContextSetPrintProc- , gribContextSetLoggingProc -- ** Control GTS Mode , gribGtsHeaderOn@@ -44,25 +39,26 @@ , gribMultiSupportOn , gribMultiSupportOff - -- * Foreign Function Type Definitions- , GribFreeProc- , GribMallocProc- , GribReallocProc- , GribLogProc- , GribPrintProc- , GribDataReadProc- , GribDataWriteProc- , GribDataTellProc- , GribDataSeekProc- , GribDataEofProc+ -- * GRIB API Version+ , gribGetApiVersion ) where -import Foreign-import Foreign.C+import Foreign ( nullPtr ) #include <grib_api.h> +-- long grib_get_api_version(void);+--+-- |Get the current version of GRIB API as an integer.+--+-- The major version is multiplied by 10000, the minor by 100 and then+-- they are summed together with the revision version to form the+-- integer. For example, version 1.13.1 would be 11301.+{#fun pure unsafe grib_get_api_version as ^ {} -> `Int' #}++-- This comment is inserted to help Haddock keep all docs.+ -- typedef struct grib_context grib_context; -- -- It doesn't seem like grib_context_delete() can be used in general,@@ -78,74 +74,6 @@ defaultGribContext :: GribContext defaultGribContext = GribContext nullPtr --- typedef void (*grib_free_proc)(const grib_context* c, void* data);------ |Grib free procedure, format of a procedure referenced in the--- context that is used to free memory.-{#pointer grib_free_proc as GribFreeProc #}---- This comment is inserted to help Haddock keep all docs.---- typedef void* (*grib_malloc_proc)(const grib_context* c, size_t length);------ |Grib malloc procedure, format of a procedure referenced in the--- context that is used to allocate memory.-{#pointer grib_malloc_proc as GribMallocProc #}---- typedef void* (*grib_realloc_proc)(const grib_context* c, void* data,--- size_t length);------ |Grib realloc procedure, format of a procedure referenced in the--- context that is used to reallocate memory.-{#pointer grib_realloc_proc as GribReallocProc #}---- typedef void (*grib_log_proc)(const grib_context* c, int level,--- const char* mesg);------ |Grib loc proc, format of a procedure referenced in the context--- that is used to log internal messages.-{#pointer grib_log_proc as GribLogProc #}---- typedef void (*grib_print_proc)(const grib_context* c, void* descriptor,--- const char* mesg);------ |Grib print proc, format of a procedure referenced in the context--- that is used to print external messages.-{#pointer grib_print_proc as GribPrintProc #}---- typedef size_t (*grib_data_read_proc)(const grib_context* c, void *ptr,--- size_t size, void *stream);------ |Grib data read proc, format of a procedure referenced in the--- context that is used to read from a stream in a resource.-{#pointer grib_data_read_proc as GribDataReadProc #}---- typedef size_t (*grib_data_write_proc)(const grib_context* c, const void *ptr,--- size_t size, void *stream);------ |Grib data read write, format of a procedure referenced in the--- context that is used to write to a stream from a resource.-{#pointer grib_data_write_proc as GribDataWriteProc #}---- typedef off_t (*grib_data_tell_proc)(const grib_context* c, void *stream);------ |Grib data tell, format of a procedure referenced in the context--- that is used to tell the current position in a stream.-{#pointer grib_data_tell_proc as GribDataTellProc #}---- typedef off_t (*grib_data_seek_proc)(const grib_context* c, off_t offset,--- int whence, void *stream);------ |Grib data seek, format of a procedure referenced in the context--- that is used to seek the current position in a stream.-{#pointer grib_data_seek_proc as GribDataSeekProc #}---- typedef int (*grib_data_eof_proc)(const grib_context* c, void *stream);------ |Grib data eof, format of a procedure referenced in the context--- that is used to test end of file.-{#pointer grib_data_eof_proc as GribDataEofProc #}- -- grib_context* grib_context_get_default(void); -- -- |Get the static default context.@@ -154,12 +82,12 @@ -- 'defaultGribContext', since that is just a null pointer and this is -- a pointer to the real thing. They should, however, be able to be -- used interchangeably with all the functions in this package.-{#fun grib_context_get_default as ^ {} -> `GribContext' #}+{#fun unsafe grib_context_get_default as ^ {} -> `GribContext' #} -- grib_context* grib_context_new(grib_context* c); -- -- |Create and allocate a new context from a parent context.-{#fun grib_context_new as ^ { `GribContext' } -> `GribContext' #}+{#fun unsafe grib_context_new as ^ { `GribContext' } -> `GribContext' #} -- void grib_context_delete(grib_context* c); --@@ -169,94 +97,41 @@ -- deleted (by this function). -- -- |Frees the cached definition files of the context.-{#fun grib_context_delete as ^ { `GribContext' } -> `()' #}+{#fun unsafe grib_context_delete as ^ { `GribContext' } -> `()' #} -- void grib_gts_header_on(grib_context* c); -- -- |Set the gts header mode on. The GTS headers will be preserved.-{#fun grib_gts_header_on as ^ { `GribContext' } -> `()' #}+{#fun unsafe grib_gts_header_on as ^ { `GribContext' } -> `()' #} -- void grib_gts_header_off(grib_context* c); -- -- |Set the gts header mode off. The GTS headers will be deleted.-{#fun grib_gts_header_off as ^ { `GribContext' } -> `()' #}+{#fun unsafe grib_gts_header_off as ^ { `GribContext' } -> `()' #} -- void grib_gribex_mode_on(grib_context* c); -- -- |Set the gribex mode on. Grib files will be compatible with -- gribex.-{#fun grib_gribex_mode_on as ^ { `GribContext' } -> `()' #}+{#fun unsafe grib_gribex_mode_on as ^ { `GribContext' } -> `()' #} -- int grib_get_gribex_mode(grib_context* c); -- -- |Get the gribex mode.-{#fun grib_get_gribex_mode as ^ { `GribContext' } -> `Bool' #}+{#fun unsafe grib_get_gribex_mode as ^ { `GribContext' } -> `Bool' #} -- void grib_gribex_mode_off(grib_context* c); -- -- |Set the gribex mode off. Grib files won't be always compatible -- with gribex.-{#fun grib_gribex_mode_off as ^ { `GribContext' } -> `()' #}---- void grib_context_set_memory_proc(grib_context* c, grib_malloc_proc griballoc,--- grib_free_proc gribfree,--- grib_realloc_proc gribrealloc);------ |Sets memory procedures of the context.-{#fun grib_context_set_memory_proc as ^ {- `GribContext'- , `GribMallocProc'- , `GribFreeProc'- , `GribReallocProc'- } -> `()' #}---- void grib_context_set_persistent_memory_proc(grib_context* c,--- grib_malloc_proc griballoc,--- grib_free_proc gribfree);------ |Sets memory procedures of the context for persistent data.-{#fun grib_context_set_persistent_memory_proc as ^ {- `GribContext'- , `GribMallocProc'- , `GribFreeProc'- } -> `()' #}---- void grib_context_set_buffer_memory_proc(grib_context* c,--- grib_malloc_proc griballoc,--- grib_free_proc gribfree,--- grib_realloc_proc gribrealloc);------ |Sets memory procedures of the context for large buffers.-{#fun grib_context_set_buffer_memory_proc as ^ {- `GribContext'- , `GribMallocProc'- , `GribFreeProc'- , `GribReallocProc'- } -> `()' #}---- void grib_context_set_print_proc(grib_context* c, grib_print_proc printp);------ |Sets the context printing procedure used for user interaction.-{#fun grib_context_set_print_proc as ^ {- `GribContext'- , `GribPrintProc'- } -> `()' #}---- void grib_context_set_logging_proc(grib_context* c, grib_log_proc logp);------ |Sets the context logging procedure used for system (warning,--- errors, infos ...) messages.-{#fun grib_context_set_logging_proc as ^ {- `GribContext'- , `GribLogProc'- } -> `()' #}+{#fun unsafe grib_gribex_mode_off as ^ { `GribContext' } -> `()' #} -- void grib_multi_support_on(grib_context* c); -- -- |Turn on support for multiple fields in single grib messages.-{#fun grib_multi_support_on as ^ { `GribContext' } -> `()' #}+{#fun unsafe grib_multi_support_on as ^ { `GribContext' } -> `()' #} -- void grib_multi_support_off(grib_context* c); -- -- |Turn off support for multiple fields in single grib messages.-{#fun grib_multi_support_off as ^ { `GribContext' } -> `()' #}+{#fun unsafe grib_multi_support_off as ^ { `GribContext' } -> `()' #}
src/Data/Grib/Raw/Exception.chs view
@@ -25,8 +25,8 @@ , ErrorCode(..) ) where -import Control.Exception-import Data.Typeable+import Control.Exception ( Exception )+import Data.Typeable ( Typeable ) #include <grib_api.h>
src/Data/Grib/Raw/Handle.chs view
@@ -45,8 +45,8 @@ , gribCountInFile ) where -import Foreign-import Foreign.C+import Foreign ( Ptr, alloca, peek, with )+import Foreign.C ( CSize, withCString ) {#import Data.Grib.Raw.CFile #} {#import Data.Grib.Raw.Context #}@@ -78,7 +78,7 @@ -- int grib_count_in_file(grib_context *c, FILE *f, int *n); -- -- |Counts the messages contained in a file resource.-{#fun grib_count_in_file as ^ {+{#fun unsafe grib_count_in_file as ^ { `GribContext' , `CFilePtr' , alloca- `Int' peekIntegral*@@ -90,7 +90,7 @@ -- -- The file is read until a message is found. The message is then -- copied.-{#fun grib_handle_new_from_file as ^ {+{#fun unsafe grib_handle_new_from_file as ^ { `GribContext' , `CFilePtr' , alloca- `CInt' checkStatusPtr*-@@ -100,7 +100,7 @@ -- -- |Write a coded message to a file given its name and the C file mode -- string, in that order.-{#fun grib_write_message as ^ {+{#fun unsafe grib_write_message as ^ { `GribHandle' , withCString* `FilePath' , `String'@@ -121,7 +121,7 @@ -- -- __WARNING!__ This method does not handle a message of zero length -- gracefully.-{#fun grib_handle_new_from_message as ^ {+{#fun unsafe grib_handle_new_from_message as ^ { `GribContext' , id `Message' , `Int'@@ -135,7 +135,7 @@ -- The message will not be freed at the end. The message will be -- copied as soon as a modification is needed. This function works -- also with multi field messages.-{#fun grib_handle_new_from_multi_message as ^ {+{#fun unsafe grib_handle_new_from_multi_message as ^ { `GribContext' , with* `Message' peek* , withIntegral* `Int' peekIntegral*@@ -154,7 +154,7 @@ -- -- * @NullPtrReturned@ if the message is invalid or a problem is -- encountered.-{#fun grib_handle_new_from_message_copy as ^ {+{#fun unsafe grib_handle_new_from_message_copy as ^ { `GribContext' , id `Message' , `Int'@@ -173,7 +173,7 @@ -- -- * @NullPtrReturned@ if the resource is invalid or a problem is -- encountered.-{#fun grib_handle_new_from_template as ^ {+{#fun unsafe grib_handle_new_from_template as ^ { `GribContext' , `String' } -> `GribHandle' checkHandle* #}@@ -189,7 +189,7 @@ -- -- * @NullPtrReturned@ if the resource is invalid or a problem is -- encountered.-{#fun grib_handle_new_from_samples as ^ {+{#fun unsafe grib_handle_new_from_samples as ^ { `GribContext' -- ^the context from which the handle will be -- created (NULL for default context) , `String' -- ^the resource name@@ -205,7 +205,9 @@ -- -- * @NullPtrReturned@ if the message is invalid or a problem is -- encountered.-{#fun grib_handle_clone as ^ { `GribHandle' } -> `GribHandle' checkHandle* #}+{#fun unsafe grib_handle_clone as ^ {+ `GribHandle'+ } -> `GribHandle' checkHandle* #} -- typedef struct grib_multi_handle grib_multi_handle; --@@ -231,7 +233,7 @@ -- This operation may fail with: -- -- * @NullPtrReturned@ if a problem is encountered.-{#fun grib_multi_handle_new as ^ {+{#fun unsafe grib_multi_handle_new as ^ { `GribContext' } -> `GribMultiHandle' checkMultiHandle* #} @@ -240,7 +242,7 @@ -- -- |Append the sections starting with start_section of the message -- pointed by h at the end of the multi field handle mh.-{#fun grib_multi_handle_append as ^ {+{#fun unsafe grib_multi_handle_append as ^ { `GribHandle' , `Int' , `GribMultiHandle'@@ -249,7 +251,7 @@ -- int grib_multi_handle_write(grib_multi_handle* mh, FILE* f); -- -- |Write a multi field handle in a file.-{#fun grib_multi_handle_write as ^ {+{#fun unsafe grib_multi_handle_write as ^ { `GribMultiHandle', `CFilePtr' } -> `()' checkStatus*- #}@@ -258,7 +260,7 @@ -- size_t *message_length); -- -- |Getting the message attached to a handle.-{#fun grib_get_message as ^ {+{#fun unsafe grib_get_message as ^ { `GribHandle' , alloca- `Message' peek* , alloca- `Int' peekIntegral*@@ -273,7 +275,7 @@ -- -- * @isGribException GribBufferTooSmall@ if the allocated message -- is too small.-{#fun grib_get_message_copy as ^ {+{#fun unsafe grib_get_message_copy as ^ { `GribHandle' -- ^the grib handle to which the buffer should be returned , id `Message' id
src/Data/Grib/Raw/Index.chs view
@@ -40,13 +40,14 @@ , gribHandleNewFromIndex ) where -import Foreign-import Foreign.C+import Foreign ( Ptr, alloca )+import Foreign.C ( CDouble, CLong, CSize, CString, peekCString, withCString ) {#import Data.Grib.Raw.Context #} {#import Data.Grib.Raw.Handle #} import Data.Grib.Raw.Marshal + #include <grib_api.h> {#typedef size_t CSize #}@@ -64,7 +65,7 @@ -- |Create a new index from a file. -- -- The file is indexed with the keys in argument.-{#fun grib_index_new_from_file as ^ {+{#fun unsafe grib_index_new_from_file as ^ { `GribContext' -- ^context , withCString* `FilePath'@@ -82,7 +83,7 @@ -- grib_index* grib_index_new(grib_context* c, const char* keys, int *err); -- -- |Create a new index based on a set of keys.-{#fun grib_index_new as ^ {+{#fun unsafe grib_index_new as ^ { `GribContext' -- ^context , withJoinedCString* `[Key]'@@ -98,7 +99,7 @@ -- int grib_index_add_file(grib_index *index, const char *filename); -- -- |Indexes the file given in argument in the index given in argument.-{#fun grib_index_add_file as ^ {+{#fun unsafe grib_index_add_file as ^ { `GribIndex' , withCString* `FilePath' } -> `()' checkStatus*- #}@@ -106,7 +107,7 @@ -- int grib_index_write(grib_index *index, const char *filename); -- -- |Write the index and its messages to file.-{#fun grib_index_write as ^ {+{#fun unsafe grib_index_write as ^ { `GribIndex' , withCString* `FilePath' } -> `()' checkStatus*- #}@@ -114,7 +115,7 @@ -- grib_index* grib_index_read(grib_context* c, const char* filename, int *err); -- -- |Read messages and their index from a file.-{#fun grib_index_read as ^ {+{#fun unsafe grib_index_read as ^ { `GribContext' , withCString* `FilePath' , alloca- `CInt' checkStatusPtr*-@@ -126,7 +127,7 @@ -- in the index. -- -- The key must belong to the index.-{#fun grib_index_get_size as ^ {+{#fun unsafe grib_index_get_size as ^ { `GribIndex' , withCString* `Key' , alloca- `Int' peekIntegral*@@ -160,8 +161,8 @@ -> IO [Int] -- ^an IO action that will return the -- data in a list gribIndexGetLong idx key ls n = withGribIndex idx $ \idx' ->- map fromIntegral <$> getArray (cCall idx') key ls n- where cCall = {#call grib_index_get_long as gribIndexGetLong'_ #}+ fmap (map fromIntegral) $ getArray (cCall idx') key ls n+ where cCall = {#call unsafe grib_index_get_long #} -- int grib_index_get_double(grib_index* index, const char* key, -- double* values, size_t *size);@@ -193,8 +194,8 @@ -> IO [Double] -- ^an IO action that will return -- the data in a list gribIndexGetDouble idx key ds n = withGribIndex idx $ \idx' ->- map realToFrac <$> getArray (cCall idx') key ds n- where cCall = {#call grib_index_get_double as gribIndexGetDouble'_ #}+ fmap (map realToFrac) $ getArray (cCall idx') key ds n+ where cCall = {#call unsafe grib_index_get_double #} -- int grib_index_get_string(grib_index* index, const char* key, char** values, -- size_t *size);@@ -232,7 +233,7 @@ -- the data in a list gribIndexGetString idx key ss n = withGribIndex idx $ \idx' -> getArray (cCall idx') key ss n >>= mapM peekCString- where cCall = {#call grib_index_get_string as gribIndexGetString'_ #}+ where cCall = {#call unsafe grib_index_get_string #} -- int grib_index_select_long(grib_index* index, const char* key, long value); --@@ -242,7 +243,7 @@ -- value is a long. The key must have been created with long type or -- have long as native type if the type was not explicitly defined in -- the index creation.-{#fun grib_index_select_long as ^ {+{#fun unsafe grib_index_select_long as ^ { `GribIndex' , withCString* `Key' , `Int'@@ -257,13 +258,14 @@ -- value is a double. The key must have been created with double type -- or have double as native type if the type was not explicitly -- defined in the index creation.-{#fun grib_index_select_double as ^ {+{#fun unsafe grib_index_select_double as ^ { `GribIndex' , withCString* `Key' , `Double' } -> `()' checkStatus*- #} --- int grib_index_select_string(grib_index* index, const char* key, char* value);+-- int grib_index_select_string(grib_index* index, const char* key,+-- char* value); -- -- |Select the message subset with key==value. --@@ -271,7 +273,7 @@ -- value is a string. The key must have been created with string type -- or have string as native type if the type was not explicitly -- defined in the index creation.-{#fun grib_index_select_string as ^ {+{#fun unsafe grib_index_select_string as ^ { `GribIndex' , withCString* `Key' , `String'@@ -290,7 +292,7 @@ -- -- * @isGribException GribEndOfIndex@ when no more handles are -- available from the index.-{#fun grib_handle_new_from_index as ^ {+{#fun unsafe grib_handle_new_from_index as ^ { `GribIndex' , alloca- `CInt' checkStatusPtr*- } -> `GribHandle' #}
src/Data/Grib/Raw/Iterator.chs view
@@ -26,13 +26,13 @@ , withGribIterator ) where -import Control.Exception (bracket)-import Foreign-import Foreign.C+import Control.Exception ( bracket )+import Foreign ( alloca ) {#import Data.Grib.Raw.Handle #} import Data.Grib.Raw.Marshal + #include <grib_api.h> -- typedef struct grib_iterator grib_iterator;@@ -57,7 +57,7 @@ -- 'gribIteratorDelete'. However, due to the reason given in that -- function, 'withGribIterator' should be preferred over this -- function.-{#fun grib_iterator_new as ^ {+{#fun unsafe grib_iterator_new as ^ { `GribHandle' -- ^the handle from which the iterator will be created , `Int'@@ -75,7 +75,7 @@ -- This function returns a tuple @(status, latitude, longitude, -- value)@, where @status@ is @True@ if successful and @False@ if no -- more data is available.-{#fun grib_iterator_next as ^ {+{#fun unsafe grib_iterator_next as ^ { `GribIterator' , alloca- `Double' peekReal* , alloca- `Double' peekReal*@@ -86,7 +86,7 @@ -- double* value); -- -- |Like 'gribIteratorNext', but return the previous value instead.-{#fun grib_iterator_previous as ^ {+{#fun unsafe grib_iterator_previous as ^ { `GribIterator' , alloca- `Double' peekReal* , alloca- `Double' peekReal*@@ -96,12 +96,14 @@ -- int grib_iterator_has_next(grib_iterator *i); -- -- |Test procedure for values in an iterator.-{#fun grib_iterator_has_next as ^ { `GribIterator' } -> `Bool' #}+{#fun unsafe grib_iterator_has_next as ^ { `GribIterator' } -> `Bool' #} -- int grib_iterator_reset(grib_iterator *i); -- -- |Reset the iterator.-{#fun grib_iterator_reset as ^ { `GribIterator' } -> `()' checkStatus*- #}+{#fun unsafe grib_iterator_reset as ^ {+ `GribIterator'+ } -> `()' checkStatus*- #} -- int grib_iterator_delete(grib_iterator *i); --@@ -111,7 +113,9 @@ -- collected by the time this function is called, the behavior is -- undefined. Because of this, 'withGribIterator' should be preferred -- over directly using 'gribIteratorNew' and this function.-{#fun grib_iterator_delete as ^ { `GribIterator' } -> `()' checkStatus*- #}+{#fun unsafe grib_iterator_delete as ^ {+ `GribIterator'+ } -> `()' checkStatus*- #} -- |Safely create, use and delete a 'GribIterator'. --
src/Data/Grib/Raw/KeysIterator.chs view
@@ -31,11 +31,11 @@ , gribKeysIteratorSetFlags ) where -import Control.Exception (bracket, throw)-import Foreign-import Foreign.C+import Control.Exception ( bracket, throw )+import Foreign ( nullPtr )+import Foreign.C ( peekCString ) -{#import Data.Grib.Raw.Exception #}+import Data.Grib.Raw.Exception {#import Data.Grib.Raw.Handle #} import Data.Grib.Raw.Marshal @@ -81,7 +81,7 @@ -- -- * @NullPtrReturned@ if the handle is invalid or the memory -- allocation fails.-{#fun grib_keys_iterator_new as ^ {+{#fun unsafe grib_keys_iterator_new as ^ { `GribHandle' -- ^the handle whose keys you want to iterate , fromFlagList `[GribKeysIteratorFlag]'@@ -100,13 +100,13 @@ -- int grib_keys_iterator_next(grib_keys_iterator *kiter); -- -- |Try to step to the next key and return @True@ if successful.-{#fun grib_keys_iterator_next as ^ { `GribKeysIterator' } -> `Bool' #}+{#fun unsafe grib_keys_iterator_next as ^ { `GribKeysIterator' } -> `Bool' #} -- const char* grib_keys_iterator_get_name(grib_keys_iterator *kiter); -- -- |Get the key name from the iterator.-{#fun grib_keys_iterator_get_name as ^ {- `GribKeysIterator'+{#fun unsafe grib_keys_iterator_get_name as ^ {+ `GribKeysIterator' } -> `Key' peekCString* #} -- int grib_keys_iterator_delete(grib_keys_iterator* kiter);@@ -118,25 +118,25 @@ -- undefined. Because of this, 'withGribKeysIterator' should be -- preferred over directly using 'gribKeysIteratorNew' and this -- function.-{#fun grib_keys_iterator_delete as ^ {- `GribKeysIterator'+{#fun unsafe grib_keys_iterator_delete as ^ {+ `GribKeysIterator' } -> `()' checkStatus*- #} -- int grib_keys_iterator_rewind(grib_keys_iterator* kiter); -- -- |Rewind the iterator.-{#fun grib_keys_iterator_rewind as ^ {- `GribKeysIterator'+{#fun unsafe grib_keys_iterator_rewind as ^ {+ `GribKeysIterator' } -> `()' checkStatus*- #} -- int grib_keys_iterator_set_flags(grib_keys_iterator *kiter, -- unsigned long flags); -- -- |Update the flags of the iterator.-{#fun grib_keys_iterator_set_flags as ^ {+{#fun unsafe grib_keys_iterator_set_flags as ^ { `GribKeysIterator' , fromFlagList `[GribKeysIteratorFlag]'- } -> `()' checkStatus*- #}+ } -> `()' checkStatus*- #} -- |Safely create, use and delete a 'GribKeysIterator'. --
src/Data/Grib/Raw/Marshal.hs view
@@ -30,11 +30,13 @@ , getArray ) where -import Control.Exception (throw, throwIO)-import Control.Monad ((>=>))-import Data.List (intercalate)-import Foreign-import Foreign.C+import Control.Exception ( throw, throwIO )+import Control.Monad ( (>=>) )+import Data.List ( intercalate )+import Foreign ( FinalizerPtr, ForeignPtr, Ptr, Storable, (.|.), bit+ , clearBit, maybeWith, newForeignPtr, nullPtr, peek+ , peekArray, with, withArrayLen )+import Foreign.C ( CInt, CString, withCString ) import Data.Grib.Raw.Exception import Data.Grib.Raw.Types@@ -48,11 +50,12 @@ checkStatusPtr = peek >=> checkStatus fromFlagList :: (Enum a, Integral b) => [a] -> b-fromFlagList = fromIntegral . foldr ((.|.) . fromEnum) zeroBits+fromFlagList = fromIntegral . foldr ((.|.) . fromEnum) zeroBits'+ -- Data.Bits.zeroBits is only available since base 4.7.0.0.+ where zeroBits' = clearBit (bit 0) 0 maybeWithCString :: Maybe String -> (CString -> IO a) -> IO a-maybeWithCString (Just s) f = withCString s f-maybeWithCString Nothing f = f nullPtr+maybeWithCString = maybeWith withCString peekIntegral :: (Integral a, Storable a, Num b) => Ptr a -> IO b peekIntegral = fmap fromIntegral . peek@@ -86,7 +89,7 @@ checkForeignPtr :: (ForeignPtr a -> a) -> FinalizerPtr a -> Ptr a -> IO a checkForeignPtr makeA finalizer p | p == nullPtr = throw NullPtrReturned- | otherwise = makeA <$> newForeignPtr finalizer p+ | otherwise = fmap makeA $ newForeignPtr finalizer p getArray :: (Storable a, Integral b, Storable b) => (CString -> Ptr a -> Ptr b -> IO CInt)@@ -94,4 +97,4 @@ getArray cCall key xs n = withCString key $ \key' -> with (fromIntegral n) $ \n' -> do cCall key' xs n' >>= checkStatus- fromIntegral <$> peek n' >>= flip peekArray xs+ fmap fromIntegral (peek n') >>= flip peekArray xs
src/Data/Grib/Raw/Nearest.chs view
@@ -28,8 +28,9 @@ ) where import Control.Exception (bracket)-import Foreign-import Foreign.C+import Foreign ( Ptr, Storable, alloca, allocaArray, fromBool+ , peekArray, with, withArray )+import Foreign.C ( CSize ) {#import Data.Grib.Raw.Handle #} import Data.Grib.Raw.Marshal@@ -64,7 +65,7 @@ -- The returned object needs to be manually deleted with -- 'gribNearestDelete'. This is handled automatically by -- 'withGribNearest'.-{#fun grib_nearest_new as ^ {+{#fun unsafe grib_nearest_new as ^ { `GribHandle' , alloca- `CInt' checkStatusPtr*- } -> `GribNearest' #}@@ -81,7 +82,7 @@ -- call to another you can use GRIB_NEAREST_SAME_POINT. The same is -- valid for the grid. Flags can be used together doing a bitwise -- OR. The distances are given in kilometres.-{#fun grib_nearest_find as ^ {+{#fun unsafe grib_nearest_find as ^ { `GribNearest' , `GribHandle' , `Double'@@ -103,7 +104,7 @@ -- int grib_nearest_delete(grib_nearest *nearest); -- -- |Frees an nearest from memory.-{#fun grib_nearest_delete as ^ { `GribNearest' } -> `()' checkStatus* #}+{#fun unsafe grib_nearest_delete as ^ { `GribNearest' } -> `()' checkStatus* #} -- int grib_nearest_find_multiple(grib_handle* h, int is_lsm, double* inlats, -- double* inlons, long npoints, double* outlats,@@ -149,15 +150,14 @@ allocaArray n $ \vals -> allocaArray n $ \dists -> allocaArray n $ \is -> do- status <- cCall h' lsm' ilats' ilons' n' olats olons vals dists is- checkStatus status- olats' <- map realToFrac <$> peekArray n olats- olons' <- map realToFrac <$> peekArray n olons- vals' <- map realToFrac <$> peekArray n vals- dists' <- map realToFrac <$> peekArray n dists- is' <- map fromIntegral <$> peekArray n is+ cCall h' lsm' ilats' ilons' n' olats olons vals dists is >>= checkStatus+ olats' <- fmap (map realToFrac) (peekArray n olats)+ olons' <- fmap (map realToFrac) (peekArray n olons)+ vals' <- fmap (map realToFrac) (peekArray n vals)+ dists' <- fmap (map realToFrac) (peekArray n dists)+ is' <- fmap (map fromIntegral) (peekArray n is) return (olats', olons', vals', dists', is')- where cCall = {#call grib_nearest_find_multiple as gribNearestFindMultiple'_ #}+ where cCall = {#call unsafe grib_nearest_find_multiple #} -- |Safely create, use and delete a 'GribNearest'. --
src/Data/Grib/Raw/Types.hs view
@@ -16,8 +16,8 @@ , Message ) where -import Foreign-import Foreign.C+import Foreign ( Ptr )+import Foreign.C ( CUChar ) -- |A pointer to a number of bytes in memory.
src/Data/Grib/Raw/Value.chs view
@@ -41,12 +41,14 @@ , gribCopyNamespace ) where -import Foreign-import Foreign.C+import Foreign ( Ptr, alloca, allocaArray, peek, peekArray, with+ , withArrayLen )+import Foreign.C ( CDouble, CLong, CSize, CString, peekCStringLen, withCString ) {#import Data.Grib.Raw.Handle #} import Data.Grib.Raw.Marshal + #include <grib_api.h> {#typedef size_t CSize #}@@ -59,7 +61,7 @@ -- This operation may fail with: -- -- * @isGribException GribNotFound@ if the key is missing.-{#fun grib_get_offset as ^ {+{#fun unsafe grib_get_offset as ^ { `GribHandle' , withCString* `Key' , alloca- `Int' peekIntegral*@@ -73,7 +75,7 @@ -- This operation may fail with: -- -- * @isGribException GribNotFound@ if the key is missing.-{#fun grib_get_size as ^ {+{#fun unsafe grib_get_size as ^ { `GribHandle' , withCString* `Key' , alloca- `Int' peekIntegral*@@ -87,7 +89,7 @@ -- This operation may fail with: -- -- * @isGribException GribNotFound@ if the key is missing.-{#fun grib_get_length as ^ {+{#fun unsafe grib_get_length as ^ { `GribHandle' , withCString* `Key' , alloca- `Int' peekIntegral*@@ -101,7 +103,7 @@ -- This operation may fail with: -- -- * @isGribException GribNotFound@ if the key is missing.-{#fun grib_get_long as ^ {+{#fun unsafe grib_get_long as ^ { `GribHandle' , withCString* `Key' , alloca- `Int' peekIntegral*@@ -115,7 +117,7 @@ -- This operation may fail with: -- -- * @isGribException GribNotFound@ if the key is missing.-{#fun grib_get_double as ^ {+{#fun unsafe grib_get_double as ^ { `GribHandle' , withCString* `Key' , alloca- `Double' peekReal*@@ -134,7 +136,7 @@ -- * @isGribException GribNotFound@ if the key is missing. -- -- __WARNING!__ There is no check if the index is out of bounds.-{#fun grib_get_double_element as ^ {+{#fun unsafe grib_get_double_element as ^ { `GribHandle' , withCString* `Key' , `Int'@@ -162,8 +164,8 @@ withArrayLen (map fromIntegral is) $ \n is' -> allocaArray n $ \ds -> do cCall h' key' is' (fromIntegral n) ds >>= checkStatus- map realToFrac <$> peekArray n ds- where cCall = {#call grib_get_double_elements as gribGetDoubleElements'_ #}+ fmap (map realToFrac) $ peekArray n ds+ where cCall = {#call unsafe grib_get_double_elements #} -- int grib_get_string(grib_handle* h, const char* key, char* mesg, -- size_t *length);@@ -199,8 +201,8 @@ withCString key $ \key' -> with (fromIntegral n) $ \n' -> do cCall h' key' cs n' >>= checkStatus- fromIntegral . subtract 1 <$> peek n' >>= curry peekCStringLen cs- where cCall = {#call grib_get_string as gribGetString'_ #}+ fmap (fromIntegral . subtract 1) (peek n') >>= curry peekCStringLen cs+ where cCall = {#call unsafe grib_get_string #} -- int grib_get_bytes(grib_handle* h, const char* key, unsigned char* bytes, -- size_t *length);@@ -216,7 +218,7 @@ -- -- * @isGribException GribArrayTooSmall@ if the allocated array is -- too small.-{#fun grib_get_bytes as ^ {+{#fun unsafe grib_get_bytes as ^ { `GribHandle' -- ^the handle to get the data from , withCString* `Key'@@ -263,8 +265,8 @@ -> IO [Double] -- ^an IO action that will return the -- data in a list gribGetDoubleArray h key ds n = withGribHandle h $ \h' ->- map realToFrac <$> getArray (cCall h') key ds n- where cCall = {#call grib_get_double_array as gribGetDoubleArray'_ #}+ fmap (map realToFrac) $ getArray (cCall h') key ds n+ where cCall = {#call unsafe grib_get_double_array #} -- int grib_get_long_array(grib_handle* h, const char* key, long* vals, -- size_t *length);@@ -299,8 +301,8 @@ -> IO [Int] -- ^an IO action that will return the -- data in a list gribGetLongArray h key ls n = withGribHandle h $ \h' ->- map fromIntegral <$> getArray (cCall h') key ls n- where cCall = {#call grib_get_long_array as gribGetLongArray'_ #}+ fmap (map fromIntegral) $ getArray (cCall h') key ls n+ where cCall = {#call unsafe grib_get_long_array #} -- int grib_copy_namespace(grib_handle* dest, const char* name, -- grib_handle* src);@@ -311,7 +313,7 @@ -- This operation may fail with: -- -- * @isGribException GribNotImplemented@.-{#fun grib_copy_namespace as ^ {+{#fun unsafe grib_copy_namespace as ^ { `GribHandle' -- ^destination handle , maybeWithCString* `Maybe String' -- ^namespace (pass @Nothing@ -- to copy all keys)@@ -331,7 +333,7 @@ -- * @isGribException GribNotFound@ if the key is missing; or -- -- * @isGribException GribReadOnly@ if the key is read-only.-{#fun grib_set_long as ^ {+{#fun unsafe grib_set_long as ^ { `GribHandle' , withCString* `Key' , `Int'@@ -349,7 +351,7 @@ -- * @isGribException GribNotFound@ if the key is missing; or -- -- * @isGribException GribReadOnly@ if the key is read-only.-{#fun grib_set_double as ^ {+{#fun unsafe grib_set_double as ^ { `GribHandle' , withCString* `Key' , `Double'@@ -377,8 +379,8 @@ withCString key $ \key' -> withCString msg $ \msg' -> with (fromIntegral $ length msg) $ \n ->- cCall h' key' msg' n >>= checkStatus >> fromIntegral <$> peek n- where cCall = {#call grib_set_string as gribSetString'_ #}+ cCall h' key' msg' n >>= checkStatus >> fmap fromIntegral (peek n)+ where cCall = {#call unsafe grib_set_string #} -- int grib_set_bytes(grib_handle* h, const char* key, -- const unsigned char* bytes, size_t *length);@@ -390,7 +392,7 @@ -- This operation may fail with: -- -- * @isGribException GribNotFound@ if the key is missing.-{#fun grib_set_bytes as ^ {+{#fun unsafe grib_set_bytes as ^ { `GribHandle' , withCString* `Key' , id `Bytes'@@ -412,7 +414,7 @@ -- -- __WARNING!__ Strange things seem to happen if an empty list is -- passed in.-{#fun grib_set_double_array as ^ {+{#fun unsafe grib_set_double_array as ^ { `GribHandle' , withCString* `Key' , withRealArrayLen* `[Double]'&@@ -430,7 +432,7 @@ -- * @isGribException GribNotFound@ if the key is missing; or -- -- * @isGribException GribReadOnly@ if the key is read-only.-{#fun grib_set_long_array as ^ {+{#fun unsafe grib_set_long_array as ^ { `GribHandle' , withCString* `Key' , withIntegralArrayLen* `[Int]'&
test/Data/Grib/Raw/CFileSpec.hs view
@@ -10,16 +10,16 @@ Unit and regression tests for Data.Grib.Raw.CFile. -} -module Data.Grib.Raw.CFileSpec (main, spec) where+module Data.Grib.Raw.CFileSpec ( main, spec ) where -import Control.Exception (bracket)-import Foreign-import System.Directory (getTemporaryDirectory, removeFile)-import System.IO (hClose, openTempFile)-import System.IO.Error (isDoesNotExistError)+import Control.Exception ( bracket )+import Foreign ( nullPtr )+import System.Directory ( getTemporaryDirectory, removeFile )+import System.IO ( hClose, openTempFile )+import System.IO.Error ( isDoesNotExistError ) import Test.Hspec-import Data.Grib.Raw.CFile+import Data.Grib.Raw main :: IO ()
test/Data/Grib/Raw/ContextSpec.hs view
@@ -10,12 +10,12 @@ Unit and regression tests for Data.Grib.Raw.Context. -} -module Data.Grib.Raw.ContextSpec (main, spec) where+module Data.Grib.Raw.ContextSpec ( main, spec ) where -import Control.Exception (bracket)+import Control.Exception ( bracket ) import Test.Hspec-import Data.Grib.Raw.Context+import Data.Grib.Raw main :: IO ()
test/Data/Grib/Raw/HandleSpec.hs view
@@ -10,14 +10,13 @@ Unit and regression tests for Data.Grib.Raw.Handle. -} -module Data.Grib.Raw.HandleSpec (main, spec) where+module Data.Grib.Raw.HandleSpec ( main, spec ) where -import Control.Monad (void)-import Foreign (allocaBytes, nullPtr)+import Control.Monad ( void )+import Foreign ( allocaBytes, nullPtr ) import Test.Hspec import Data.Grib.Raw-import Data.Grib.Raw.Exception import Data.Grib.Raw.Test
test/Data/Grib/Raw/IndexSpec.hs view
@@ -10,16 +10,13 @@ Unit and regression tests for Data.Grib.Raw.Index. -} -module Data.Grib.Raw.IndexSpec (main, spec) where+module Data.Grib.Raw.IndexSpec ( main, spec ) where -import Control.Exception (tryJust)-import Control.Monad (guard)-import Data.Either (isRight)-import Foreign (alloca)+import Control.Monad ( void )+import Foreign ( alloca ) import Test.Hspec import Data.Grib.Raw-import Data.Grib.Raw.Exception import Data.Grib.Raw.Test hiding (withRegular1) @@ -64,26 +61,23 @@ it "should succeed after gribIndexSelectLong \"Ni\" 16" $ withRegular1 ["Ni"] $ \idx -> do gribIndexSelectLong idx "Ni" 16 `shouldReturn` ()- tryJust (guard . isGribEndOfIndex) (gribHandleNewFromIndex idx) >>=- (`shouldSatisfy` isRight)+ void $ gribHandleNewFromIndex idx it "should succeed after gribIndexSelectDouble \"yFirst\" 60" $ withRegular1 ["yFirst"] $ \idx -> do gribIndexSelectDouble idx "yFirst" 60 `shouldReturn` ()- tryJust (guard . isGribEndOfIndex) (gribHandleNewFromIndex idx) >>=- (`shouldSatisfy` isRight)+ void $ gribHandleNewFromIndex idx it "should succeed after gribIndexSelectString \"packingtype\" \ \\"grid_simple\"" $ withRegular1 ["packingType"] $ \idx -> do gribIndexSelectString idx "packingType" "grid_simple" `shouldReturn` ()- tryJust (guard . isGribEndOfIndex) (gribHandleNewFromIndex idx) >>=- (`shouldSatisfy` isRight)+ void $ gribHandleNewFromIndex idx it "should fail with GribEndOfIndex after selecting nothing" $ withRegular1 ["Ni"] $ \idx -> do gribIndexSelectLong idx "Ni" 0 `shouldReturn` ()- gribHandleNewFromIndex idx `shouldThrow` isGribEndOfIndex+ void $ gribHandleNewFromIndex idx `shouldThrow` isGribEndOfIndex describe "gribIndexNew and gribIndexAddFile" $ it "should create a new index and add a file to it" $ do
test/Data/Grib/Raw/IteratorSpec.hs view
@@ -10,7 +10,7 @@ Unit and regression tests for Data.Grib.Raw.Iterator. -} -module Data.Grib.Raw.IteratorSpec (main, spec) where+module Data.Grib.Raw.IteratorSpec ( main, spec ) where import Test.Hspec import Data.Grib.Raw
test/Data/Grib/Raw/KeysIteratorSpec.hs view
@@ -10,7 +10,7 @@ Unit and regression tests for Data.Grib.Raw.KeysIterator. -} -module Data.Grib.Raw.KeysIteratorSpec (main, spec) where+module Data.Grib.Raw.KeysIteratorSpec ( main, spec ) where import Test.Hspec import Data.Grib.Raw@@ -28,19 +28,21 @@ gribKeysIteratorNext kiter `shouldReturn` True gribKeysIteratorGetName kiter `shouldReturn` "parametersVersion" - it "should return UseEcmfConventions in the 2nd step with no filters" $- withRegular1 $ \h -> withGribKeysIterator h [] Nothing $ \kiter -> do- gribKeysIteratorNext kiter `shouldReturn` True- gribKeysIteratorNext kiter `shouldReturn` True- gribKeysIteratorGetName kiter `shouldReturn` "UseEcmfConventions"- it "should return totalLength in the 1st step with SkipComputed" $ let flags = [GribKeysIteratorSkipComputed] in withRegular1 $ \h -> withGribKeysIterator h flags Nothing $ \kiter -> do gribKeysIteratorNext kiter `shouldReturn` True gribKeysIteratorGetName kiter `shouldReturn` "totalLength" - it "should return totalLength when SkipComputed is set after creation" $+ it "should return UseEcmfConventions in the 2nd step with SkipComputed" $+ let flags = [GribKeysIteratorSkipComputed] in+ withRegular1 $ \h -> withGribKeysIterator h flags Nothing $ \kiter -> do+ gribKeysIteratorNext kiter `shouldReturn` True+ gribKeysIteratorNext kiter `shouldReturn` True+ gribKeysIteratorGetName kiter `shouldReturn` "editionNumber"++ skipIfGribApiVersion (< 11300) $ -- GRIB API issue GRIB-566+ it "should return totalLength when SkipComputed is set after creation" $ let flags = [GribKeysIteratorSkipComputed] in withRegular1 $ \h -> withGribKeysIterator h [] Nothing $ \kiter -> do gribKeysIteratorSetFlags kiter flags
test/Data/Grib/Raw/NearestSpec.hs view
@@ -10,7 +10,7 @@ Unit and regression tests for Data.Grib.Raw.Nearest. -} -module Data.Grib.Raw.NearestSpec (main, spec) where+module Data.Grib.Raw.NearestSpec ( main, spec ) where import Test.Hspec import Data.Grib.Raw
test/Data/Grib/Raw/Test.hs view
@@ -11,7 +11,8 @@ -} module Data.Grib.Raw.Test- ( safeRemoveFile+ ( skipIfGribApiVersion+ , safeRemoveFile , withGribFile , regular1Path , regular2Path@@ -19,13 +20,19 @@ , withRegular2 ) where -import Control.Exception (tryJust)-import Control.Monad ((>=>), guard, void)-import System.Directory (removeFile)-import System.IO.Error (isDoesNotExistError)+import Control.Exception ( tryJust )+import Control.Monad ( (>=>), guard, void )+import System.Directory ( removeFile )+import System.IO.Error ( isDoesNotExistError )+import Test.Hspec ( SpecWith ) import Data.Grib.Raw ++skipIfGribApiVersion :: (Int -> Bool) -> SpecWith a -> SpecWith a+skipIfGribApiVersion p+ | p gribGetApiVersion = const $ return ()+ | otherwise = id safeRemoveFile :: FilePath -> IO () safeRemoveFile path =
test/Data/Grib/Raw/ValueSpec.hs view
@@ -10,13 +10,12 @@ Unit and regression tests for Data.Grib.Raw.Value. -} -module Data.Grib.Raw.ValueSpec (main, spec) where+module Data.Grib.Raw.ValueSpec ( main, spec ) where -import Foreign+import Foreign ( allocaArray, allocaBytes, nullPtr ) import Test.Hspec import Data.Grib.Raw-import Data.Grib.Raw.Exception import Data.Grib.Raw.Test @@ -276,7 +275,6 @@ `shouldThrow` isGribException GribNotFound describe "gribCopyNamespace" $- it "should fail with GribNotImplemented" $+ it "should succeed to copy namespace ls to itself" $ withRegular1 $ \h ->- gribCopyNamespace h Nothing h- `shouldThrow` isGribException GribNotImplemented+ gribCopyNamespace h (Just "ls") h