Extending compound dataset (Matlab)

Dear forum members,

I am trying to extend a dataset in Matlab with the low-level API. The underlying datatype is compound.

···

###############

Code: ##########

###############

% create file

FILE ='myFile.h5';
file = H5F.create(FILE, 'H5F_ACC_TRUNC', 'H5P_DEFAULT', 'H5P_DEFAULT');

% create compound datatype
memtype = H5T.create ('H5T_COMPOUND', 32);
H5T.insert (memtype, 'serial_no', 0 ,'H5T_NATIVE_DOUBLE');
H5T.insert (memtype, 'location', 8, 'H5T_NATIVE_DOUBLE');
H5T.insert (memtype, 'wurz', 16, 'H5T_NATIVE_DOUBLE');

% create compound datatype
filetype = H5T.create ('H5T_COMPOUND', 32);
H5T.insert (filetype, 'serial_no', 0 ,'H5T_NATIVE_DOUBLE');
H5T.insert (filetype, 'location', 8, 'H5T_NATIVE_DOUBLE');
H5T.insert (filetype, 'wurz', 16, 'H5T_NATIVE_DOUBLE');

% create unlimited filespace
H5S_UNLIMITED = H5ML.get_constant_value('H5S_UNLIMITED');
maxdims = [H5S_UNLIMITED];
memspace = H5S.create_simple(1, fliplr(0), fliplr(maxdims));

% create data set
dcpl = H5P.create('H5P_DATASET_CREATE');
H5P.set_chunk (dcpl, fliplr(1));

dset = H5D.create(file, 'DS',filetype ,memspace, dcpl);
bSpace = H5D.get_space(dset);
%dset = H5D.create (file, 'DS', filetype, memspace, 'H5P_DEFAULT');

% fill element-wise
for i=1:10

    % create test data
    wdata.location = i;
    wdata.serial_no = i*10;
    wdata.wurz = -i*10;

    % extend data set
    H5D.extend(dset, i);
    space = H5D.get_space(dset);
    H5S.select_all(space);

    H5S.select_hyperslab(space,'H5S_SELECT_SET', i-1, 1, 1 ,1);

    % write initial slab
    %H5D.write (dset, memtype, 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT', wdata);
    H5D.write(dset, memtype, 'H5S_ALL', space, 'H5P_DEFAULT',wdata);

    H5S.close (space);

end

% Extend Existing Dataset Dimensions
%h5_newdims = fliplr(2000);

% H5S.select_hyperslab(space,'H5S_SELECT_SET', 0,[],1000,[]);
%H5S.select_hyperslab(space, 'H5S_SELECT_SET', 1000, [], 1000, []);

%H5S.select_hyperslab(space_id,'H5S_SELECT_SET', 1000, [], [], 1000);

%status = H5Dwrite(dataset, s1_tid, memspace, space, H5P_DEFAULT, s1);

%for i = 1:1000
    %H5D.write (dset, memtype, 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT', wdata);
    %H5D.write(dset, memtype, 'H5S_ALL', space_id, 'H5P_DEFAULT',wdata);
    %disp(num2str(i))
%end

H5D.close(dset);
%H5S.close (space);
H5T.close (filetype);
H5T.close (memtype);

% close file
H5F.close(file);

Dear forum members,

I am trying to extend a dataset in Matlab with the low-level API. The underlying datatype is compound.

···

###############

Code: ##########

###############

% create file

FILE ='myFile.h5';
file = H5F.create(FILE, 'H5F_ACC_TRUNC', 'H5P_DEFAULT', 'H5P_DEFAULT');

% create compound datatype
memtype = H5T.create ('H5T_COMPOUND', 32);
H5T.insert (memtype, 'serial_no', 0 ,'H5T_NATIVE_DOUBLE');
H5T.insert (memtype, 'location', 8, 'H5T_NATIVE_DOUBLE');
H5T.insert (memtype, 'wurz', 16, 'H5T_NATIVE_DOUBLE');

% create compound datatype
filetype = H5T.create ('H5T_COMPOUND', 32);
H5T.insert (filetype, 'serial_no', 0 ,'H5T_NATIVE_DOUBLE');
H5T.insert (filetype, 'location', 8, 'H5T_NATIVE_DOUBLE');
H5T.insert (filetype, 'wurz', 16, 'H5T_NATIVE_DOUBLE');

% create unlimited filespace
H5S_UNLIMITED = H5ML.get_constant_value('H5S_UNLIMITED');
maxdims = [H5S_UNLIMITED];
memspace = H5S.create_simple(1, fliplr(0), fliplr(maxdims));

% create data set
dcpl = H5P.create('H5P_DATASET_CREATE');
H5P.set_chunk (dcpl, fliplr(1));

dset = H5D.create(file, 'DS',filetype ,memspace, dcpl);
bSpace = H5D.get_space(dset);
%dset = H5D.create (file, 'DS', filetype, memspace, 'H5P_DEFAULT');

% fill element-wise
for i=1:10

    % create test data
    wdata.location = i;
    wdata.serial_no = i*10;
    wdata.wurz = -i*10;

    % extend data set
    H5D.extend(dset, i);
    space = H5D.get_space(dset);
    H5S.select_all(space);

    % select hyperslab
    H5S.select_hyperslab(space,'H5S_SELECT_SET', i-1, 1, 1 ,1);

    % write data
    H5D.write(dset, memtype, 'H5S_ALL', space, 'H5P_DEFAULT',wdata);

    % close file space
    H5S.close (space);

end

H5D.close(dset);
H5T.close (filetype);
H5T.close (memtype);
H5F.close(file);

######################

Unfortunately my program does not do what I intend: Instead of filling element-wise, it will only copy the first compound data to the hdf5-file:

##################################

Output of dataset DS from HDF5 viewer:

##################################

serial_no location wurz

1.0 10.0 -10.0
0.0 0.0 0.0
0.0 0.0 0.0
-1.288480843725888E-231 -3.786504882356714E-270 -3.786504882356956E-270
4.9E-324 9.8117197E-315 9.81183448E-315
4.5792095E-316 9.8117197E-315 9.81183448E-315
9.792595565E-315 9.8117197E-315 9.81183448E-315
8.4E-323 4.9E-324 1.353122016E-315
9.79259493E-315 8.49433059E-315 2.121477727E-314
8.4E-323 9.790301677E-315 5.295032923E-315

##################################

Can anybody help?

Thanks,

Daniel