Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete or update a dataset in HDF5?

Tags:

c++

c

hdf5

api

I would like to programatically change the data associated with a dataset in an HDF5 file. I can't seem to find a way to either delete a dataset by name (allowing me to add it again with the modified data) or update a dataset by name. I'm using the C API for HDF5 1.6.x but pointers towards any HDF5 API would be useful.

like image 745
Barry Wark Avatar asked Dec 30 '22 06:12

Barry Wark


2 Answers

According to the user guide:

HDF5 does not at this time provide an easy mechanism to remove a dataset from a file or to reclaim the storage space occupied by a deleted object.

So simple deletion appears to be out of the question. But the section continues:

Removing a dataset and reclaiming the space it used can be done with the H5Ldelete function and the h5repack utility program. With the H5Ldelete function, links to a dataset can be removed from the file structure. After all the links have been removed, the dataset becomes inaccessible to any application and is effectively removed from the file. The way to recover the space occupied by an unlinked dataset is to write all of the objects of the file into a new file. Any unlinked object is inaccessible to the application and will not be included in the new file. Writing objects to a new file can be done with a custom program or with the h5repack utility program.

like image 155
Max Lybbert Avatar answered Jan 08 '23 09:01

Max Lybbert


If you want to delete a dataset in c++ you need the following commands:

H5File m_h5File (pathAndNameToHDF5File, H5F_ACC_RDWR); //The hdf5 c++ object.
std::string channelName = "/myGroup/myDataset";
int result = H5Ldelete(m_h5File.getId(), channelName.data(), H5P_DEFAULT);

result will be a non-negative value if successful; otherwise returns a negative value. https://support.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Delete

As @MaxLybbert said, the hard-disk space it is not recoverd. You must use the repack tool. However, with HDF5 v.1.10 the space can be recovered. But the user's guide is not ready yet: https://support.hdfgroup.org/HDF5/docNewFeatures/NewFeaturesFileSpaceMgmtDocs.html

like image 45
pablo_worker Avatar answered Jan 08 '23 10:01

pablo_worker