-
Notifications
You must be signed in to change notification settings - Fork 30
Cookbook : Datasets
Alexander edited this page Feb 11, 2019
·
3 revisions
This snippet reads a dataset from the specified file.
Private Function Read_dataset(ByVal hdf5file As Long, ByVal dsname As String)
Dim dsID = H5D.open(hdf5file, dsname, H5P.DEFAULT)
Dim spaceID = H5D.get_space(dsID)
Dim typeID = H5D.get_type(dsID)
Dim rank = H5S.get_simple_extent_ndims(spaceID)
Dim dims(rank - 1) As ULong
Dim maxDims(rank - 1) As ULong
H5S.get_simple_extent_dims(spaceID, dims, maxDims)
Dim sizeData = H5T.get_size(typeID)
Dim size = sizeData.ToInt32()
Dim bytearray_elements = 1
For i = 0 To dims.Length - 1
bytearray_elements *= dims(i)
Next
Dim dataBytes(bytearray_elements * CULng(size)) As Byte
Dim pinnedArray As GCHandle = GCHandle.Alloc(dataBytes, GCHandleType.Pinned)
H5D.read(dsID, typeID, H5S.ALL, H5S.ALL, H5P.DEFAULT, pinnedArray.AddrOfPinnedObject())
pinnedArray.Free()
For i = 0 to bytearray_elements - 1:
Dim slice = dataBytes.Skip(i * size).Take(size).ToArray()
Dim val = BitConverter.ToInt32(slice, 0) ' This line depends on the type of your dataset
Next
End Function