    {-# LINE 1 "src/Bindings/HDF5/Dataspace.hsc" #-}
    {-# LANGUAGE CPP                        #-}
    {-# LANGUAGE GeneralizedNewtypeDeriving #-}

    module Bindings.HDF5.Dataspace
        ( Dataspace
        , DataspaceClass(..)
        , SelectionOperator(..)
        , SelectionType(..)

        , createDataspace
        , createSimpleDataspace
        , createExpandableDataspace

        , copyDataspace

        , closeDataspace

        , encodeDataspace
        , decodeDataspace

        , getSimpleDataspaceExtentNPoints
        , getSimpleDataspaceExtentNDims
        , getSimpleDataspaceExtent

        , isSimpleDataspace

        , getDataspaceSelectionNPoints

        , selectHyperslab
        , selectElements

        , getSimpleDataspaceExtentType

        , setDataspaceExtentNone
        , copyDataspaceExtent
        , dataspaceExtentsEqual

        , selectAll
        , selectNone

        , offsetSimpleDataspaceSelection

        , selectionValid

        , getHyperslabSelection
        , getHyperslabSelectionNBlocks
        , getHyperslabSelectionBlockList

        , getElementSelection
        , getElementSelectionNPoints
        , getElementSelectionPointList

        , getSelectionBounds

        , getSelectionType
        ) where

    import           Bindings.HDF5.Core
    import           Bindings.HDF5.Error
    import           Bindings.HDF5.Object
    import           Bindings.HDF5.Raw.H5I
    import           Bindings.HDF5.Raw.H5S
    import           Control.Exception       (assert)
    import           Control.Monad
    import qualified Data.ByteString         as BS
    import qualified Data.ByteString.Unsafe  as BS
    import           Data.List
    import           Data.Maybe
    import           Data.Tagged
    import qualified Data.Vector             as V
    import qualified Data.Vector.Storable    as SV
    import           Foreign                 (nullPtr)
    import           Foreign.C
    import           Foreign.Ptr.Conventions

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

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

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

    rawDataspaceClass :: DataspaceClass -> H5S_class_t
    rawDataspaceClass :: DataspaceClass -> H5S_class_t
    rawDataspaceClass DataspaceClass
    Scalar = H5S_class_t
    h5s_SCALAR
    rawDataspaceClass DataspaceClass
    Simple = H5S_class_t
    h5s_SIMPLE
    rawDataspaceClass DataspaceClass
    Null   = H5S_class_t
    h5s_NULL

    dataspaceClass :: H5S_class_t -> DataspaceClass
    dataspaceClass :: H5S_class_t -> DataspaceClass
    dataspaceClass H5S_class_t
    c
        | H5S_class_t
    c H5S_class_t -> H5S_class_t -> Bool
    forall a. Eq a => a -> a -> Bool
    == H5S_class_t
    h5s_SCALAR   = DataspaceClass
    Scalar
        | H5S_class_t
    c H5S_class_t -> H5S_class_t -> Bool
    forall a. Eq a => a -> a -> Bool
    == H5S_class_t
    h5s_SIMPLE   = DataspaceClass
    Simple
        | H5S_class_t
    c H5S_class_t -> H5S_class_t -> Bool
    forall a. Eq a => a -> a -> Bool
    == H5S_class_t
    h5s_NULL     = DataspaceClass
    Null
        | Bool
    otherwise         = String -> DataspaceClass
    forall a. HasCallStack => String -> a
    error (String
    "unknown dataspace class: " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ H5S_class_t -> String
    forall a. Show a => a -> String
    show H5S_class_t
    c)

    createDataspace :: DataspaceClass -> IO Dataspace
    createDataspace :: DataspaceClass -> IO Dataspace
    createDataspace DataspaceClass
    cls =
        (HId_t -> Dataspace) -> IO HId_t -> IO Dataspace
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HId_t -> Dataspace
    Dataspace (IO HId_t -> IO Dataspace) -> IO HId_t -> IO Dataspace
    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
    $
                H5S_class_t -> IO HId_t
    h5s_create (DataspaceClass -> H5S_class_t
    rawDataspaceClass DataspaceClass
    cls)

    createSimpleDataspace :: [HSize] -> IO Dataspace
    createSimpleDataspace :: [HSize] -> IO Dataspace
    createSimpleDataspace [HSize]
    dims =
        (HId_t -> Dataspace) -> IO HId_t -> IO Dataspace
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HId_t -> Dataspace
    Dataspace (IO HId_t -> IO Dataspace) -> IO HId_t -> IO Dataspace
    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
    $
                [HSize_t] -> (InArray HSize_t -> IO HId_t) -> IO HId_t
    forall a (m :: * -> *) b.
    (Storable a, MonadBaseControl IO m) =>
    [a] -> (InArray a -> m b) -> m b
    withInList ((HSize -> HSize_t) -> [HSize] -> [HSize_t]
    forall a b. (a -> b) -> [a] -> [b]
    map HSize -> HSize_t
    hSize [HSize]
    dims) ((InArray HSize_t -> IO HId_t) -> IO HId_t)
    -> (InArray HSize_t -> IO HId_t) -> IO HId_t
    forall a b. (a -> b) -> a -> b
    $ \InArray HSize_t
    idims ->
                    CInt -> InArray HSize_t -> InArray HSize_t -> IO HId_t
    h5s_create_simple CInt
    n InArray HSize_t
    idims (Ptr HSize_t -> InArray HSize_t
    forall a. Ptr a -> InArray a
    InArray Ptr HSize_t
    forall a. Ptr a
    nullPtr)
        where n :: CInt
    n = [HSize] -> CInt
    forall i a. Num i => [a] -> i
    genericLength [HSize]
    dims

    createExpandableDataspace :: [(HSize, Maybe HSize)] -> IO Dataspace
    createExpandableDataspace :: [(HSize, Maybe HSize)] -> IO Dataspace
    createExpandableDataspace [(HSize, Maybe HSize)]
    dims =
        (HId_t -> Dataspace) -> IO HId_t -> IO Dataspace
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HId_t -> Dataspace
    Dataspace (IO HId_t -> IO Dataspace) -> IO HId_t -> IO Dataspace
    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
    $
                [HSize_t] -> (InArray HSize_t -> IO HId_t) -> IO HId_t
    forall a (m :: * -> *) b.
    (Storable a, MonadBaseControl IO m) =>
    [a] -> (InArray a -> m b) -> m b
    withInList ((HSize -> HSize_t) -> [HSize] -> [HSize_t]
    forall a b. (a -> b) -> [a] -> [b]
    map HSize -> HSize_t
    hSize [HSize]
    dimSizes) ((InArray HSize_t -> IO HId_t) -> IO HId_t)
    -> (InArray HSize_t -> IO HId_t) -> IO HId_t
    forall a b. (a -> b) -> a -> b
    $ \InArray HSize_t
    idimSizes ->
                    [HSize_t] -> (InArray HSize_t -> IO HId_t) -> IO HId_t
    forall a (m :: * -> *) b.
    (Storable a, MonadBaseControl IO m) =>
    [a] -> (InArray a -> m b) -> m b
    withInList ((Maybe HSize -> HSize_t) -> [Maybe HSize] -> [HSize_t]
    forall a b. (a -> b) -> [a] -> [b]
    map (HSize_t -> (HSize -> HSize_t) -> Maybe HSize -> HSize_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe HSize_t
    forall a. Num a => a
    h5s_UNLIMITED HSize -> HSize_t
    hSize) [Maybe HSize]
    dimLimits) ((InArray HSize_t -> IO HId_t) -> IO HId_t)
    -> (InArray HSize_t -> IO HId_t) -> IO HId_t
    forall a b. (a -> b) -> a -> b
    $ \InArray HSize_t
    idimLimits ->
                        CInt -> InArray HSize_t -> InArray HSize_t -> IO HId_t
    h5s_create_simple CInt
    n InArray HSize_t
    idimSizes InArray HSize_t
    idimLimits
        where
            n :: CInt
    n = [(HSize, Maybe HSize)] -> CInt
    forall i a. Num i => [a] -> i
    genericLength [(HSize, Maybe HSize)]
    dims
            ([HSize]
    dimSizes, [Maybe HSize]
    dimLimits) = [(HSize, Maybe HSize)] -> ([HSize], [Maybe HSize])
    forall a b. [(a, b)] -> ([a], [b])
    unzip [(HSize, Maybe HSize)]
    dims

    copyDataspace :: Dataspace -> IO Dataspace
    copyDataspace :: Dataspace -> IO Dataspace
    copyDataspace (Dataspace HId_t
    space_id) =
        (HId_t -> Dataspace) -> IO HId_t -> IO Dataspace
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HId_t -> Dataspace
    Dataspace (IO HId_t -> IO Dataspace) -> IO HId_t -> IO Dataspace
    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
    h5s_copy HId_t
    space_id

    closeDataspace :: Dataspace -> IO ()
    closeDataspace :: Dataspace -> IO ()
    closeDataspace (Dataspace HId_t
    space_id) =
        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 -> IO HErr_t
    h5s_close HId_t
    space_id

    encodeDataspace :: Dataspace -> IO BS.ByteString
    encodeDataspace :: Dataspace -> IO ByteString
    encodeDataspace (Dataspace HId_t
    space_id) =
        (OutArray CChar -> CSize -> IO CSize) -> IO ByteString
    forall (m :: * -> *) a b.
    (MonadBaseControl IO m, MonadIO m, Integral a, Integral b) =>
    (OutArray CChar -> a -> m b) -> m ByteString
    withOutByteString ((OutArray CChar -> CSize -> IO CSize) -> IO ByteString)
    -> (OutArray CChar -> CSize -> IO CSize) -> IO ByteString
    forall a b. (a -> b) -> a -> b
    $ \OutArray CChar
    buf CSize
    bufSz ->
            CSize -> (InOut CSize -> IO ()) -> IO CSize
    forall a (m :: * -> *) b.
    (Storable a, MonadBaseControl IO m, MonadIO m) =>
    a -> (InOut a -> m b) -> m a
    withInOut_ CSize
    bufSz ((InOut CSize -> IO ()) -> IO CSize)
    -> (InOut CSize -> IO ()) -> IO CSize
    forall a b. (a -> b) -> a -> b
    $ \InOut CSize
    ioBufSz ->
                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 -> OutArray CChar -> InOut CSize -> IO HErr_t
    h5s_encode1 HId_t
    space_id OutArray CChar
    buf InOut CSize
    ioBufSz

    decodeDataspace :: BS.ByteString -> IO Dataspace
    decodeDataspace :: ByteString -> IO Dataspace
    decodeDataspace ByteString
    bs = ByteString -> (CString -> IO Dataspace) -> IO Dataspace
    forall a. ByteString -> (CString -> IO a) -> IO a
    BS.unsafeUseAsCString ByteString
    bs ((CString -> IO Dataspace) -> IO Dataspace)
    -> (CString -> IO Dataspace) -> IO Dataspace
    forall a b. (a -> b) -> a -> b
    $ \CString
    buf ->
        (HId_t -> Dataspace) -> IO HId_t -> IO Dataspace
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HId_t -> Dataspace
    Dataspace (IO HId_t -> IO Dataspace) -> IO HId_t -> IO Dataspace
    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
    $
                InArray CChar -> IO HId_t
    h5s_decode (CString -> InArray CChar
    forall a. Ptr a -> InArray a
    InArray CString
    buf)

    getSimpleDataspaceExtentNPoints :: Dataspace -> IO HSize
    getSimpleDataspaceExtentNPoints :: Dataspace -> IO HSize
    getSimpleDataspaceExtentNPoints (Dataspace HId_t
    space_id) =
        (HSSize_t -> HSize) -> IO HSSize_t -> IO HSize
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HSSize_t -> HSize
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (IO HSSize_t -> IO HSize) -> IO HSSize_t -> IO HSize
    forall a b. (a -> b) -> a -> b
    $
            (HSSize_t -> Bool) -> IO HSSize_t -> IO HSSize_t
    forall t. (t -> Bool) -> IO t -> IO t
    withErrorWhen (HSSize_t -> HSSize_t -> Bool
    forall a. Ord a => a -> a -> Bool
    < HSSize_t
    0) (IO HSSize_t -> IO HSSize_t) -> IO HSSize_t -> IO HSSize_t
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> IO HSSize_t
    h5s_get_simple_extent_npoints HId_t
    space_id

    getSimpleDataspaceExtentNDims :: Dataspace -> IO CInt
    getSimpleDataspaceExtentNDims :: Dataspace -> IO CInt
    getSimpleDataspaceExtentNDims (Dataspace HId_t
    space_id) =
        (CInt -> Bool) -> IO CInt -> IO CInt
    forall t. (t -> Bool) -> IO t -> IO t
    withErrorWhen (CInt -> CInt -> Bool
    forall a. Ord a => a -> a -> Bool
    < CInt
    0) (IO CInt -> IO CInt) -> IO CInt -> IO CInt
    forall a b. (a -> b) -> a -> b
    $
            HId_t -> IO CInt
    h5s_get_simple_extent_ndims HId_t
    space_id

    getSimpleDataspaceExtent :: Dataspace -> IO ([HSize], [Maybe HSize])
    getSimpleDataspaceExtent :: Dataspace -> IO ([HSize], [Maybe HSize])
    getSimpleDataspaceExtent space :: Dataspace
    space@(Dataspace HId_t
    space_id) = do
        n <- Dataspace -> IO CInt
    getSimpleDataspaceExtentNDims Dataspace
    space

        (dims, (maxDims, n')) <-
            withOutList (fromIntegral n) $ \OutArray HSize_t
    dims ->
                Int -> (OutArray HSize_t -> IO CInt) -> IO ([HSize_t], CInt)
    forall a (m :: * -> *) b.
    (Storable a, MonadIO m) =>
    Int -> (OutArray a -> m b) -> m ([a], b)
    withOutList (CInt -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    n) ((OutArray HSize_t -> IO CInt) -> IO ([HSize_t], CInt))
    -> (OutArray HSize_t -> IO CInt) -> IO ([HSize_t], CInt)
    forall a b. (a -> b) -> a -> b
    $ \OutArray HSize_t
    maxDims ->
                    (CInt -> Bool) -> IO CInt -> IO CInt
    forall t. (t -> Bool) -> IO t -> IO t
    withErrorWhen (CInt -> CInt -> Bool
    forall a. Ord a => a -> a -> Bool
    < CInt
    0) (IO CInt -> IO CInt) -> IO CInt -> IO CInt
    forall a b. (a -> b) -> a -> b
    $
                        HId_t -> OutArray HSize_t -> OutArray HSize_t -> IO CInt
    h5s_get_simple_extent_dims HId_t
    space_id OutArray HSize_t
    dims OutArray HSize_t
    maxDims

        assert (n==n') $ return
            ( map HSize dims
            , [ if d == h5s_UNLIMITED then Nothing else Just (HSize d) | d <- maxDims]
            )

    isSimpleDataspace :: Dataspace -> IO Bool
    isSimpleDataspace :: Dataspace -> IO Bool
    isSimpleDataspace (Dataspace HId_t
    space_id) =
        IO HTri_t -> IO Bool
    htriToBool (IO HTri_t -> IO Bool) -> IO HTri_t -> IO Bool
    forall a b. (a -> b) -> a -> b
    $
            HId_t -> IO HTri_t
    h5s_is_simple HId_t
    space_id

    getDataspaceSelectionNPoints :: Dataspace -> IO HSize
    getDataspaceSelectionNPoints :: Dataspace -> IO HSize
    getDataspaceSelectionNPoints (Dataspace HId_t
    space_id) =
        (HSSize_t -> HSize) -> IO HSSize_t -> IO HSize
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HSSize_t -> HSize
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (IO HSSize_t -> IO HSize) -> IO HSSize_t -> IO HSize
    forall a b. (a -> b) -> a -> b
    $
            (HSSize_t -> Bool) -> IO HSSize_t -> IO HSSize_t
    forall t. (t -> Bool) -> IO t -> IO t
    withErrorWhen (HSSize_t -> HSSize_t -> Bool
    forall a. Ord a => a -> a -> Bool
    < HSSize_t
    0) (IO HSSize_t -> IO HSSize_t) -> IO HSSize_t -> IO HSSize_t
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> IO HSSize_t
    h5s_get_select_npoints HId_t
    space_id

    data SelectionOperator
        = Set
        | Or
        | And
        | Xor
        | NotB
        | NotA
        | Append
        | Prepend
        deriving (SelectionOperator -> SelectionOperator -> Bool
    (SelectionOperator -> SelectionOperator -> Bool)
    -> (SelectionOperator -> SelectionOperator -> Bool)
    -> Eq SelectionOperator
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: SelectionOperator -> SelectionOperator -> Bool
    == :: SelectionOperator -> SelectionOperator -> Bool
    $c/= :: SelectionOperator -> SelectionOperator -> Bool
    /= :: SelectionOperator -> SelectionOperator -> Bool
    Eq, Eq SelectionOperator
    Eq SelectionOperator =>
    (SelectionOperator -> SelectionOperator -> Ordering)
    -> (SelectionOperator -> SelectionOperator -> Bool)
    -> (SelectionOperator -> SelectionOperator -> Bool)
    -> (SelectionOperator -> SelectionOperator -> Bool)
    -> (SelectionOperator -> SelectionOperator -> Bool)
    -> (SelectionOperator -> SelectionOperator -> SelectionOperator)
    -> (SelectionOperator -> SelectionOperator -> SelectionOperator)
    -> Ord SelectionOperator
    SelectionOperator -> SelectionOperator -> Bool
    SelectionOperator -> SelectionOperator -> Ordering
    SelectionOperator -> SelectionOperator -> SelectionOperator
    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 :: SelectionOperator -> SelectionOperator -> Ordering
    compare :: SelectionOperator -> SelectionOperator -> Ordering
    $c< :: SelectionOperator -> SelectionOperator -> Bool
    < :: SelectionOperator -> SelectionOperator -> Bool
    $c<= :: SelectionOperator -> SelectionOperator -> Bool
    <= :: SelectionOperator -> SelectionOperator -> Bool
    $c> :: SelectionOperator -> SelectionOperator -> Bool
    > :: SelectionOperator -> SelectionOperator -> Bool
    $c>= :: SelectionOperator -> SelectionOperator -> Bool
    >= :: SelectionOperator -> SelectionOperator -> Bool
    $cmax :: SelectionOperator -> SelectionOperator -> SelectionOperator
    max :: SelectionOperator -> SelectionOperator -> SelectionOperator
    $cmin :: SelectionOperator -> SelectionOperator -> SelectionOperator
    min :: SelectionOperator -> SelectionOperator -> SelectionOperator
    Ord, Int -> SelectionOperator
    SelectionOperator -> Int
    SelectionOperator -> [SelectionOperator]
    SelectionOperator -> SelectionOperator
    SelectionOperator -> SelectionOperator -> [SelectionOperator]
    SelectionOperator
    -> SelectionOperator -> SelectionOperator -> [SelectionOperator]
    (SelectionOperator -> SelectionOperator)
    -> (SelectionOperator -> SelectionOperator)
    -> (Int -> SelectionOperator)
    -> (SelectionOperator -> Int)
    -> (SelectionOperator -> [SelectionOperator])
    -> (SelectionOperator -> SelectionOperator -> [SelectionOperator])
    -> (SelectionOperator -> SelectionOperator -> [SelectionOperator])
    -> (SelectionOperator
        -> SelectionOperator -> SelectionOperator -> [SelectionOperator])
    -> Enum SelectionOperator
    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 :: SelectionOperator -> SelectionOperator
    succ :: SelectionOperator -> SelectionOperator
    $cpred :: SelectionOperator -> SelectionOperator
    pred :: SelectionOperator -> SelectionOperator
    $ctoEnum :: Int -> SelectionOperator
    toEnum :: Int -> SelectionOperator
    $cfromEnum :: SelectionOperator -> Int
    fromEnum :: SelectionOperator -> Int
    $cenumFrom :: SelectionOperator -> [SelectionOperator]
    enumFrom :: SelectionOperator -> [SelectionOperator]
    $cenumFromThen :: SelectionOperator -> SelectionOperator -> [SelectionOperator]
    enumFromThen :: SelectionOperator -> SelectionOperator -> [SelectionOperator]
    $cenumFromTo :: SelectionOperator -> SelectionOperator -> [SelectionOperator]
    enumFromTo :: SelectionOperator -> SelectionOperator -> [SelectionOperator]
    $cenumFromThenTo :: SelectionOperator
    -> SelectionOperator -> SelectionOperator -> [SelectionOperator]
    enumFromThenTo :: SelectionOperator
    -> SelectionOperator -> SelectionOperator -> [SelectionOperator]
    Enum, SelectionOperator
    SelectionOperator -> SelectionOperator -> Bounded SelectionOperator
    forall a. a -> a -> Bounded a
    $cminBound :: SelectionOperator
    minBound :: SelectionOperator
    $cmaxBound :: SelectionOperator
    maxBound :: SelectionOperator
    Bounded, ReadPrec [SelectionOperator]
    ReadPrec SelectionOperator
    Int -> ReadS SelectionOperator
    ReadS [SelectionOperator]
    (Int -> ReadS SelectionOperator)
    -> ReadS [SelectionOperator]
    -> ReadPrec SelectionOperator
    -> ReadPrec [SelectionOperator]
    -> Read SelectionOperator
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS SelectionOperator
    readsPrec :: Int -> ReadS SelectionOperator
    $creadList :: ReadS [SelectionOperator]
    readList :: ReadS [SelectionOperator]
    $creadPrec :: ReadPrec SelectionOperator
    readPrec :: ReadPrec SelectionOperator
    $creadListPrec :: ReadPrec [SelectionOperator]
    readListPrec :: ReadPrec [SelectionOperator]
    Read, Int -> SelectionOperator -> ShowS
    [SelectionOperator] -> ShowS
    SelectionOperator -> String
    (Int -> SelectionOperator -> ShowS)
    -> (SelectionOperator -> String)
    -> ([SelectionOperator] -> ShowS)
    -> Show SelectionOperator
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> SelectionOperator -> ShowS
    showsPrec :: Int -> SelectionOperator -> ShowS
    $cshow :: SelectionOperator -> String
    show :: SelectionOperator -> String
    $cshowList :: [SelectionOperator] -> ShowS
    showList :: [SelectionOperator] -> ShowS
    Show)

    rawSelectionOperator :: SelectionOperator -> H5S_seloper_t
    rawSelectionOperator :: SelectionOperator -> H5S_seloper_t
    rawSelectionOperator SelectionOperator
    Set     = H5S_seloper_t
    h5s_SELECT_SET
    rawSelectionOperator SelectionOperator
    Or      = H5S_seloper_t
    h5s_SELECT_OR
    rawSelectionOperator SelectionOperator
    And     = H5S_seloper_t
    h5s_SELECT_AND
    rawSelectionOperator SelectionOperator
    Xor     = H5S_seloper_t
    h5s_SELECT_XOR
    rawSelectionOperator SelectionOperator
    NotB    = H5S_seloper_t
    h5s_SELECT_NOTB
    rawSelectionOperator SelectionOperator
    NotA    = H5S_seloper_t
    h5s_SELECT_NOTA
    rawSelectionOperator SelectionOperator
    Append  = H5S_seloper_t
    h5s_SELECT_APPEND
    rawSelectionOperator SelectionOperator
    Prepend = H5S_seloper_t
    h5s_SELECT_PREPEND

    selectHyperslab :: Dataspace -> SelectionOperator -> [(HSize, Maybe HSize, HSize, Maybe HSize)] -> IO ()
    selectHyperslab :: Dataspace
    -> SelectionOperator
    -> [(HSize, Maybe HSize, HSize, Maybe HSize)]
    -> IO ()
    selectHyperslab space :: Dataspace
    space@(Dataspace HId_t
    space_id) SelectionOperator
    oper [(HSize, Maybe HSize, HSize, Maybe HSize)]
    hyperSlab = do
        nDims <- Dataspace -> IO CInt
    getSimpleDataspaceExtentNDims Dataspace
    space

        when (length hyperSlab /= fromIntegral nDims)
            (fail "selectHyperslab: the given hyperslab has the wrong number of dimensions for this dataspace")

        withErrorCheck_ $
            withInList' start $ \InArray HSize_t
    istart ->
                ((InArray HSize_t -> IO HErr_t) -> IO HErr_t)
    -> ([HSize] -> (InArray HSize_t -> IO HErr_t) -> IO HErr_t)
    -> Maybe [HSize]
    -> (InArray HSize_t -> IO HErr_t)
    -> IO HErr_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe (InArray HSize_t -> IO HErr_t) -> IO HErr_t
    forall {a} {t}. (InArray a -> t) -> t
    withNull [HSize] -> (InArray HSize_t -> IO HErr_t) -> IO HErr_t
    forall {b}. [HSize] -> (InArray HSize_t -> IO b) -> IO b
    withInList' Maybe [HSize]
    stride ((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
    istride ->
                    [HSize] -> (InArray HSize_t -> IO HErr_t) -> IO HErr_t
    forall {b}. [HSize] -> (InArray HSize_t -> IO b) -> IO b
    withInList' [HSize]
    count ((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
    icount ->
                        ((InArray HSize_t -> IO HErr_t) -> IO HErr_t)
    -> ([HSize] -> (InArray HSize_t -> IO HErr_t) -> IO HErr_t)
    -> Maybe [HSize]
    -> (InArray HSize_t -> IO HErr_t)
    -> IO HErr_t
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe (InArray HSize_t -> IO HErr_t) -> IO HErr_t
    forall {a} {t}. (InArray a -> t) -> t
    withNull [HSize] -> (InArray HSize_t -> IO HErr_t) -> IO HErr_t
    forall {b}. [HSize] -> (InArray HSize_t -> IO b) -> IO b
    withInList' Maybe [HSize]
    block ((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
    iblock ->
                            HId_t
    -> H5S_seloper_t
    -> InArray HSize_t
    -> InArray HSize_t
    -> InArray HSize_t
    -> InArray HSize_t
    -> IO HErr_t
    h5s_select_hyperslab HId_t
    space_id (SelectionOperator -> H5S_seloper_t
    rawSelectionOperator SelectionOperator
    oper) InArray HSize_t
    istart InArray HSize_t
    istride InArray HSize_t
    icount InArray HSize_t
    iblock
        where
            ([HSize]
    start, [Maybe HSize]
    mbStrides, [HSize]
    count, [Maybe HSize]
    mbBlocks) = [(HSize, Maybe HSize, HSize, Maybe HSize)]
    -> ([HSize], [Maybe HSize], [HSize], [Maybe HSize])
    forall a b c d. [(a, b, c, d)] -> ([a], [b], [c], [d])
    unzip4 [(HSize, Maybe HSize, HSize, Maybe HSize)]
    hyperSlab
            stride :: Maybe [HSize]
    stride
                | (Maybe HSize -> Bool) -> [Maybe HSize] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    any Maybe HSize -> Bool
    forall a. Maybe a -> Bool
    isJust [Maybe HSize]
    mbStrides  = [HSize] -> Maybe [HSize]
    forall a. a -> Maybe a
    Just ((Maybe HSize -> HSize) -> [Maybe HSize] -> [HSize]
    forall a b. (a -> b) -> [a] -> [b]
    map (HSize -> Maybe HSize -> HSize
    forall a. a -> Maybe a -> a
    fromMaybe HSize
    1) [Maybe HSize]
    mbStrides)
                | Bool
    otherwise             = Maybe [HSize]
    forall a. Maybe a
    Nothing
            block :: Maybe [HSize]
    block
                | (Maybe HSize -> Bool) -> [Maybe HSize] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    any Maybe HSize -> Bool
    forall a. Maybe a -> Bool
    isJust [Maybe HSize]
    mbBlocks  = [HSize] -> Maybe [HSize]
    forall a. a -> Maybe a
    Just ((Maybe HSize -> HSize) -> [Maybe HSize] -> [HSize]
    forall a b. (a -> b) -> [a] -> [b]
    map (HSize -> Maybe HSize -> HSize
    forall a. a -> Maybe a -> a
    fromMaybe HSize
    1) [Maybe HSize]
    mbBlocks)
                | Bool
    otherwise             = Maybe [HSize]
    forall a. Maybe a
    Nothing
            withNull :: (InArray a -> t) -> t
    withNull InArray a -> t
    f = InArray a -> t
    f (Ptr a -> InArray a
    forall a. Ptr a -> InArray a
    InArray Ptr a
    forall a. Ptr a
    nullPtr)
            withInList' :: [HSize] -> (InArray HSize_t -> IO b) -> IO b
    withInList' = [HSize_t] -> (InArray HSize_t -> IO b) -> IO b
    forall a (m :: * -> *) b.
    (Storable a, MonadBaseControl IO m) =>
    [a] -> (InArray a -> m b) -> m b
    withInList ([HSize_t] -> (InArray HSize_t -> IO b) -> IO b)
    -> ([HSize] -> [HSize_t])
    -> [HSize]
    -> (InArray HSize_t -> IO b)
    -> IO b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (HSize -> HSize_t) -> [HSize] -> [HSize_t]
    forall a b. (a -> b) -> [a] -> [b]
    map HSize -> HSize_t
    hSize

    selectElements :: Dataspace -> SelectionOperator -> V.Vector (SV.Vector HSize) -> IO ()
    selectElements :: Dataspace -> SelectionOperator -> Vector (Vector HSize) -> IO ()
    selectElements space :: Dataspace
    space@(Dataspace HId_t
    space_id) SelectionOperator
    oper Vector (Vector HSize)
    elems = do
        nDims <- Dataspace -> IO CInt
    getSimpleDataspaceExtentNDims Dataspace
    space

        let nElems = Vector (Vector HSize) -> Int
    forall a. Vector a -> Int
    V.length Vector (Vector HSize)
    elems
            packed = Int -> (Int -> HSize) -> Vector HSize
    forall a. Storable a => Int -> (Int -> a) -> Vector a
    SV.generate (Int
    nElems Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * CInt -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    nDims) ((Int -> HSize) -> Vector HSize) -> (Int -> HSize) -> Vector HSize
    forall a b. (a -> b) -> a -> b
    $ \Int
    i ->
                case Int
    i Int -> Int -> (Int, Int)
    forall a. Integral a => a -> a -> (a, a)
    `divMod` Int
    nElems of
                    (Int
    dim, Int
    elt) -> Vector (Vector HSize)
    elems Vector (Vector HSize) -> Int -> Vector HSize
    forall a. Vector a -> Int -> a
    V.! Int
    elt Vector HSize -> Int -> HSize
    forall a. Storable a => Vector a -> Int -> a
    SV.! Int
    dim

        withErrorCheck_ $
            withInVector packed $ \InArray HSize
    ielems ->
                HId_t -> H5S_seloper_t -> CSize -> InArray HSize_t -> IO HErr_t
    h5s_select_elements HId_t
    space_id (SelectionOperator -> H5S_seloper_t
    rawSelectionOperator SelectionOperator
    oper) (Int -> CSize
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    nElems) (InArray HSize -> InArray HSize_t
    forall a b. InArray a -> InArray b
    forall (p :: * -> *) a b. WrappedPtr p => p a -> p b
    castWrappedPtr InArray HSize
    ielems)

    -- TODO: determine whether to throw an exception or simply report it
    -- when the returned value is invalid.
    getSimpleDataspaceExtentType :: Dataspace -> IO DataspaceClass
    getSimpleDataspaceExtentType :: Dataspace -> IO DataspaceClass
    getSimpleDataspaceExtentType (Dataspace HId_t
    space_id) =
        (H5S_class_t -> DataspaceClass)
    -> IO H5S_class_t -> IO DataspaceClass
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap H5S_class_t -> DataspaceClass
    dataspaceClass (IO H5S_class_t -> IO DataspaceClass)
    -> IO H5S_class_t -> IO DataspaceClass
    forall a b. (a -> b) -> a -> b
    $
            (H5S_class_t -> Bool) -> IO H5S_class_t -> IO H5S_class_t
    forall t. (t -> Bool) -> IO t -> IO t
    withErrorWhen (\(H5S_class_t Int32
    c) -> Int32
    c Int32 -> Int32 -> Bool
    forall a. Ord a => a -> a -> Bool
    < Int32
    0) (IO H5S_class_t -> IO H5S_class_t)
    -> IO H5S_class_t -> IO H5S_class_t
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> IO H5S_class_t
    h5s_get_simple_extent_type HId_t
    space_id

    setDataspaceExtentNone :: Dataspace -> IO ()
    setDataspaceExtentNone :: Dataspace -> IO ()
    setDataspaceExtentNone (Dataspace HId_t
    space_id) =
        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 -> IO HErr_t
    h5s_set_extent_none HId_t
    space_id

    copyDataspaceExtent :: Dataspace -> Dataspace -> IO ()
    copyDataspaceExtent :: Dataspace -> Dataspace -> IO ()
    copyDataspaceExtent (Dataspace HId_t
    dst) (Dataspace HId_t
    src) =
        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 -> IO HErr_t
    h5s_extent_copy HId_t
    dst HId_t
    src

    dataspaceExtentsEqual :: Dataspace -> Dataspace -> IO Bool
    dataspaceExtentsEqual :: Dataspace -> Dataspace -> IO Bool
    dataspaceExtentsEqual (Dataspace HId_t
    s1) (Dataspace HId_t
    s2) =
        IO HTri_t -> IO Bool
    htriToBool (IO HTri_t -> IO Bool) -> IO HTri_t -> IO Bool
    forall a b. (a -> b) -> a -> b
    $
            HId_t -> HId_t -> IO HTri_t
    h5s_extent_equal HId_t
    s1 HId_t
    s2

    selectAll :: Dataspace -> IO ()
    selectAll :: Dataspace -> IO ()
    selectAll (Dataspace HId_t
    space_id) =
        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 -> IO HErr_t
    h5s_select_all HId_t
    space_id

    selectNone :: Dataspace -> IO ()
    selectNone :: Dataspace -> IO ()
    selectNone (Dataspace HId_t
    space_id) =
        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 -> IO HErr_t
    h5s_select_none HId_t
    space_id

    offsetSimpleDataspaceSelection :: Dataspace -> SV.Vector HSSize -> IO ()
    offsetSimpleDataspaceSelection :: Dataspace -> Vector HSSize -> IO ()
    offsetSimpleDataspaceSelection space :: Dataspace
    space@(Dataspace HId_t
    space_id) Vector HSSize
    offsets = do
        nDims <- Dataspace -> IO CInt
    getSimpleDataspaceExtentNDims Dataspace
    space

        when (fromIntegral nDims /= SV.length offsets)
            (fail "offsetSimpleDataspaceSelection: offset vector's length must equal number dimensions in dataspace")

        withErrorCheck_ $
            withInVector offsets $ \InArray HSSize
    ioffsets ->
                HId_t -> InArray HSSize_t -> IO HErr_t
    h5s_offset_simple HId_t
    space_id (InArray HSSize -> InArray HSSize_t
    forall a b. InArray a -> InArray b
    forall (p :: * -> *) a b. WrappedPtr p => p a -> p b
    castWrappedPtr InArray HSSize
    ioffsets)

    selectionValid :: Dataspace -> IO Bool
    selectionValid :: Dataspace -> IO Bool
    selectionValid (Dataspace HId_t
    space_id) =
        IO HTri_t -> IO Bool
    htriToBool (IO HTri_t -> IO Bool) -> IO HTri_t -> IO Bool
    forall a b. (a -> b) -> a -> b
    $
            HId_t -> IO HTri_t
    h5s_select_valid HId_t
    space_id

    getHyperslabSelection :: Dataspace -> IO (V.Vector (SV.Vector HSize, SV.Vector HSize))
    getHyperslabSelection :: Dataspace -> IO (Vector (Vector HSize, Vector HSize))
    getHyperslabSelection Dataspace
    space = Dataspace
    -> HSize -> HSize -> IO (Vector (Vector HSize, Vector HSize))
    getHyperslabSelectionBlockList Dataspace
    space HSize
    0 HSize
    forall a. Bounded a => a
    maxBound

    getHyperslabSelectionNBlocks :: Dataspace -> IO HSize
    getHyperslabSelectionNBlocks :: Dataspace -> IO HSize
    getHyperslabSelectionNBlocks (Dataspace HId_t
    space_id) =
        (HSSize_t -> HSize) -> IO HSSize_t -> IO HSize
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HSSize_t -> HSize
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (IO HSSize_t -> IO HSize) -> IO HSSize_t -> IO HSize
    forall a b. (a -> b) -> a -> b
    $
            (HSSize_t -> Bool) -> IO HSSize_t -> IO HSSize_t
    forall t. (t -> Bool) -> IO t -> IO t
    withErrorWhen (HSSize_t -> HSSize_t -> Bool
    forall a. Ord a => a -> a -> Bool
    < HSSize_t
    0) (IO HSSize_t -> IO HSSize_t) -> IO HSSize_t -> IO HSSize_t
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> IO HSSize_t
    h5s_get_select_hyper_nblocks HId_t
    space_id

    getHyperslabSelectionBlockList :: Dataspace -> HSize -> HSize -> IO (V.Vector (SV.Vector HSize, SV.Vector HSize))
    getHyperslabSelectionBlockList :: Dataspace
    -> HSize -> HSize -> IO (Vector (Vector HSize, Vector HSize))
    getHyperslabSelectionBlockList space :: Dataspace
    space@(Dataspace HId_t
    space_id) HSize
    startBlock HSize
    numBlocks = do
        n <- Dataspace -> IO HSize
    getHyperslabSelectionNBlocks Dataspace
    space
        nDims <- getSimpleDataspaceExtentNDims space

        let nBlks = HSize -> HSize -> HSize
    forall a. Ord a => a -> a -> a
    min HSize
    numBlocks (HSize
    n HSize -> HSize -> HSize
    forall a. Num a => a -> a -> a
    - HSize
    startBlock)
            blkSize = HSize
    2 HSize -> HSize -> HSize
    forall a. Num a => a -> a -> a
    * CInt -> HSize
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    nDims
            numSizes = HSize
    nBlks HSize -> HSize -> HSize
    forall a. Num a => a -> a -> a
    * HSize
    blkSize

        sizes <- withOutVector_ (fromIntegral numSizes) $ \OutArray HSize
    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 -> HSize_t -> HSize_t -> OutArray HSize_t -> IO HErr_t
    h5s_get_select_hyper_blocklist HId_t
    space_id (HSize -> HSize_t
    hSize HSize
    startBlock) (HSize -> HSize_t
    hSize HSize
    nBlks) (OutArray HSize -> OutArray HSize_t
    forall a b. OutArray a -> OutArray b
    forall (p :: * -> *) a b. WrappedPtr p => p a -> p b
    castWrappedPtr OutArray HSize
    buf)

        let decodePt Int
    i = Int -> Int -> Vector HSize -> Vector HSize
    forall a. Storable a => Int -> Int -> Vector a -> Vector a
    SV.slice Int
    i (CInt -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    nDims) Vector HSize
    sizes
            decodeBlock Int
    i = (Int -> Vector HSize
    decodePt Int
    b, Int -> Vector HSize
    decodePt (Int
    b Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + CInt -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    nDims))
                where b :: Int
    b = Int
    i Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * HSize -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral HSize
    blkSize
        return $! V.generate (fromIntegral nBlks) decodeBlock

    getElementSelection :: Dataspace -> IO (V.Vector (SV.Vector HSize))
    getElementSelection :: Dataspace -> IO (Vector (Vector HSize))
    getElementSelection Dataspace
    space = Dataspace -> HSize -> HSize -> IO (Vector (Vector HSize))
    getElementSelectionPointList Dataspace
    space HSize
    0 HSize
    forall a. Bounded a => a
    maxBound

    getElementSelectionNPoints :: Dataspace -> IO HSize
    getElementSelectionNPoints :: Dataspace -> IO HSize
    getElementSelectionNPoints (Dataspace HId_t
    space_id) =
        (HSSize_t -> HSize) -> IO HSSize_t -> IO HSize
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HSSize_t -> HSize
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (IO HSSize_t -> IO HSize) -> IO HSSize_t -> IO HSize
    forall a b. (a -> b) -> a -> b
    $
            (HSSize_t -> Bool) -> IO HSSize_t -> IO HSSize_t
    forall t. (t -> Bool) -> IO t -> IO t
    withErrorWhen (HSSize_t -> HSSize_t -> Bool
    forall a. Ord a => a -> a -> Bool
    < HSSize_t
    0) (IO HSSize_t -> IO HSSize_t) -> IO HSSize_t -> IO HSSize_t
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> IO HSSize_t
    h5s_get_select_elem_npoints HId_t
    space_id

    getElementSelectionPointList :: Dataspace -> HSize -> HSize -> IO (V.Vector (SV.Vector HSize))
    getElementSelectionPointList :: Dataspace -> HSize -> HSize -> IO (Vector (Vector HSize))
    getElementSelectionPointList space :: Dataspace
    space@(Dataspace HId_t
    space_id) HSize
    startPoint HSize
    numPoints = do
        n <- Dataspace -> IO HSize
    getElementSelectionNPoints Dataspace
    space
        nDims <- getSimpleDataspaceExtentNDims space

        let nPts = HSize -> HSize -> HSize
    forall a. Ord a => a -> a -> a
    min HSize
    numPoints (HSize
    n HSize -> HSize -> HSize
    forall a. Num a => a -> a -> a
    - HSize
    startPoint)
            sz = HSize
    nPts HSize -> HSize -> HSize
    forall a. Num a => a -> a -> a
    * CInt -> HSize
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    nDims

        rawPoints <- withOutVector_ (fromIntegral sz) $ \OutArray HSize
    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 -> HSize_t -> HSize_t -> OutArray HSize_t -> IO HErr_t
    h5s_get_select_elem_pointlist HId_t
    space_id (HSize -> HSize_t
    hSize HSize
    startPoint) (HSize -> HSize_t
    hSize HSize
    nPts) (OutArray HSize -> OutArray HSize_t
    forall a b. OutArray a -> OutArray b
    forall (p :: * -> *) a b. WrappedPtr p => p a -> p b
    castWrappedPtr OutArray HSize
    buf)

        let unpackPt Int
    i = Int -> (Int -> HSize) -> Vector HSize
    forall a. Storable a => Int -> (Int -> a) -> Vector a
    SV.generate (CInt -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    nDims) ((Int -> HSize) -> Vector HSize) -> (Int -> HSize) -> Vector HSize
    forall a b. (a -> b) -> a -> b
    $ \Int
    j -> Vector HSize
    rawPoints Vector HSize -> Int -> HSize
    forall a. Storable a => Vector a -> Int -> a
    SV.! (Int
    i Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    j Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * HSize -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral HSize
    nPts)

        return $! V.generate (fromIntegral nPts) unpackPt

    getSelectionBounds :: Dataspace -> IO [(HSize, HSize)]
    getSelectionBounds :: Dataspace -> IO [(HSize, HSize)]
    getSelectionBounds space :: Dataspace
    space@(Dataspace HId_t
    space_id) = do
        n <- Dataspace -> IO CInt
    getSimpleDataspaceExtentNDims Dataspace
    space

        (start, end) <-
            withOutList (fromIntegral n) $ \OutArray HSize_t
    start ->
                Int -> (OutArray HSize_t -> IO ()) -> IO [HSize_t]
    forall a (m :: * -> *) b.
    (Storable a, MonadIO m) =>
    Int -> (OutArray a -> m b) -> m [a]
    withOutList_ (CInt -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    n) ((OutArray HSize_t -> IO ()) -> IO [HSize_t])
    -> (OutArray HSize_t -> IO ()) -> IO [HSize_t]
    forall a b. (a -> b) -> a -> b
    $ \OutArray HSize_t
    end ->
                    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 -> OutArray HSize_t -> OutArray HSize_t -> IO HErr_t
    h5s_get_select_bounds HId_t
    space_id OutArray HSize_t
    start OutArray HSize_t
    end

        return [(HSize s, HSize e) | (s,e) <- zip start end]

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

    selectionType :: H5S_sel_type -> Maybe SelectionType
    selectionType :: H5S_sel_type -> Maybe SelectionType
    selectionType H5S_sel_type
    c
        | H5S_sel_type
    c H5S_sel_type -> H5S_sel_type -> Bool
    forall a. Eq a => a -> a -> Bool
    == H5S_sel_type
    h5s_SEL_NONE         = Maybe SelectionType
    forall a. Maybe a
    Nothing
        | H5S_sel_type
    c H5S_sel_type -> H5S_sel_type -> Bool
    forall a. Eq a => a -> a -> Bool
    == H5S_sel_type
    h5s_SEL_POINTS       = SelectionType -> Maybe SelectionType
    forall a. a -> Maybe a
    Just SelectionType
    Points
        | H5S_sel_type
    c H5S_sel_type -> H5S_sel_type -> Bool
    forall a. Eq a => a -> a -> Bool
    == H5S_sel_type
    h5s_SEL_HYPERSLABS   = SelectionType -> Maybe SelectionType
    forall a. a -> Maybe a
    Just SelectionType
    Hyperslabs
        | Bool
    otherwise                 = String -> Maybe SelectionType
    forall a. HasCallStack => String -> a
    error (String
    "unknown h5s_SEL value" String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ H5S_sel_type -> String
    forall a. Show a => a -> String
    show H5S_sel_type
    c)

    getSelectionType :: Dataspace -> IO (Maybe SelectionType)
    getSelectionType :: Dataspace -> IO (Maybe SelectionType)
    getSelectionType (Dataspace HId_t
    space_id) =
        (H5S_sel_type -> Maybe SelectionType)
    -> IO H5S_sel_type -> IO (Maybe SelectionType)
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap H5S_sel_type -> Maybe SelectionType
    selectionType (IO H5S_sel_type -> IO (Maybe SelectionType))
    -> IO H5S_sel_type -> IO (Maybe SelectionType)
    forall a b. (a -> b) -> a -> b
    $
            (H5S_sel_type -> Bool) -> IO H5S_sel_type -> IO H5S_sel_type
    forall t. (t -> Bool) -> IO t -> IO t
    withErrorWhen (\(H5S_sel_type Int32
    c) -> Int32
    c Int32 -> Int32 -> Bool
    forall a. Ord a => a -> a -> Bool
    < Int32
    0) (IO H5S_sel_type -> IO H5S_sel_type)
    -> IO H5S_sel_type -> IO H5S_sel_type
    forall a b. (a -> b) -> a -> b
    $
                HId_t -> IO H5S_sel_type
    h5s_get_select_type HId_t
    space_id