Delete or update dataset in HDF5?

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

+1


source to share


2 answers


According to the user manual :

HDF5 does not currently provide a simple mechanism for deleting a dataset from a file or for reclaiming memory space occupied by a deleted object.



Such a simple exception seems to be out of the question. But the section continues:

You can use a function H5Ldelete

and a h5repack

utility to delete a dataset and restore the space it used . Using the function, H5Ldelete

references to a dataset can be removed from the file structure. After all links have been removed, the dataset becomes inaccessible to any application and is effectively removed from the file. The way to reclaim the space occupied by an unrelated dataset is to write all the objects in the file to a new file. Any unrelated object is not available to the application and will not be included in the new file. Writing objects to a new file can be performed using a special program or using a utility h5repack

.

+5


source


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);

      



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

As @MaxLybbert said, hard disk space is not reclaimed. You must use the repack tool. However, with HDF5 v.1.10, space can be restored. But the user manual is not ready yet: https://support.hdfgroup.org/HDF5/docNewFeatures/NewFeaturesFileSpaceMgmtDocs.html

+1


source







All Articles