Help with array of compound type

I am using HDF5 in C# via HDF.PInvoke.1.10. I have an array of a compound type that I wish to add to an encompassing compound type. When I get the size of the array type to add it to the encompassing compound type, it returns what appears to be a invalid pointer location.

hsize_t[] max_dims = { H5S.UNLIMITED };
hid_t header_array = H5T.array_create(_header_kvt, 1, max_dims);
H5T.get_size(header_array);

Returns:
0xffffffffffffffe0

Thanks,
Vince

If I set the size to 32 (which is the size of the elements in the compound type) it works. However I get an exception when trying to write to a file.

Hi @vince.gibson,

Given that the issue described in your post is not very clear, would you mind sharing the C# code and the HDF5 file it generates, as well as indicating the HDF5 object stored in this file that you want to retrieve the dimensions from? This will help the community to better understand the issue and eventually help you with it.

This is the code to create the dataset:

// Create compound type for headers
// Variable length string for model name type
hid_t header_model_name_t = H5T.create(H5T.class_t.STRING, H5T.VARIABLE);
Debug.Assert(STRING_TYPE_SIZE == (int)H5T.get_size(header_model_name_t));

// Variable length string for message name type
hid_t header_message_name_t = H5T.create(H5T.class_t.STRING, H5T.VARIABLE);
Debug.Assert(STRING_TYPE_SIZE == (int)H5T.get_size(header_message_name_t));

// a variable-length array type
hid_t eight_bit_t = H5T.copy(H5T.NATIVE_UINT8);
hid_t header_vlba = H5T.vlen_create(eight_bit_t);
int data_payload_size = (int)H5T.get_size(header_vlba);

// Size for Model name (string), Message name (string) and variable length data
int temp_header_size = STRING_TYPE_SIZE + STRING_TYPE_SIZE + data_payload_size;
_header_kvt = H5T.create(H5T.class_t.COMPOUND, temp_header_size);
int header_offset = 0;
Check_HDF(H5T.insert(_header_kvt, “header_model_name”, header_offset, header_model_name_t));
header_offset += STRING_TYPE_SIZE;
Check_HDF(H5T.insert(_header_kvt, “header_message_name”, header_offset, header_message_name_t));
header_offset += STRING_TYPE_SIZE;
Check_HDF(H5T.insert(_header_kvt, “header_message_data”, header_offset, header_vlba));

// Fixed length timestamp type
hid_t timestamp_t = H5T.copy(H5T.IEEE_F64LE);
Debug.Assert(TIMESTAMP_SIZE == (int)H5T.get_size(timestamp_t));

// Connection type
hid_t connection_t = H5T.copy(H5T.NATIVE_INT32);
Debug.Assert(CONNECTION_SIZE == (int)H5T.get_size(connection_t));

// Variable length string for message name type
hid_t message_name_t = H5T.create(H5T.class_t.STRING, H5T.VARIABLE);
Debug.Assert(MESSAGE_NAME_SIZE == (int)H5T.get_size(message_name_t));

// Variable length string for the publisher type
hid_t publisher_t = H5T.create(H5T.class_t.STRING, H5T.VARIABLE);
Debug.Assert(MESSAGE_NAME_SIZE == (int)H5T.get_size(publisher_t));

// a variable-length array type
hid_t vlba = H5T.vlen_create(eight_bit_t);

int vl_data_size = (int)H5T.get_size(vlba);

// One dimensional array of compound types
hsize_t[] max_dims = { H5S.UNLIMITED };
hid_t header_array = H5T.array_create(_header_kvt, 1, max_dims);
Check_HDF(header_array);
Check_HDF(H5T.set_size(header_array, 32));
int header_data_size = 32; // (int)H5T.get_size(header_array);
//Check_HDF(header_data_size);

// Create compound type
int temp_size = TIMESTAMP_SIZE + CONNECTION_SIZE + MESSAGE_NAME_SIZE + PUBLISHER_SIZE + vl_data_size + (int)header_data_size;
_kvt = H5T.create(H5T.class_t.COMPOUND, temp_size);
int offset = 0;
Check_HDF(H5T.insert(_kvt, “time stamp us”, offset, timestamp_t));
offset += TIMESTAMP_SIZE;
Check_HDF(H5T.insert(_kvt, “connection”, offset, connection_t));
offset += CONNECTION_SIZE;
Check_HDF(H5T.insert(_kvt, “message_name”, offset, message_name_t));
offset += MESSAGE_NAME_SIZE;
Check_HDF(H5T.insert(_kvt, “publisher”, offset, publisher_t));
offset += PUBLISHER_SIZE;
Check_HDF(H5T.insert(_kvt, “data”, offset, vlba));
offset += (int)vl_data_size;
Check_HDF(H5T.insert(_kvt, “headers”, offset, header_array));

Hi @vince.gibson,

Please check out this post: Trouble using HDF.PInvoke in c# - #3 by gheber for an alternative.