I am trying to write a set of fields to a H5Table, not knowing what the fields are apriori.
Calculating the offsets here has been an issue, since HOFFSET/offsetof cannot be used due to absence of a predefined struct. I am calculating the offsets assuming contiguous allocation and no padding which may be erroneous.
Is there an alternative way to handle such a situation.
HDF5-DIAG: Error detected in HDF5 (1.14.5):
#000: /home/gsabhishek/Downloads/hdf5-1.14.5/src/H5Tcompound.c line 340 in H5Tinsert(): unable to insert member
major: Datatype
minor: Unable to insert object
#001: /home/gsabhishek/Downloads/hdf5-1.14.5/src/H5Tcompound.c line 421 in H5T__insert(): member extends past end of compound type
major: Datatype
minor: Unable to insert object
Similar to this post, but I cannot use H5QL as of now.
The error message is clear: H5T__insert(): member extends past end of compound type. How about you check the invariant field_offsets[i] + H5Tget_size(field_types[i]) <= tot_size in the H5Tinsert loop?
A follow up issue I have is regarding the creation of a data buffer we pass to H5TBmake_table
I am trying to create a void pointer for the data. Since we have a variable length string, the size of the void pointer may not be equal to the compound_dtype_size and the offsets calculated during the creation of compound_dtype would also not be valid anymore.
So here I tried to calculate the new offsets and field sizes. The code runs fine, but when I open the table with hdfview I get an error and the fields are not populated.
I recommend you read the section on string handling in the HDF5 user guide and look at this example. The gist is that the API for variable-length strings works with pointers. In a structure/compound datatype, the corresponding field of the nominal structure is a pointer and not an array of characters. In your snippet, the field would potentially have a different size, data2[n].size(), for each string, which is not how structures work. OK?