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);
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

Reply via email to