Skip to content

Instantly share code, notes, and snippets.

@jmcarthur
Forked from carlohamalainen/gist:1187895
Created September 2, 2011 04:12
Show Gist options
  • Save jmcarthur/1187906 to your computer and use it in GitHub Desktop.
Save jmcarthur/1187906 to your computer and use it in GitHub Desktop.
ncInq :: NCID -> IO (Int, Int, Int, Int)
ncInq ncid =
alloca $ \ndims_ptr ->
alloca $ \nvars_ptr ->
alloca $ \natts_ptr ->
alloca $ \unlimdimid_ptr -> do
status <- nc_inq ncid ndims_ptr nvars_ptr natts_ptr unlimdimid_ptr
ndims <- peek ndims_ptr
nvars <- peek nvars_ptr
natts <- peek natts_ptr
unlimdimid <- peek unlimdimid_ptr
return (fromEnum ndims, fromEnum nvars, fromEnum natts, fromEnum unlimdimid)
ncInq :: NCID -> IO (Int, Int, Int, Int)
ncInq ncid = (`runContT` return) $ do
ndims_ptr <- newPtr
nvars_ptr <- newPtr
natts_ptr <- newPtr
unlimdimid_ptr <- newPtr
liftIO $ do
status <- nc_inq ncid ndims_ptr nvars_ptr natts_ptr unlimdimid_ptr
ndims <- peek ndims_ptr
nvars <- peek nvars_ptr
natts <- peek natts_ptr
unlimdimid <- peek unlimdimid_ptr
return (fromEnum ndims, fromEnum nvars, fromEnum natts, fromEnum unlimdimid)
where newPtr = ContT alloca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment