How to add 'ChunkSize' in .h5 file?

15 views (last 30 days)
Axel
Axel on 30 Aug 2019
Answered: Manas Meena on 30 Sep 2020
I would like to resize my dataset (as shown in the attached picture) from 2x20 to 2x3. To achieve this it is necessary to have the ChunkSize to be 2x3. I have been trying to fix this for hours now without any luck. This what I have done so far...
% Ok!, Now let's set the writable attribute of FileName
fileattrib(FileName,'+w');
fid = H5F.open(FileName,'H5F_ACC_RDWR','H5P_DEFAULT');
dset_id = H5D.open(fid,DatasetName);
dcpl = H5D.get_create_plist(dset_id);
chunk_dims = [2 3];
% set it to use the chunked dataset
h5_chunk_dims = fliplr(chunk_dims);
H5P.set_chunk(dcpl,h5_chunk_dims)
% Change size of dataset
H5D.set_extent(dset_id,[3,2]) %[THIS DOES NOT WORK and throw the messag]
=================================
Error using hdf5lib2
The HDF5 library encountered an error and produced the following stack trace information:
H5D__set_extent dataset has contiguous storage
H5Dset_extent unable to set extend dataset
Error in H5D.set_extent (line 27)
H5ML.hdf5lib2('H5Dset_extent', dset_id, h5_extents);

Answers (1)

Manas Meena
Manas Meena on 30 Sep 2020
The error might be because the library cannot find the file/variable that was passed in the “H5P.set_extent” command.
Refer to the below documentation links on how to use the H5P.set_chunk” and “H5P.set_extent” commands:
You can also refer to the following link to see how to replace a dataset with a smaller dataset in a HDF5 file:

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!