Error when selecting and writing an element dataset hdf5 1.10.4


#1

Dear all,
I am new to hdf5. I’d like to select an element from a dataset and write a real value in it. To do this, I use the following fortran code (it’s a minimal working example extracted from the main code):

program test
use hdf5
implicit none
integer :: err, cnt
real(8) :: fmd
integer(HID_T) :: file_ifmd, dset_ifmd, dspace_ifmd
integer(HSIZE_T) :: dim_fmd(1)
integer(HSIZE_T), dimension(1) :: dim_buf(1)=1
integer(SIZE_T), parameter :: nel=1
integer(HSSIZE_T) :: fmd_coord(1,nel)

dim_fmd(1) = 54

call h5fcreate_f('fmd.hdf5', H5F_ACC_TRUNC_F, file_ifmd, err)
call h5screate_simple_f(1, dim_fmd, dspace_ifmd, err)
call h5dcreate_f(file_ifmd, 'fmd', H5T_NATIVE_DOUBLE, dspace_ifmd, dset_ifmd, err)
call h5dclose_f(dset_ifmd, err)
call h5sclose_f(dspace_ifmd, err)
call h5fclose_f(file_ifmd,err)

call h5fopen_f('fmd.hdf5', H5F_ACC_RDWR_F, file_ifmd, err)
call h5dopen_f(file_ifmd, 'fmd', dset_ifmd, err)

do cnt = 1, 1 ! just one loop for testing purposes
  fmd_coord(1,nel) = cnt
  call h5sselect_elements_f(dset_ifmd, H5S_SELECT_SET_F, 1, nel, fmd_coord, err)
  fmd = 0.5d0
  call h5dwrite_f(dset_ifmd, H5T_NATIVE_DOUBLE, fmd, dim_buf, err)
end do

call h5dclose_f(dset_ifmd, err)
call h5sclose_f(dspace_ifmd, err)
call h5fclose_f(file_ifmd,err)
end program test

I create the executable on ubuntu 20.04.3 LTS with the latest updates, gcc 9.3.0, HDF5 1.10.4 using the command
h5fc -ffree-line-length-none -Wall -Wextra -Wconversion -pedantic -O -fcheck=all -g -fbacktrace -ffpe-trap=zero,overflow,underflow,invalid test2_hdf5.f90

where h5fc -show gives

gfortran -I/usr/include/hdf5/serial -L/usr/lib/x86_64-linux-gnu/hdf5/serial /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5hl_fortran.a /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5_hl.a /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5_fortran.a /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.a -lpthread -lsz -lz -ldl -lm -Wl,-rpath -Wl,/usr/lib/x86_64-linux-gnu/hdf5/serial

The code compiles successfully without warnings. When I run the executable I get

HDF5-DIAG: Error detected in HDF5 (1.10.4) thread 139755212736320:
#000: …/…/…/src/H5D.c line 121 in H5Dcreate2(): not a datatype ID
major: Invalid arguments to routine
minor: Inappropriate type
HDF5-DIAG: Error detected in HDF5 (1.10.4) thread 139755212736320:
#000: …/…/…/src/H5D.c line 331 in H5Dclose(): not a dataset
major: Invalid arguments to routine
minor: Inappropriate type
HDF5-DIAG: Error detected in HDF5 (1.10.4) thread 139755212736320:
#000: …/…/…/src/H5D.c line 292 in H5Dopen2(): unable to open dataset
major: Dataset
minor: Can’t open object
#001: …/…/…/src/H5Dint.c line 1205 in H5D__open_name(): not found
major: Dataset
minor: Object not found
#002: …/…/…/src/H5Gloc.c line 422 in H5G_loc_find(): can’t find object
major: Symbol table
minor: Object not found
#003: …/…/…/src/H5Gtraverse.c line 851 in H5G_traverse(): internal path traversal failed
major: Symbol table
minor: Object not found
#004: …/…/…/src/H5Gtraverse.c line 627 in H5G__traverse_real(): traversal operator failed
major: Symbol table
minor: Callback failed
#005: …/…/…/src/H5Gloc.c line 378 in H5G__loc_find_cb(): object ‘fmd’ doesn’t exist
major: Symbol table
minor: Object not found
HDF5-DIAG: Error detected in HDF5 (1.10.4) thread 139755212736320:
#000: …/…/…/src/H5S.c line 921 in H5Sget_simple_extent_ndims(): not a dataspace
major: Invalid arguments to routine
minor: Inappropriate type
HDF5-DIAG: Error detected in HDF5 (1.10.4) thread 139755212736320:
#000: …/…/…/src/H5Dio.c line 314 in H5Dwrite(): dset_id is not a dataset ID
major: Invalid arguments to routine
minor: Inappropriate type
HDF5-DIAG: Error detected in HDF5 (1.10.4) thread 139755212736320:
#000: …/…/…/src/H5D.c line 331 in H5Dclose(): not a dataset
major: Invalid arguments to routine
minor: Inappropriate type
HDF5-DIAG: Error detected in HDF5 (1.10.4) thread 139755212736320:
#000: …/…/…/src/H5S.c line 489 in H5Sclose(): not a dataspace
major: Invalid arguments to routine
minor: Inappropriate type

I browsed through the forum and in the web but I could not get a solution suitable for my environment.

Thanks a lot in advance for your help!
Antonio