Array of compound

Hi everybody,

I have two main problem with working with HDF5, some of you may have the solution:

  1. I am trying to create an array of compound (the compound can contain several fields, which can also be arrays).

Example:

“tata(1).heh=[2:2:20];
tata(2).heh=[2:4:40];”

I tried to method which both didn’t work :slight_smile:

a) "file=H5F.open(name_of_HDF5_file,‘H5F_ACC_RDWR’,‘H5P_DEFAULT’);

dataspace = H5S.create_simple(2, [1 2], []);

doubleType=H5T.copy(‘H5T_NATIVE_DOUBLE’);
member(1).datatype = H5T.array_create(doubleType, 1, length(tata(1).heh), []);
sz(1) =H5T.get_size(member(1).datatype);

% Computer the offsets of each field. The first offset is always zero
offset(1)=0;
memtype = H5T.create(‘H5T_COMPOUND’,sum(sz));

H5T.insert(memtype,‘heh’,offset(1),member(1).datatype);

base_type=H5T.copy(memtype);

datatype=H5T.array_create(base_type, 2, [1 2],[]);

dataset = H5D.create(file, dataset, datatype, dataspace,‘H5P_DEFAULT’);

H5D.write(dataset, datatype, ‘H5S_ALL’, ‘H5S_ALL’, ‘H5P_DEFAULT’, tata);"

b)"file=H5F.open(name_of_HDF5_file,‘H5F_ACC_RDWR’,‘H5P_DEFAULT’);

doubleType=H5T.copy(‘H5T_NATIVE_DOUBLE’);
member(1).datatype = H5T.array_create(doubleType, 1, length(tata(1).heh), []);
sz(1) =H5T.get_size(member(1).datatype);

% Computer the offsets of each field. The first offset is always zero
offset(1)=0;
memtype = H5T.create(‘H5T_COMPOUND’,sum(sz));
H5T.insert(memtype,‘heh’,offset(1),member(1).datatype);

% Create dataspace. Setting maximum size to [] sets the maximum size to be the current size
space = H5S.create_simple(2,[1 2], []);

dset_id = H5D.create(file, dataset, memtype, space, ‘H5P_DEFAULT’);

H5D.write(dset_id, memtype, ‘H5S_ALL’, ‘H5S_ALL’, ‘H5P_DEFAULT’, tata);"

has anyone any ideas of what I did bad?

  1. I am trying to read a part of an array which is inside a structure

“tata(1).heh=[2:2:20];
tata(2).heh=[2:4:40];”

tata(2).heh(1)=2;

I used hyperslab but the only thing I managed to get is the entire array. I am wondering whether or not this is possible.

thanks for reading

Antoine

Hello Antoine,

A subset cannot be selected from a dataset with an H5T_ARRAY datatype.

See the second paragraph in section 6.5.2.2.2 “Array” in the HDF5 User’s Guide.
A link to Chapter 6.5.2 can be reached here:

https://bitbucket.hdfgroup.org/pages/HDFFV/hdf5doc/master/browse/html/UG/HDF5_Users_Guide-Responsive%20HTML5/index.html#t=HDF5_Users_Guide%2FDatatypes%2FHDF5_Datatypes.htm%23TOC_6_5_2_Definition_ofbc-14&rhtocid=6.3.0_2

Also see the table in that section, Table 6-21.

-Barbara
help@hdfgroup.org

So can we / are we able to insert an array datatype into a compound dataset?
I am facing a similar issue these days, really appreciate for any help
here is my question

Hi @kli,

Yes, you can insert an array field into a compound dataset at the time of creation - not sure how this is done using MATLAB low-level API though. Keep in mind that it is not possible to change the compound characteristics once created (e.g. add/remove/rename members, change data types or dimensions).

Hope it helps!

thanks
I do have figured out MATLAB low-level solution already

btw, do you know if the compound dataset is able to compress or not? I have tried to compress, but keep getting errors

best