How exactly H5Dget_type works

Hello
I am new to HDF5 and I don’t understand how the H5Dget_type function works.
I wanted to use it to know what type of data are stored in a dataset. To test I use a H5 file with different data set
one is an array of 32bit float
one is an array of 32bi integer
but when I use the H5Dget_type function to see the type of data I have in my dataset the answer is always the same 0

Can you share a short code example? It is now impossible to answer why you are getting 0.

-Aleksandar

Sorry I forget to share my code

int main(void)
{
        file_id = H5Fopen("myfile.h5", H5F_ACC_RDWR, H5P_DEFAULT);
	
       dataset_id = H5Dopen(file_id, "/DS1/", H5P_DEFAULT);//26x256x320 32bit floating point
	hsize_t taille = H5Dget_storage_size(dataset_id);
	hid_t dt= H5Dget_type(dataset_id);
	printf("size=%i (%i)", taille, dt);
	status = H5Dclose(dataset_id);

	dataset_id = H5Dopen(file_id, "/DS2/", H5P_DEFAULT);///26 64bit floating point
	taille = H5Dget_storage_size(dataset_id);
	dt = H5Dget_type(dataset_id);
	printf("size=%i (%i)", taille, dt);
	status = H5Dclose(dataset_id);
        status = H5Fclose(file_id);
}

the output for the size is correct but data type is always 0

hid_t dt - this is an identifier that has to be used in other calls.
get the size:
size_t datum_size = H5Tget_size(dt);
get the type class:
H5T_class_t type_class = H5Tget_class(dt);
then:
switch (type_class) {
case H5T_INTEGER:
if (H5Tequal(dt, H5T_STD_I8BE) == true)
printf(“H5T_STD_I8BE”);
else if (H5Tequal(dt, H5T_STD_I8LE) == true)
printf(“H5T_STD_I8LE”);
etc… (see the source for h5tools_print_datatype function in the tools/lib/h5tools_dump.c file)

Allen

It is working thanks

Hi @gouyon,

In case you are not bound to a specific library, have a look at HDFql, a high-level declarative programming language to manage HDF5 data. Using HDFql in C, your use-case can easily be solved as follows:

int data_type;

hdfql_execute("SHOW DATA TYPE myfile.h5 DS1");

hdfql_cursor_first(NULL);

data_type = hdfql_cursor_get_int(NULL);

if (data_type == HDFQL_INT)
{
    printf("The dataset is of type integer\n");
}
else if (data_type == HDFQL_FLOAT)
{
    printf("The dataset is of type float\n");
}
else if (data_type == HDFQL_DOUBLE)
{
    printf("The dataset is of type double\n");
}
(...)

Hope it helps!