HDF5 library encounter problems when write into a hyperslab of data matrix which was chunked+deflated

HDF5 can write a 3D matrix as a whole into .h5 file, or write only a defined portion(hyperslab) of matrix into the specific position of the whole Data Matrix created in h5 file.

However, when the Data Matrix was created in chunk mode(with deflated turn on) instead of H5P_DEFAULT, “write as a whole” still works, but “write a portion(hyperslab)” no longer works.

I have tried four mode of writing matrix into h5 file:

write as a whole into data created by H5P_DEFAULT in .h5 file: works OK.
write as a whole into data created by Chunk&Deflate in .h5 file: works OK.
write as a portion(hyperslab) into data created by H5P_DEFAULT in .h5 file: works OK.
write as a portion(hyperslab) into data created by Chunk&Deflate in .h5 file: not work.
Below is the matlab code:

turn_on_chunk_deflate = 0 % works

turn_on_chunk_deflate = 1 % does not work

%% ============write as portion============
turn_on_chunk_deflate = 0; % 0 is off and works, 1 is on and not work

% create a h5 file and data container 'DataSet''
outFile = 'D:\example.h5';

fid = H5F.create(outFile);
gid0 = H5G.open(fid,'/');
plist = 'H5P_DEFAULT';

% create data body "Data'
dims = [100,100,100];
h5_dims = fliplr(dims);% matlab and hdf5.jar's dim are inverted
h5_maxdims = h5_dims;% max dimension
space_id = H5S.create_simple(length(dims),h5_dims,h5_maxdims);
gid = H5G.open(fid,'/DataSet');
type_id = H5T.copy('H5T_NATIVE_UINT8');

    % plist: this is the crucial part that cause the error
        if ~turn_on_chunk_deflate
            % without deflate : runs OK!
            plist = 'H5P_DEFAULT';
            % with deflate 0~9 & chunk[20,20,20]; Not work in final H5D.write!
            plist = H5P.create('H5P_DATASET_CREATE');
            h5_chunk = [20,20,20];
            deflate = 1; %turn on deflate


% write data
start = [2,3,4]; % Note! location is 0-based, not 1-based!
h5_start = fliplr(start);
block = [11,23,25];% block size along xyz
h5_block = fliplr(block);
mem_space_id = H5S.create_simple(length(dims),h5_block,[]);
gid = H5D.open(fid,['/DataSet/Data']);
space_id = H5D.get_space(gid);
data = ones(block);

The error:

Error using hdf5lib2
The HDF5 library encountered an unknown error.

Error in H5D.write (line 71)
H5ML.hdf5lib2('H5Dwrite', varargin{:});

Error in HDF5_test (line 56)

I think the problem is the plist passed to H5D.write. If your code is indeed as shown, plist in H5D.write is still the dataset creation property list shown earlier. However, H5D.write expects a dataset transfer property list. Please try H5P_DEFAULT as (default) dataset transfer property list!

Hi, gheber,

You are right! It works now. Thank you very much.