    {-# LANGUAGE CPP #-}
    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    module Bindings.HDF5.Dataset
        ( Dataset
        , createDataset
        , createAnonymousDataset
        , openDataset
        , closeDataset

        , getDatasetSpace
        , SpaceStatus(..)
        , getDatasetSpaceStatus
        , getDatasetType

        , getDatasetCreatePList
        , getDatasetAccessPList

        , getDatasetStorageSize
        , getDatasetOffset

        , readDataset
        , readDatasetInto
        , writeDataset

        , setDatasetExtent

        , fillSelection
        ) where

    #if __GLASGOW_HASKELL__ < 710
    import Control.Applicative ((<$>))
    #endif

    import Bindings.HDF5.Core
    import Bindings.HDF5.Dataspace
    import Bindings.HDF5.Datatype.Internal
    import Bindings.HDF5.Error
    import Bindings.HDF5.Object
    import Bindings.HDF5.PropertyList.DAPL
    import Bindings.HDF5.PropertyList.DCPL
    import Bindings.HDF5.PropertyList.DXPL
    import Bindings.HDF5.PropertyList.LCPL
    import Bindings.HDF5.Raw.H5D
    import Bindings.HDF5.Raw.H5I
    import Bindings.HDF5.Raw.H5P
    import Bindings.HDF5.Raw.H5S
    import Control.Monad.ST (RealWorld)
    import qualified Data.ByteString as BS
    import qualified Data.Vector.Storable as SV
    import qualified Data.Vector.Storable.Mutable as SV.M
    import Foreign.Ptr.Conventions

    newtype Dataset = Dataset HId_t
        deriving (Dataset -> Dataset -> Bool
    (Dataset -> Dataset -> Bool)
    -> (Dataset -> Dataset -> Bool) -> Eq Dataset
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Dataset -> Dataset -> Bool
    == :: Dataset -> Dataset -> Bool
    $c/= :: Dataset -> Dataset -> Bool
    /= :: Dataset -> Dataset -> Bool
    Eq, Dataset -> HId_t
    (Dataset -> HId_t) -> HId Dataset
    forall t. (t -> HId_t) -> HId t
    $chid :: Dataset -> HId_t
    hid :: Dataset -> HId_t
    HId, HId_t -> Dataset
    (HId_t -> Dataset) -> FromHId Dataset
    forall t. (HId_t -> t) -> FromHId t
    $cuncheckedFromHId :: HId_t -> Dataset
    uncheckedFromHId :: HId_t -> Dataset
    FromHId, Dataset -> Bool
    (Dataset -> Bool) -> HDFResultType Dataset
    forall t. (t -> Bool) -> HDFResultType t
    $cisError :: Dataset -> Bool
    isError :: Dataset -> Bool
    HDFResultType)

    instance Object Dataset where
        staticObjectType :: Tagged Dataset (Maybe ObjectType)
    staticObjectType = Maybe ObjectType -> Tagged Dataset (Maybe ObjectType)
    forall {k} (s :: k) b. b -> Tagged s b
    Tagged (ObjectType -> Maybe ObjectType
    forall a. a -> Maybe a
    Just ObjectType
    DatasetObj)

    createDataset :: Location loc
        => loc -> BS.ByteString -> Datatype -> Dataspace -> Maybe LCPL -> Maybe DCPL -> Maybe DAPL -> IO Dataset
    createDataset :: forall loc.
    Location loc =>
    loc
    -> ByteString
    -> Datatype
    -> Dataspace
    -> Maybe LCPL
    -> Maybe DCPL
    -> Maybe DAPL
    -> IO Dataset
    createDataset loc
    loc_id ByteString
    name Datatype
    type_id Dataspace
    space_id Maybe LCPL
    lcpl_id Maybe DCPL
    dcpl_id Maybe DAPL
    dapl_id =
        (HId_t -> Dataset) -> IO HId_t -> IO Dataset
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HId_t -> Dataset
    Dataset (IO HId_t -> IO Dataset) -> IO HId_t -> IO Dataset
    forall a b. (a -> b) -> a -> b
    $
            IO HId_t -> IO HId_t
    forall t. HDFResultType t => IO t -> IO t
    withErrorCheck (IO HId_t -> IO HId_t) -> IO HId_t -> IO HId_t
    forall a b. (a -> b) -> a -> b
    $
                ByteString -> (CString -> IO HId_t) -> IO HId_t
    forall a. ByteString -> (CString -> IO a) -> IO a
    BS.useAsCString ByteString
    name ((CString -> IO HId_t) -> IO HId_t)
    -> (CString -> IO HId_t) -> IO HId_t
    forall a b. (a -> b) -> a -> b
    $ \CString
    cname ->
                    HId_t
    -> CString -> HId_t -> HId_t -> HId_t -> HId_t -> HId_t -> IO HId_t
    h5d_create2 (loc -> HId_t
    forall t. HId t => t -> HId_t
    hid loc
    loc_id) CString
    cname (Datatype -> HId_t
    forall t. HId t => t -> HId_t
    hid Datatype
    type_id) (Dataspace -> HId_t
    forall t. HId t => t -> HId_t
    hid Dataspace
    space_id) (HId_t -> (LCPL -> HId_t) -> Maybe LCPL -> HId_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HId_t
    h5p_DEFAULT LCPL -> HId_t
    forall t. HId t => t -> HId_t
    hid Maybe LCPL
    lcpl_id) (HId_t -> (DCPL -> HId_t) -> Maybe DCPL -> HId_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HId_t
    h5p_DEFAULT DCPL -> HId_t
    forall t. HId t => t -> HId_t
    hid Maybe DCPL
    dcpl_id) (HId_t -> (DAPL -> HId_t) -> Maybe DAPL -> HId_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HId_t
    h5p_DEFAULT DAPL -> HId_t
    forall t. HId t => t -> HId_t
    hid Maybe DAPL
    dapl_id)

    createAnonymousDataset :: Location loc
        => loc -> Datatype -> Dataspace -> Maybe DCPL -> Maybe DAPL -> IO Dataset
    createAnonymousDataset :: forall loc.
    Location loc =>
    loc
    -> Datatype -> Dataspace -> Maybe DCPL -> Maybe DAPL -> IO Dataset
    createAnonymousDataset loc
    loc_id Datatype
    type_id Dataspace
    space_id Maybe DCPL
    dcpl_id Maybe DAPL
    dapl_id =
        (HId_t -> Dataset) -> IO HId_t -> IO Dataset
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HId_t -> Dataset
    Dataset (IO HId_t -> IO Dataset) -> IO HId_t -> IO Dataset
    forall a b. (a -> b) -> a -> b
    $
            IO HId_t -> IO HId_t
    forall t. HDFResultType t => IO t -> IO t
    withErrorCheck (IO HId_t -> IO HId_t) -> IO HId_t -> IO HId_t
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> HId_t -> HId_t -> HId_t -> HId_t -> IO HId_t
    h5d_create_anon (loc -> HId_t
    forall t. HId t => t -> HId_t
    hid loc
    loc_id) (Datatype -> HId_t
    forall t. HId t => t -> HId_t
    hid Datatype
    type_id) (Dataspace -> HId_t
    forall t. HId t => t -> HId_t
    hid Dataspace
    space_id) (HId_t -> (DCPL -> HId_t) -> Maybe DCPL -> HId_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HId_t
    h5p_DEFAULT DCPL -> HId_t
    forall t. HId t => t -> HId_t
    hid Maybe DCPL
    dcpl_id) (HId_t -> (DAPL -> HId_t) -> Maybe DAPL -> HId_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HId_t
    h5p_DEFAULT DAPL -> HId_t
    forall t. HId t => t -> HId_t
    hid Maybe DAPL
    dapl_id)

    openDataset :: Location loc
        => loc -> BS.ByteString -> Maybe DAPL -> IO Dataset
    openDataset :: forall loc.
    Location loc =>
    loc -> ByteString -> Maybe DAPL -> IO Dataset
    openDataset loc
    loc_id ByteString
    name Maybe DAPL
    dapl_id =
        (HId_t -> Dataset) -> IO HId_t -> IO Dataset
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HId_t -> Dataset
    Dataset (IO HId_t -> IO Dataset) -> IO HId_t -> IO Dataset
    forall a b. (a -> b) -> a -> b
    $
            IO HId_t -> IO HId_t
    forall t. HDFResultType t => IO t -> IO t
    withErrorCheck (IO HId_t -> IO HId_t) -> IO HId_t -> IO HId_t
    forall a b. (a -> b) -> a -> b
    $
                ByteString -> (CString -> IO HId_t) -> IO HId_t
    forall a. ByteString -> (CString -> IO a) -> IO a
    BS.useAsCString ByteString
    name ((CString -> IO HId_t) -> IO HId_t)
    -> (CString -> IO HId_t) -> IO HId_t
    forall a b. (a -> b) -> a -> b
    $ \CString
    cname ->
                    HId_t -> CString -> HId_t -> IO HId_t
    h5d_open2 (loc -> HId_t
    forall t. HId t => t -> HId_t
    hid loc
    loc_id) CString
    cname (HId_t -> (DAPL -> HId_t) -> Maybe DAPL -> HId_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HId_t
    h5p_DEFAULT DAPL -> HId_t
    forall t. HId t => t -> HId_t
    hid Maybe DAPL
    dapl_id)

    closeDataset :: Dataset -> IO ()
    closeDataset :: Dataset -> IO ()
    closeDataset (Dataset HId_t
    dset_id) =
        IO HErr_t -> IO ()
    forall t. HDFResultType t => IO t -> IO ()
    withErrorCheck_ (HId_t -> IO HErr_t
    h5d_close HId_t
    dset_id)

    getDatasetSpace :: Dataset -> IO Dataspace
    getDatasetSpace :: Dataset -> IO Dataspace
    getDatasetSpace (Dataset HId_t
    dset_id) =
        HId_t -> Dataspace
    forall t. FromHId t => HId_t -> t
    uncheckedFromHId
        (HId_t -> Dataspace) -> IO HId_t -> IO Dataspace
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> IO HId_t -> IO HId_t
    forall t. HDFResultType t => IO t -> IO t
    withErrorCheck (HId_t -> IO HId_t
    h5d_get_space HId_t
    dset_id)

    data SpaceStatus
        = NotAllocated
        | Allocated
        | PartAllocated
        deriving (SpaceStatus -> SpaceStatus -> Bool
    (SpaceStatus -> SpaceStatus -> Bool)
    -> (SpaceStatus -> SpaceStatus -> Bool) -> Eq SpaceStatus
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: SpaceStatus -> SpaceStatus -> Bool
    == :: SpaceStatus -> SpaceStatus -> Bool
    $c/= :: SpaceStatus -> SpaceStatus -> Bool
    /= :: SpaceStatus -> SpaceStatus -> Bool
    Eq, Eq SpaceStatus
    Eq SpaceStatus =>
    (SpaceStatus -> SpaceStatus -> Ordering)
    -> (SpaceStatus -> SpaceStatus -> Bool)
    -> (SpaceStatus -> SpaceStatus -> Bool)
    -> (SpaceStatus -> SpaceStatus -> Bool)
    -> (SpaceStatus -> SpaceStatus -> Bool)
    -> (SpaceStatus -> SpaceStatus -> SpaceStatus)
    -> (SpaceStatus -> SpaceStatus -> SpaceStatus)
    -> Ord SpaceStatus
    SpaceStatus -> SpaceStatus -> Bool
    SpaceStatus -> SpaceStatus -> Ordering
    SpaceStatus -> SpaceStatus -> SpaceStatus
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: SpaceStatus -> SpaceStatus -> Ordering
    compare :: SpaceStatus -> SpaceStatus -> Ordering
    $c< :: SpaceStatus -> SpaceStatus -> Bool
    < :: SpaceStatus -> SpaceStatus -> Bool
    $c<= :: SpaceStatus -> SpaceStatus -> Bool
    <= :: SpaceStatus -> SpaceStatus -> Bool
    $c> :: SpaceStatus -> SpaceStatus -> Bool
    > :: SpaceStatus -> SpaceStatus -> Bool
    $c>= :: SpaceStatus -> SpaceStatus -> Bool
    >= :: SpaceStatus -> SpaceStatus -> Bool
    $cmax :: SpaceStatus -> SpaceStatus -> SpaceStatus
    max :: SpaceStatus -> SpaceStatus -> SpaceStatus
    $cmin :: SpaceStatus -> SpaceStatus -> SpaceStatus
    min :: SpaceStatus -> SpaceStatus -> SpaceStatus
    Ord, ReadPrec [SpaceStatus]
    ReadPrec SpaceStatus
    Int -> ReadS SpaceStatus
    ReadS [SpaceStatus]
    (Int -> ReadS SpaceStatus)
    -> ReadS [SpaceStatus]
    -> ReadPrec SpaceStatus
    -> ReadPrec [SpaceStatus]
    -> Read SpaceStatus
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS SpaceStatus
    readsPrec :: Int -> ReadS SpaceStatus
    $creadList :: ReadS [SpaceStatus]
    readList :: ReadS [SpaceStatus]
    $creadPrec :: ReadPrec SpaceStatus
    readPrec :: ReadPrec SpaceStatus
    $creadListPrec :: ReadPrec [SpaceStatus]
    readListPrec :: ReadPrec [SpaceStatus]
    Read, Int -> SpaceStatus -> ShowS
    [SpaceStatus] -> ShowS
    SpaceStatus -> String
    (Int -> SpaceStatus -> ShowS)
    -> (SpaceStatus -> String)
    -> ([SpaceStatus] -> ShowS)
    -> Show SpaceStatus
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> SpaceStatus -> ShowS
    showsPrec :: Int -> SpaceStatus -> ShowS
    $cshow :: SpaceStatus -> String
    show :: SpaceStatus -> String
    $cshowList :: [SpaceStatus] -> ShowS
    showList :: [SpaceStatus] -> ShowS
    Show, Int -> SpaceStatus
    SpaceStatus -> Int
    SpaceStatus -> [SpaceStatus]
    SpaceStatus -> SpaceStatus
    SpaceStatus -> SpaceStatus -> [SpaceStatus]
    SpaceStatus -> SpaceStatus -> SpaceStatus -> [SpaceStatus]
    (SpaceStatus -> SpaceStatus)
    -> (SpaceStatus -> SpaceStatus)
    -> (Int -> SpaceStatus)
    -> (SpaceStatus -> Int)
    -> (SpaceStatus -> [SpaceStatus])
    -> (SpaceStatus -> SpaceStatus -> [SpaceStatus])
    -> (SpaceStatus -> SpaceStatus -> [SpaceStatus])
    -> (SpaceStatus -> SpaceStatus -> SpaceStatus -> [SpaceStatus])
    -> Enum SpaceStatus
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: SpaceStatus -> SpaceStatus
    succ :: SpaceStatus -> SpaceStatus
    $cpred :: SpaceStatus -> SpaceStatus
    pred :: SpaceStatus -> SpaceStatus
    $ctoEnum :: Int -> SpaceStatus
    toEnum :: Int -> SpaceStatus
    $cfromEnum :: SpaceStatus -> Int
    fromEnum :: SpaceStatus -> Int
    $cenumFrom :: SpaceStatus -> [SpaceStatus]
    enumFrom :: SpaceStatus -> [SpaceStatus]
    $cenumFromThen :: SpaceStatus -> SpaceStatus -> [SpaceStatus]
    enumFromThen :: SpaceStatus -> SpaceStatus -> [SpaceStatus]
    $cenumFromTo :: SpaceStatus -> SpaceStatus -> [SpaceStatus]
    enumFromTo :: SpaceStatus -> SpaceStatus -> [SpaceStatus]
    $cenumFromThenTo :: SpaceStatus -> SpaceStatus -> SpaceStatus -> [SpaceStatus]
    enumFromThenTo :: SpaceStatus -> SpaceStatus -> SpaceStatus -> [SpaceStatus]
    Enum, SpaceStatus
    SpaceStatus -> SpaceStatus -> Bounded SpaceStatus
    forall a. a -> a -> Bounded a
    $cminBound :: SpaceStatus
    minBound :: SpaceStatus
    $cmaxBound :: SpaceStatus
    maxBound :: SpaceStatus
    Bounded)

    spaceStatusFromCode :: H5D_space_status_t -> SpaceStatus
    spaceStatusFromCode :: H5D_space_status_t -> SpaceStatus
    spaceStatusFromCode H5D_space_status_t
    c
        | H5D_space_status_t
    c H5D_space_status_t -> H5D_space_status_t -> Bool
    forall a. Eq a => a -> a -> Bool
    == H5D_space_status_t
    h5d_SPACE_STATUS_NOT_ALLOCATED   = SpaceStatus
    NotAllocated
        | H5D_space_status_t
    c H5D_space_status_t -> H5D_space_status_t -> Bool
    forall a. Eq a => a -> a -> Bool
    == H5D_space_status_t
    h5d_SPACE_STATUS_ALLOCATED       = SpaceStatus
    Allocated
        | H5D_space_status_t
    c H5D_space_status_t -> H5D_space_status_t -> Bool
    forall a. Eq a => a -> a -> Bool
    == H5D_space_status_t
    h5d_SPACE_STATUS_PART_ALLOCATED  = SpaceStatus
    PartAllocated
        | Bool
    otherwise = String -> SpaceStatus
    forall a. HasCallStack => String -> a
    error (String
    "Unknown H5D_space_status_t " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ H5D_space_status_t -> String
    forall a. Show a => a -> String
    show H5D_space_status_t
    c)

    getDatasetSpaceStatus :: Dataset -> IO SpaceStatus
    getDatasetSpaceStatus :: Dataset -> IO SpaceStatus
    getDatasetSpaceStatus (Dataset HId_t
    dset_id) =
        (H5D_space_status_t -> SpaceStatus)
    -> IO H5D_space_status_t -> IO SpaceStatus
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap H5D_space_status_t -> SpaceStatus
    spaceStatusFromCode (IO H5D_space_status_t -> IO SpaceStatus)
    -> IO H5D_space_status_t -> IO SpaceStatus
    forall a b. (a -> b) -> a -> b
    $
            (Out H5D_space_status_t -> IO HErr_t) -> IO H5D_space_status_t
    forall a (m :: * -> *) b.
    (Storable a, MonadBaseControl IO m, MonadIO m) =>
    (Out a -> m b) -> m a
    withOut_ ((Out H5D_space_status_t -> IO HErr_t) -> IO H5D_space_status_t)
    -> (Out H5D_space_status_t -> IO HErr_t) -> IO H5D_space_status_t
    forall a b. (a -> b) -> a -> b
    $ \Out H5D_space_status_t
    status ->
                IO HErr_t -> IO HErr_t
    forall t. HDFResultType t => IO t -> IO t
    withErrorCheck (HId_t -> Out H5D_space_status_t -> IO HErr_t
    h5d_get_space_status HId_t
    dset_id Out H5D_space_status_t
    status)

    getDatasetType :: Dataset -> IO Datatype
    getDatasetType :: Dataset -> IO Datatype
    getDatasetType (Dataset HId_t
    dset_id) =
        (HId_t -> Datatype) -> IO HId_t -> IO Datatype
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HId_t -> Datatype
    Datatype (IO HId_t -> IO Datatype) -> IO HId_t -> IO Datatype
    forall a b. (a -> b) -> a -> b
    $
            IO HId_t -> IO HId_t
    forall t. HDFResultType t => IO t -> IO t
    withErrorCheck (IO HId_t -> IO HId_t) -> IO HId_t -> IO HId_t
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> IO HId_t
    h5d_get_type HId_t
    dset_id

    getDatasetCreatePList :: Dataset -> IO DCPL
    getDatasetCreatePList :: Dataset -> IO DCPL
    getDatasetCreatePList (Dataset HId_t
    dset_id) =
        (HId_t -> DCPL) -> IO HId_t -> IO DCPL
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HId_t -> DCPL
    forall t. FromHId t => HId_t -> t
    uncheckedFromHId (IO HId_t -> IO DCPL) -> IO HId_t -> IO DCPL
    forall a b. (a -> b) -> a -> b
    $
            IO HId_t -> IO HId_t
    forall t. HDFResultType t => IO t -> IO t
    withErrorCheck (IO HId_t -> IO HId_t) -> IO HId_t -> IO HId_t
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> IO HId_t
    h5d_get_create_plist HId_t
    dset_id

    getDatasetAccessPList :: Dataset -> IO DAPL
    getDatasetAccessPList :: Dataset -> IO DAPL
    getDatasetAccessPList (Dataset HId_t
    dset_id) =
        (HId_t -> DAPL) -> IO HId_t -> IO DAPL
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HId_t -> DAPL
    forall t. FromHId t => HId_t -> t
    uncheckedFromHId (IO HId_t -> IO DAPL) -> IO HId_t -> IO DAPL
    forall a b. (a -> b) -> a -> b
    $
            IO HId_t -> IO HId_t
    forall t. HDFResultType t => IO t -> IO t
    withErrorCheck (IO HId_t -> IO HId_t) -> IO HId_t -> IO HId_t
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> IO HId_t
    h5d_get_access_plist HId_t
    dset_id

    getDatasetStorageSize :: Dataset -> IO HSize
    getDatasetStorageSize :: Dataset -> IO HSize
    getDatasetStorageSize (Dataset HId_t
    dset_id) =
        HSize_t -> HSize
    HSize
        (HSize_t -> HSize) -> IO HSize_t -> IO HSize
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> HId_t -> IO HSize_t
    h5d_get_storage_size HId_t
    dset_id

    getDatasetOffset :: Dataset -> IO HAddr
    getDatasetOffset :: Dataset -> IO HAddr
    getDatasetOffset (Dataset HId_t
    dset_id) =
        (HAddr_t -> HAddr) -> IO HAddr_t -> IO HAddr
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HAddr_t -> HAddr
    HAddr (IO HAddr_t -> IO HAddr) -> IO HAddr_t -> IO HAddr
    forall a b. (a -> b) -> a -> b
    $
            IO HAddr_t -> IO HAddr_t
    forall t. HDFResultType t => IO t -> IO t
    withErrorCheck (IO HAddr_t -> IO HAddr_t) -> IO HAddr_t -> IO HAddr_t
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> IO HAddr_t
    h5d_get_offset HId_t
    dset_id

    readDataset :: NativeType t =>
        Dataset -> Maybe Dataspace -> Maybe DXPL -> IO (SV.Vector t)
    readDataset :: forall t.
    NativeType t =>
    Dataset -> Maybe Dataspace -> Maybe DXPL -> IO (Vector t)
    readDataset dset :: Dataset
    dset@(Dataset HId_t
    dset_id) Maybe Dataspace
    file_space_id Maybe DXPL
    plist_id = do
        effectiveSelection <- IO Dataspace
    -> (Dataspace -> IO Dataspace) -> Maybe Dataspace -> IO Dataspace
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe (Dataset -> IO Dataspace
    getDatasetSpace Dataset
    dset) Dataspace -> IO Dataspace
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe Dataspace
    file_space_id
        n <- getSimpleDataspaceExtentNPoints effectiveSelection

        withOutVector_ (fromIntegral n) $ \OutArray t
    buf ->
            IO HErr_t -> IO ()
    forall t. HDFResultType t => IO t -> IO ()
    withErrorCheck_ (IO HErr_t -> IO ()) -> IO HErr_t -> IO ()
    forall a b. (a -> b) -> a -> b
    $
                HId_t
    -> HId_t -> HId_t -> HId_t -> HId_t -> OutArray t -> IO HErr_t
    forall a.
    HId_t
    -> HId_t -> HId_t -> HId_t -> HId_t -> OutArray a -> IO HErr_t
    h5d_read HId_t
    dset_id (OutArray t -> HId_t
    forall t (f :: * -> *). NativeType t => f t -> HId_t
    hdfTypeOf1 OutArray t
    buf) HId_t
    h5s_ALL (HId_t -> (Dataspace -> HId_t) -> Maybe Dataspace -> HId_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HId_t
    h5s_ALL Dataspace -> HId_t
    forall t. HId t => t -> HId_t
    hid Maybe Dataspace
    file_space_id) (HId_t -> (DXPL -> HId_t) -> Maybe DXPL -> HId_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HId_t
    h5p_DEFAULT DXPL -> HId_t
    forall t. HId t => t -> HId_t
    hid Maybe DXPL
    plist_id) OutArray t
    buf

    readDatasetInto :: NativeType t =>
        Dataset -> Maybe Dataspace -> Maybe Dataspace -> Maybe DXPL -> SV.MVector RealWorld t -> IO ()
    readDatasetInto :: forall t.
    NativeType t =>
    Dataset
    -> Maybe Dataspace
    -> Maybe Dataspace
    -> Maybe DXPL
    -> MVector RealWorld t
    -> IO ()
    readDatasetInto dset :: Dataset
    dset@(Dataset HId_t
    dset_id) Maybe Dataspace
    mem_space_id Maybe Dataspace
    file_space_id Maybe DXPL
    plist_id MVector RealWorld t
    vec = do
        effectiveSelection <- IO Dataspace
    -> (Dataspace -> IO Dataspace) -> Maybe Dataspace -> IO Dataspace
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe (Dataset -> IO Dataspace
    getDatasetSpace Dataset
    dset) Dataspace -> IO Dataspace
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe Dataspace
    mem_space_id
        n <- getSimpleDataspaceExtentNPoints effectiveSelection

        withOutMVector vec $ \Int
    vecSz OutArray t
    buf ->
            if HSize -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral HSize
    n Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    vecSz
                then String -> IO ()
    forall a. String -> IO a
    forall (m :: * -> *) a. MonadFail m => String -> m a
    fail String
    "readDatasetInto: output vector is too small to contain selection"
                else IO HErr_t -> IO ()
    forall t. HDFResultType t => IO t -> IO ()
    withErrorCheck_ (IO HErr_t -> IO ()) -> IO HErr_t -> IO ()
    forall a b. (a -> b) -> a -> b
    $
                        HId_t
    -> HId_t -> HId_t -> HId_t -> HId_t -> OutArray t -> IO HErr_t
    forall a.
    HId_t
    -> HId_t -> HId_t -> HId_t -> HId_t -> OutArray a -> IO HErr_t
    h5d_read HId_t
    dset_id (OutArray t -> HId_t
    forall t (f :: * -> *). NativeType t => f t -> HId_t
    hdfTypeOf1 OutArray t
    buf) (HId_t -> (Dataspace -> HId_t) -> Maybe Dataspace -> HId_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HId_t
    h5s_ALL Dataspace -> HId_t
    forall t. HId t => t -> HId_t
    hid Maybe Dataspace
    mem_space_id) (HId_t -> (Dataspace -> HId_t) -> Maybe Dataspace -> HId_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HId_t
    h5s_ALL Dataspace -> HId_t
    forall t. HId t => t -> HId_t
    hid Maybe Dataspace
    file_space_id) (HId_t -> (DXPL -> HId_t) -> Maybe DXPL -> HId_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HId_t
    h5p_DEFAULT DXPL -> HId_t
    forall t. HId t => t -> HId_t
    hid Maybe DXPL
    plist_id) OutArray t
    buf

    writeDataset :: NativeType t =>
        Dataset -> Maybe Dataspace -> Maybe Dataspace -> Maybe DXPL -> SV.Vector t -> IO ()
    writeDataset :: forall t.
    NativeType t =>
    Dataset
    -> Maybe Dataspace
    -> Maybe Dataspace
    -> Maybe DXPL
    -> Vector t
    -> IO ()
    writeDataset (Dataset HId_t
    dset_id) Maybe Dataspace
    mem_space_id Maybe Dataspace
    file_space_id Maybe DXPL
    plist_id Vector t
    buf =
        IO HErr_t -> IO ()
    forall t. HDFResultType t => IO t -> IO ()
    withErrorCheck_ (IO HErr_t -> IO ()) -> IO HErr_t -> IO ()
    forall a b. (a -> b) -> a -> b
    $
            Vector t -> (InArray t -> IO HErr_t) -> IO HErr_t
    forall a (m :: * -> *) b.
    (Storable a, MonadBaseControl IO m) =>
    Vector a -> (InArray a -> m b) -> m b
    withInVector Vector t
    buf ((InArray t -> IO HErr_t) -> IO HErr_t)
    -> (InArray t -> IO HErr_t) -> IO HErr_t
    forall a b. (a -> b) -> a -> b
    $ \InArray t
    ibuf ->
                HId_t -> HId_t -> HId_t -> HId_t -> HId_t -> InArray t -> IO HErr_t
    forall a.
    HId_t -> HId_t -> HId_t -> HId_t -> HId_t -> InArray a -> IO HErr_t
    h5d_write HId_t
    dset_id (Vector t -> HId_t
    forall t (f :: * -> *). NativeType t => f t -> HId_t
    hdfTypeOf1 Vector t
    buf) (HId_t -> (Dataspace -> HId_t) -> Maybe Dataspace -> HId_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HId_t
    h5s_ALL Dataspace -> HId_t
    forall t. HId t => t -> HId_t
    hid Maybe Dataspace
    mem_space_id) (HId_t -> (Dataspace -> HId_t) -> Maybe Dataspace -> HId_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HId_t
    h5s_ALL Dataspace -> HId_t
    forall t. HId t => t -> HId_t
    hid Maybe Dataspace
    file_space_id) (HId_t -> (DXPL -> HId_t) -> Maybe DXPL -> HId_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HId_t
    h5p_DEFAULT DXPL -> HId_t
    forall t. HId t => t -> HId_t
    hid Maybe DXPL
    plist_id) InArray t
    ibuf

    -- foreign import ccall "wrapper" wrap_iterate_op
    --     :: (InOut a -> HId_t -> CUInt -> InArray HSize_t -> InOut b -> IO HErr_t)
    --     -> IO (H5D_operator_t a b)
    --
    -- TODO: figure out a good way to properly encapsulate the buffer so that
    -- out-of-bounds accesses are impossible.  Probably use a storable vector
    -- and check the bounds against the dataspace.
    -- Also check whether h5s_ALL is a valid dataspace; Actually I'm not sure how
    -- it could be, given that there is no information here about the size
    -- of the array apart from whatever is carried in the dataspace.
    -- iterateDatasetSelection :: NativeType t => InOutArray t -> Dataspace -> (InOut t -> [HSize] -> IO HErr_t) -> IO ()
    -- iterateDatasetSelection buf space_id op = do
    --     -- In order to marshall Haskell exceptions through the iterate operations,
    --     -- we use 'maxBound' as a "something might have happened" return value
    --     -- and pass a description of what that was via these IORefs.
    --     --
    --     -- The assertion mentioned here is that the 'type_id' argument to h5d_iterate
    --     -- is passed unchanged to the operator.  If that doesn't hold, then this
    --     -- function will need a more complicated type.
    --     assertionFailed <- newIORef False
    --     exception       <- newIORef Nothing :: IO (IORef (Maybe SomeException))
    --
    --     let bufType = hdfTypeOf1 buf
    --
    --     op <- wrap_iterate_op $ \elem type_id ndim (InArray point) _operator_data -> do
    --         point <- peekArray (fromIntegral ndim) point
    --         if type_id == bufType
    --             then do
    --                 result <- try (op elem (fmap HSize point))
    --                 case result of
    --                     Left exc -> do
    --                         writeIORef exception (Just exc)
    --                         return maxBound
    --                     Right x -> return x
    --             else do
    --                 writeIORef assertionFailed True
    --                 return maxBound
    --
    --     result <- withErrorCheck_
    --         (h5d_iterate buf bufType (hid space_id) op (InOut nullPtr)
    --         `finally` freeHaskellFunPtr op)
    --
    --     when (result == maxBound) $ do
    --         assertionFailed <- readIORef assertionFailed
    --         when assertionFailed (throwIO (AssertionFailed "iterateDatasetSelection: operator called with different type_id than h5d_iterate was called with!"))
    --         exception <- readIORef exception
    --         maybe (return result) throwIO exception
    --
    --     return result

    setDatasetExtent :: Dataset -> [HSize] -> IO ()
    setDatasetExtent :: Dataset -> [HSize] -> IO ()
    setDatasetExtent (Dataset HId_t
    dset_id) [HSize]
    sizes =
        IO HErr_t -> IO ()
    forall t. HDFResultType t => IO t -> IO ()
    withErrorCheck_ (IO HErr_t -> IO ()) -> IO HErr_t -> IO ()
    forall a b. (a -> b) -> a -> b
    $
            [HSize_t] -> (InArray HSize_t -> IO HErr_t) -> IO HErr_t
    forall a (m :: * -> *) b.
    (Storable a, MonadBaseControl IO m) =>
    [a] -> (InArray a -> m b) -> m b
    withInList [HSize_t
    sz | HSize HSize_t
    sz <- [HSize]
    sizes] ((InArray HSize_t -> IO HErr_t) -> IO HErr_t)
    -> (InArray HSize_t -> IO HErr_t) -> IO HErr_t
    forall a b. (a -> b) -> a -> b
    $ \InArray HSize_t
    isizes ->
                HId_t -> InArray HSize_t -> IO HErr_t
    h5d_set_extent HId_t
    dset_id InArray HSize_t
    isizes

    -- Fill part of a vector with a value, using the geometry and selection of the given data space
    fillSelection :: (NativeType a, NativeType b) => a -> SV.MVector RealWorld b -> Dataspace -> IO ()
    fillSelection :: forall a b.
    (NativeType a, NativeType b) =>
    a -> MVector RealWorld b -> Dataspace -> IO ()
    fillSelection a
    fill MVector RealWorld b
    buf Dataspace
    space =
        IO HErr_t -> IO ()
    forall t. HDFResultType t => IO t -> IO ()
    withErrorCheck_ (IO HErr_t -> IO ()) -> IO HErr_t -> IO ()
    forall a b. (a -> b) -> a -> b
    $
            a -> (In a -> IO HErr_t) -> IO HErr_t
    forall a (m :: * -> *) b.
    (Storable a, MonadBaseControl IO m) =>
    a -> (In a -> m b) -> m b
    withIn a
    fill ((In a -> IO HErr_t) -> IO HErr_t)
    -> (In a -> IO HErr_t) -> IO HErr_t
    forall a b. (a -> b) -> a -> b
    $ \In a
    ifill ->
                MVector RealWorld b -> (Ptr b -> IO HErr_t) -> IO HErr_t
    forall a b. Storable a => IOVector a -> (Ptr a -> IO b) -> IO b
    SV.M.unsafeWith MVector RealWorld b
    buf ((Ptr b -> IO HErr_t) -> IO HErr_t)
    -> (Ptr b -> IO HErr_t) -> IO HErr_t
    forall a b. (a -> b) -> a -> b
    $ \Ptr b
    pbuf ->
                    In a -> HId_t -> InOutArray b -> HId_t -> HId_t -> IO HErr_t
    forall a b.
    In a -> HId_t -> InOutArray b -> HId_t -> HId_t -> IO HErr_t
    h5d_fill In a
    ifill (In a -> HId_t
    forall t (f :: * -> *). NativeType t => f t -> HId_t
    hdfTypeOf1 In a
    ifill) (Ptr b -> InOutArray b
    forall a. Ptr a -> InOutArray a
    InOutArray Ptr b
    pbuf) (MVector RealWorld b -> HId_t
    forall t (f :: * -> *). NativeType t => f t -> HId_t
    hdfTypeOf1 MVector RealWorld b
    buf) (Dataspace -> HId_t
    forall t. HId t => t -> HId_t
    hid Dataspace
    space)