using variable length integer array in a compound data type

Hello all -

I have scoured the internet and cannot find any example code for what
I am trying to do.

Using matlab, I am trying to insert a variable length integer array
(2 x 1) into a compound data type. I can insert a compound datatype
and I can insert variable length strings. Here is my code:

data.temp1 = uint32([7; 0]);
data.temp2 = int32([0; 0]);

intType1=H5T.copy('H5T_NATIVE_UINT');
sz(1) =H5T.get_size(intType1);
intType2=H5T.copy('H5T_STD_U32LE');
varType1 =H5T.vlen_create(intType1);
sz(2) =H5T.get_size(varType1);
sz(3) =H5T.get_size(intType2);

offset(1)=0;
offset(2:3)=cumsum(sz(1:2));
sz(3) = 0;

%
% Create the compound datatype for memory.
%

memtype = H5T.create ('H5T_COMPOUND', sum(sz));
varType1 =H5T.vlen_create(intType1);
varType2 =H5T.vlen_create(intType2);

H5T.insert (memtype,...
   'resolution',offset(1),intType1);
H5T.insert (memtype,...
   'badValues',offset(2), varType1);

filetype = H5T.create ('H5T_COMPOUND', sum(sz));
H5T.insert (filetype, 'Temp1', offset(1),intType2);
H5T.insert (filetype, 'Temp2, offset(2),varType2);

space = H5S.create_simple (1,fliplr(2), []);
%
% Create the dataset and write the compound data to it.
%
dset = H5D.create (BandStats, BandStatData{1}, memtype, space, 'H5P_DEFAULT');
H5D.write (dset, filetype, 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT', data);

The code runs, but MatLab crashes after the write command.

Any help would GREATLY be appreciated.

Thank you.
Ben

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