I'm currently learning HDF5 and need to figure out how to add attributes to an empty group with C++. I know how to do it via HDFView, but I can't seem to find any documentation about adding attributes to a simple group, only datasets (is this even possible?).
In HDFView, if you add a group then right-click that group and select "Show properties", a new window will pop up with tabs for 'General' and 'Attributes'. In the 'Attributes' tab you can add multiple attributes. I basically want to do this, but through code.
My code below adds a single group to a new H5 file:
//Create a new file using default properties
H5File file("NewH5.h5", H5F_ACC_TRUNC);
//Create PLATFORM_t and SONAR_t groups in the file
The operations on attributes attached to files, groups, datasets etc. are the member functions of the H5Location class. In order to write an attribute named "some_attribute" of type double in your group you simply call
Attribute att = groupPlatform.createAttribute("some_attribute",PredType::NATIVE_DOUBLE,dspace);
More complex attributes are possible if you use more complex dataspaces.
Asked in February 2016Viewed 1,315 timesVoted 7Answered 1 times