Hi,
I'm new to HDF and was wondering if someone could tell me
if I'm doing this right. I'm using the C++ interface and I want
to add and attribute if it doesn't exist, and increment it if it
does.
The code I'm using to do this is as follows:
int experiment_count = 1;
// Get the value of Experiment count
Group m_root_g = m_file.get_handle().openGroup("/");
try {
Attribute expcount = m_root_g.openAttribute("ExperimentCount");
expcount.read(PredType::NATIVE_INT,&experiment_count);
experiment_count++;
expcount.write(PredType::NATIVE_INT, &experiment_count);
expcount.close();
} catch (AttributeIException E) {
// Add or increment attribute called "ExperimentCount"
DataSpace expcount_att_space(H5S_SCALAR);
Attribute expcount_att = m_root_g.createAttribute(H5std_string("ExperimentCount"),
PredType::NATIVE_INT,
expcount_att_space);
expcount_att.write(PredType::NATIVE_INT, &experiment_count);
expcount_att.close();
}
So, I've tried to open the attribute in a try/catch block, and if the opening fails I catch
the exception and create a new attribute. I'm using this attribute to count the number of
experiment groups I'm holding (as I want to name the groups Experiment1 Experiment2 etc.).
My question is it wrapping the openAttribute in a try/catch block the correct thing to do? Or
is there a better way. It all works correctly, but I get the following output:
HDF5-DIAG: Error detected in HDF5 (1.8.1) thread 0:
#000: H5A.c line 539 in H5Aopen(): unable to load attribute info from object header
major: Attribute
minor: Unable to initialize object
#001: H5Oattribute.c line 504 in H5O_attr_open_by_name(): can't locate attribute
major: Attribute
minor: Object not found
This error makes me think that perhaps there a better way to go about this?
Any advice appreciated.
···
----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.