Hi,
I am using HDF.PInvoke 1.10.0.4 but I am struggling to read the string
value of an attribute when it is variable length.
Ultimately I believe I need to call:
GCHandle hnd = GCHandle.Alloc(*data*, GCHandleType.Pinned);
int err = H5A.read(aid, *typeId*, hnd.AddrOfPinnedObject());
hnd.Free()
What’s the storage layout of the attribute?
(i.e., is it H5S_SIMPLE or H5S_SCALAR?)
G.
From: Hdf-forum [mailto:hdf-forum-boun...@lists.hdfgroup.org] On Behalf Of Matt
Wood
Sent: Thursday, March 30, 2017 9:42 AM
To: hdf-forum@lists.hdfgroup.org
Subject: [Hdf-forum] Reading VLEN string attribute v
Try something like this, if you want a single string (not tested):
int byteLength = Marshal.SizeOf(Of IntPtr);
IntPtr intPtr = Marshal.AllocHGlobal(byteLength);
H5A.read(attributeId, attributeTypeId, intPtr);
string result = Marshal.PtrToStringAnsi(intPtr);
If you want a more general way to rea
The output from h5dump is:
ATTRIBUTE "ORIGIN" {
DATATYPE H5T_STRING {
STRSIZE H5T_VARIABLE;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_ASCII;
CTYPE H5T_C_S1;
}
DATASPACE SIMPLE { ( 1 ) / ( 1 ) }
DATA {
(0): "BASIC"
}
}
And I tried:
int byteLength = Marsha
The dataspace is simple, i.e., it's an array which in this case
happens to have only one element. (This is NOT the same as a scalar attribute!)
Have a look at H5DreadTest2 in
https://github.com/HDFGroup/HDF.PInvoke/blob/master/UnitTests/H5DTest/H5Dread.cs
[TestMethod]
public void
Many thanks, that worked a treat. I have attached my working method below.
Matt
///
/// Helper method that extracts a string array value from a variable
length attribute.
/// See
https://github.com/HDFGroup/HDF.PInvoke/blob/master/UnitTests/H5DTest/H5Dread.cs
///
/// The id of the attribute
Glad to hear that it works.
Don’t forget to free the buffer(s) that the HDF5 library
allocated for those strings or you’ll have created a memory leak:
Assert.IsTrue(H5.free_memory(rdata[i]) >= 0);
G.
From: Hdf-forum [mailto:hdf-forum-boun...@lists.hdfgroup.org] On Behalf Of Matt
Wood
Sent: Thu
Dear all,
we are using HDF5 in our collaboration to store large event data of neutrino
interactions. The data itself has a very simple structure but I still could not
find a acceptable way to design the structure of the HDF5 format. It would be
great if some HDF5 experts could give me a hint h