Reputation: 1372
I have a HDF5 datafile that has an array of int32 data values. I wish to change the data stored in that array to different values which are of a different format (double).
for example I can query the data type with the following:
finf=h5info('file.hdf5');
finf.Datasets(1).Datatype
ans =
Name: ''
Class: 'H5T_INTEGER'
Type: 'H5T_STD_I32LE'
Size: 4
Attributes: []
If I try to recreate the data in the same node location it gives me the following error that the data set already exists:
t=double(h5read([filepath filename],'/t'));
% more t calculations here....
h5create('file.hdf5','/t',size(t),'DataType','double');
Error using h5create>create_dataset (line 159)
The dataset '/t' already exists.
Error in h5create (line 69)
create_dataset(options);
I've looked in the Matlab docs for a function for deleting a data set in an hdf5 file but can't find any references. Any one have any ideas?
Upvotes: 3
Views: 2569
Reputation: 5471
It is not possible to either delete a dataset or change its datatype. From section 5.3.2 of the HDF5 manual:
The datatype is set when the dataset is created and can never be changed.
This is due to how space is assigned in an HDF5 file. While it's not possible to delete a dataset (for the same reasons), it can be "unlinked" and be made inaccessible, but this does not reclaim the used space.
If you really need to change the datatype, you have two choices: the first is to unlink the old dataset and create a new one in its place. The new dataset can have the same name as the old one. However, if space is a concern, you may prefer to just create an entirely new HDF5 file, and copy the old data into the new one.
Upvotes: 2
Reputation: 1372
According to This post which is a similar problem there is no mechanism for deleting a dataset in an HDF5 file. It also indicates that it is possible to Modify in place.
Upvotes: 0