Getting native type of HDF5 attribute

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting native type of HDF5 attribute

jolindbe
Hi,

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? How do I correctly figure out the type of an attribute value?

Best regards,
Johan Lindberg

_______________________________________________
Hdf-forum is for HDF software users discussion.
[hidden email]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5
Reply | Threaded
Open this post in threaded view
|

Re: Getting native type of HDF5 attribute

Gerd Heber

Johan, the only valid way to compare the underlying types of two datatype handles (identifiers)

is H5Tequal (or H5T.equal in HDF.PInvoke)

 

https://support.hdfgroup.org/HDF5/doc/RM/RM_H5T.html#Datatype-Equal

 

Most likely, you will narrow down the type by first establishing the datatype’s “class”

via H5Tget_class (H5T.get_class), and then refine your test from there.

 

The HDF5 API handles, including datatype IDs, are opaque and transient, and don’t mean anything

as integer values.

 

G.

 

 

 

From: Hdf-forum [mailto:[hidden email]] On Behalf Of Johan Lindberg
Sent: Monday, May 22, 2017 4:23 AM
To: [hidden email]
Subject: [Hdf-forum] Getting native type of HDF5 attribute

 

Hi,

 

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? How do I correctly figure out the type of an attribute value?

 

Best regards,

Johan Lindberg


_______________________________________________
Hdf-forum is for HDF software users discussion.
[hidden email]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5
Reply | Threaded
Open this post in threaded view
|

Re: Getting native type of HDF5 attribute

jolindbe
Thanks for the quick reply, Gerd! That is exactly what I needed.

Best,
Johan

2017-05-22 15:24 GMT+02:00 Gerd Heber <[hidden email]>:

Johan, the only valid way to compare the underlying types of two datatype handles (identifiers)

is H5Tequal (or H5T.equal in HDF.PInvoke)

 

https://support.hdfgroup.org/HDF5/doc/RM/RM_H5T.html#Datatype-Equal

 

Most likely, you will narrow down the type by first establishing the datatype’s “class”

via H5Tget_class (H5T.get_class), and then refine your test from there.

 

The HDF5 API handles, including datatype IDs, are opaque and transient, and don’t mean anything

as integer values.

 

G.

 

 

 

From: Hdf-forum [mailto:[hidden email]] On Behalf Of Johan Lindberg
Sent: Monday, May 22, 2017 4:23 AM
To: [hidden email]
Subject: [Hdf-forum] Getting native type of HDF5 attribute

 

Hi,

 

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? How do I correctly figure out the type of an attribute value?

 

Best regards,

Johan Lindberg


_______________________________________________
Hdf-forum is for HDF software users discussion.
[hidden email]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5



--
Dr. Johan E. Lindberg
Mobile phone: +46 (0)76-209 14 13
e-mail: [hidden email]

_______________________________________________
Hdf-forum is for HDF software users discussion.
[hidden email]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5