Some example to use the API:
http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/api16-m.html
vlen example showing the use of cell arrays to input the data:
http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/matlab/HDF5_M_Examples-1.6/h5ex_t_vlen.m
compound data creation example:
http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/matlab/HDF5_M_Examples-1.6/h5ex_t_cmpd.m
I was not able to make out what datatypes you wanted. (The data was signed and unsigned, but the HDF5 types were only unsigned). And I wasnt sure if your compound had 2 or 3 elements.
So I went ahead and combined the API examples above , and updating them to use H5T.get_size arrived at this:
fileName = 'h5ex_t_cmpd.h5';
DATASET = 'DS1';
DIM0 = 4;
dims = DIM0;
%
% Initialize data.
%
wdata.serial_no =int32([1153 ; 1184 ; 1027 ; 1313]);
wdata.temperature =[53.23; 55.12; 130.55; 1252.89];
% this would be the variable length element. Note the use of cell arrays.
wdata.pressure ={int32([1 2 3]) int32([ 12 ]) int32([3 4 5]) int32([4 5 6 7])};
%
%% Create a new file using the default properties.
%
file = H5F.create (fileName, 'H5F_ACC_TRUNC', 'H5P_DEFAULT', 'H5P_DEFAULT');
% Create a vlen data type for pressure
vlenMemType = H5T.vlen_create ('H5T_NATIVE_INT');
vlenFileType = H5T.vlen_create ('H5T_STD_I32LE');
%
% Create the compound datatype for memory.
%
compoundSize = H5T.get_size('H5T_NATIVE_INT')+...
H5T.get_size('H5T_NATIVE_DOUBLE')+...
H5T.get_size(vlenMemType);
memtype = H5T.create ('H5T_COMPOUND', compoundSize);
H5T.insert (memtype, 'serial_no',...
0, ... % this is the size of all previous elements.0 for the first one.
'H5T_NATIVE_INT');
H5T.insert (memtype, 'temperature',...
H5T.get_size('H5T_NATIVE_INT'),...
'H5T_NATIVE_DOUBLE');
H5T.insert (memtype, 'pressure',...
H5T.get_size('H5T_NATIVE_INT')+ H5T.get_size('H5T_NATIVE_DOUBLE'),...
vlenMemType);
%
% Create the compound datatype for the file. Because the standard
% types we are using for the file may have different sizes than
% the corresponding native types, we must manually calculate the
% offset of each member.
%
filetype = H5T.create ('H5T_COMPOUND', compoundSize);
H5T.insert (filetype, 'serial_no', 0, 'H5T_STD_I32LE');
H5T.insert (filetype, 'temperature',...
H5T.get_size('H5T_STD_I32LE'),...
'H5T_IEEE_F64BE');
H5T.insert (filetype, 'pressure',...
H5T.get_size('H5T_STD_I32LE')+ H5T.get_size('H5T_IEEE_F64BE'),...
vlenFileType);
%
% Create dataspace. Setting maximum size to [] sets the maximum
% size to be the current size.
%
space = H5S.create_simple (1,fliplr( dims), []);
%
% Create the dataset and write the compound data to it.
%
dset = H5D.create (file, DATASET, filetype, space, 'H5P_DEFAULT');
H5D.write (dset, memtype, 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT', wdata);
%
% Close and release resources.
%
H5D.close (dset);
H5S.close (space);
H5T.close (filetype);
H5F.close (file);
Resulting hdf5dump:
HDF5 "h5ex_t_cmpd.h5" {
GROUP "/" {
DATASET "DS1" {
DATATYPE H5T_COMPOUND {
H5T_STD_I32LE "serial_no";
H5T_IEEE_F64BE "temperature";
H5T_VLEN { H5T_STD_I32LE} "pressure";
}
DATASPACE SIMPLE { ( 4 ) / ( 4 ) }
DATA {
(0): {
1153,
53.23,
(1, 2, 3)
},
(1): {
1184,
55.12,
(12)
},
(2): {
1027,
130.55,
(3, 4, 5)
},
(3): {
1313,
1252.89,
(4, 5, 6, 7)
}
}
}
}
The crash is most likely due to array inputs for vlen data types.
The code expects cell arrays. We will look into making this more robust.
Ashish