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){ 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?
c ++ hdf5
eudoxos
source share