HDF5.net Compound datatype with variable length string

Hello All,

I'm trying to write some attributes to a dataset and I'd like to use a compound data type to hold the information. I'm using C# and the .NET wrapper. I can read/write just regular string and variable length string datasets and/or attributes with the wrapper, but I can't figure out a good way to write with a compound datatype with a variable length string.

I've tried the following:

1) Create a struct with the SequentialLayout attribute. Then, I created a field for each member of the datatype. For the variable length types, I use the IntPtr. In the constructor for the struct, I generate the pointer to the string value.

2) I create a HDF5 compound datatype. I insert fields and for the string types, I use a type derived from C_S1 and set it to variable length. I use an offset of 4 for the length.

3) Then I created a dataset of the new datatype.

4) Next, I create a C# array of the struct values.

5) Finally, I tried writing the array of structs to the dataset.

However, in that last statement I am getting an exception. Is there a transformation of the struct that I need to do before writing the array? I can post the full code that I've tried if that is helpful in diagnosing.

Thanks,
Jesse

Jesse, how are you? Please have a look at the attached IronPython script.
It shows how to write a compound type with two integer members and one
variable-length string member. I'm sure there are more elegant ways, but the
brute force writing of a byte array is effective. We use
BitConverter to get the bytes from the integers and the pointer (converted
to an
integer of the right size). Use Marshal.StringToHGlobalAnsi to obtain a
pointer to a good old-fashioned string on the global heap.
(Free later with Marshal.FreeHGlobal.)

Best, G.

cmpvstr.py (2.14 KB)

ยทยทยท

-----Original Message-----
From: hdf-forum-bounces@hdfgroup.org [mailto:hdf-forum-bounces@hdfgroup.org]
On Behalf Of Jesse Lai
Sent: Monday, January 23, 2012 1:21 PM
To: HDF Users Discussion List
Subject: [Hdf-forum] HDF5.net Compound datatype with variable length string

Hello All,

I'm trying to write some attributes to a dataset and I'd like to use a
compound data type to hold the information. I'm using C# and the .NET
wrapper. I can read/write just regular string and variable length string
datasets and/or attributes with the wrapper, but I can't figure out a good
way to write with a compound datatype with a variable length string.

I've tried the following:

1) Create a struct with the SequentialLayout attribute. Then, I created a
field for each member of the datatype. For the variable length types, I use
the IntPtr. In the constructor for the struct, I generate the pointer to
the string value.

2) I create a HDF5 compound datatype. I insert fields and for the string
types, I use a type derived from C_S1 and set it to variable length. I use
an offset of 4 for the length.

3) Then I created a dataset of the new datatype.

4) Next, I create a C# array of the struct values.

5) Finally, I tried writing the array of structs to the dataset.

However, in that last statement I am getting an exception. Is there a
transformation of the struct that I need to do before writing the array? I
can post the full code that I've tried if that is helpful in diagnosing.

Thanks,
Jesse

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org