The presence of a test group in hdf5 / C ++

I open an existing HDF5 file to add data; I want to assure that for subsequent access there is a group named /A I am looking for a simple way to either create /A conditionally (create and return a new group if it does not exist, or return an existing group). One way is to verify the existence of /A How can I do this efficiently?

According to the API docs, I can do something like this:

 H5::H5File h5file(filename,H5F_ACC_RDWR); H5::H5Group grp; try{ grp=h5file.openGroup("A"); } catch(H5::Exception& e){ /* group does not exists, create it */ grp=h5file.createGroup("A"); } 

but the obvious ugliness comes from the fact that an exception is used to convey information that is not exceptional at all.

There is H5 :: CommonFG :: getObjinfo , which seems to terminate H5Gget_objinfo in such a way that a false (nonexistent) return value of the C routine throws an exception; so again the problem.

Is calling API C clean in this case, or is there some kind of function specifically designed to check for existence in the C ++ API that I miss?

+8
c ++ hdf5
source share
1 answer

I am testing the existence of a group with:

 bool H5Location::attrExists(const char* name) const; 

This way you can check for the existence of a group / dataset / ... at a specified location.

 // Test if empty (= new) H5 file auto isNewFile = this->attrExists(VariablesH5GroupName); 
+1
source share

All Articles