I am using Visual Studio (C#) and HDF5 P/Invoke.
I have made an HDF5 file with groups and datasets with attributes of different datatypes (in this case, let's say it is an integer, saved as H5T.NATIVE_INT32, but I have the same problem for other datatypes). Now I am making a code to read data from the HDF5 file. To read the attribute value, I first need to determine the data type of the attribute value. I have tried the following:
attributeId = H5A.open(groupId, attributeName, H5P.DEFAULT);
hid_t attributeSpace = H5A.get_space(attributeId);
H5S.class_t extentType = H5S.get_simple_extent_type(attributeSpace);
hid_t typeId = H5A.get_type(attributeId);
attributeClass = H5T.get_class(typeId);
type = H5T.get_native_type(typeId, H5T.direction_t.DEFAULT);
H5T.close(typeId);
However, the resulting variable type
does not match with the H5T.NATIVE_INTEGER
type, or any other H5T type I can think of. In fact, even
H5T.get_native_type(H5T.NATIVE_INT,H5T.direction_t.DEFAULT) == H5T.NATIVE_INT
returns false
, so it appears as if H5T.get_native_type()
does not return a type, but perhaps a copy or a pointer of it, which is not identical to the type itself. Is this expected behaviour or a bug? Any ideas on how to correctly figure out the type of an attribute value?
HDF5 encapsulates data and you should use HDF5 routines to handle them. The values you obtain are called "type identifiers", they are HDF5 opaque datatypes.
You should use H5Tequal
to assess the equality of the type of two type identifiers
H5Tequal(type, H5T.NATIVE_INT)
PS: I am writing this with the point of view of the C API to HDF5 and hope it applies to your case too.