I am currently integrating the HDF5 library into our software with good success so far. However, I just can’t get H5Awrite to succeed. The following steps work as expected:
Create a new file.
Create and write to a dataset.
Add an attribute to the dataset.
It then fails when I try to write to the attribute. I can confirm that the attribute is successfully created, but it contents remains zero.
The shown error is:
HDF5-DIAG: Error detected in HDF5 (1.12.0) thread 0: #000: …\externals\hdf5\src\src\H5A.c line 672 in H5Awrite(): not an attribute
major: Invalid arguments to routine
minor: Inappropriate type
object.id() = – the id of the “testdata” dataset –
attributename = “test_scalar”
datatype = H5T_IEEE_F32LE
dspace.id() = H5Screate(H5S_SCALAR);
data = – pointer to a single float –
Okay I found my problem. I use a class to ensure the attribute is closed before the function returns. For whatever reason, the compiled code destroys this object too early, before the write function. I restructured my code to make it clearer to the compiler when the attribute ID is used and now it works, although it is basically the same code.