Недавно я начал изучать библиотеку HDF5 для Fortran и наткнулся на любопытное поведение, которого я не понимаю. Приведенный ниже код компилируется отлично, но когда я пытаюсь запустить код, я получаю очень длинный список ошибок, связанных с подпрограммой HDF_init_ot
. Когда я помещаю эту подпрограмму в подпрограмму вызывающего абонента HDF_init
(как я сделал в HDF_init2
), все работает отлично. Почему это происходит?
Код :
!===============================================================================
! This subroutine makes a call to an external subroutine HDF_init_ot,
! which throws an error
!===============================================================================
subroutine HDF_init()
use hdf5
character(len=11), parameter :: filename = "output.hdf5"
character(len=2), parameter :: group_ot = "ot"
integer(HID_T) :: file_handle, ot_handle
integer :: error
! Create a new HDF file
call h5open_f(error)
call h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_handle, error)
! Create a new group
call h5gcreate_f(file_handle, group_ot, ot_handle, error)
! Call to subroutine
call HDF_init_ot(ot_handle)
! Close group
call h5gclose_f(ot_handle, error)
! Close file
call h5fclose_f(file_handle, error)
call h5close_f(error)
end subroutine HDF_init
!===============================================================================
! The culprit subroutine
!===============================================================================
subroutine HDF_init_ot(ot_handle)
use hdf5
character(len=1), parameter :: dset_t = "t"
integer(HID_T) :: ot_handle, ot_space_handle
integer(HID_T) :: data_handle
integer(HSIZE_T), dimension(1) :: ot_dims, ot_max_dims
integer :: error, rank
! Define rank and dimensions
rank = 1
ot_dims = (/0/)
ot_max_dims = (/H5S_UNLIMITED_F/)
! Create a data space
call h5screate_simple_f(rank, ot_dims, ot_space_handle, error, ot_max_dims)
! Create a data set within the space
call h5dcreate_f( ot_handle, dset_t, H5T_NATIVE_DOUBLE, ot_space_handle, &
data_handle, error)
! Close the data set
call h5dclose_f(data_handle, error)
! Close the data space
call h5sclose_f(ot_space_handle, error)
end subroutine HDF_init_ot
!===============================================================================
! When I inline HDF_init_ot into the subroutine below, everything works
!===============================================================================
subroutine HDF_init2()
use hdf5
character(len=11), parameter :: filename = "output.hdf5"
character(len=2), parameter :: group_ot = "ot"
character(len=1), parameter :: dset_t = "t"
integer(HID_T) :: file_handle, ot_handle, ot_space_handle, data_handle
integer(HSIZE_T), dimension(1) :: ot_dims, ot_max_dims
integer :: error, rank
rank = 1
ot_dims = (/0/)
ot_max_dims = (/H5S_UNLIMITED_F/)
call h5open_f(error)
call h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_handle, error)
call h5gcreate_f(file_handle, group_ot, ot_handle, error)
call h5screate_simple_f(rank, ot_dims, ot_space_handle, error, ot_max_dims)
call h5dcreate_f( ot_handle, dset_t, H5T_NATIVE_DOUBLE, ot_space_handle, &
data_handle, error)
call h5dclose_f(data_handle, error)
call h5sclose_f(ot_space_handle, error)
call h5gclose_f(ot_handle, error)
call h5fclose_f(file_handle, error)
call h5close_f(error)
end subroutine HDF_init2
!===============================================================================
! Main program
!===============================================================================
program test
implicit none
! This one throws errors
call HDF_init()
! This one does not
call HDF_init2()
end program test
Ошибка :
HDF5-DIAG: Error detected in HDF5 (1.8.16) thread 140274482874112:
#000: ../../../src/H5D.c line 194 in H5Dcreate2(): unable to create dataset
major: Dataset
minor: Unable to initialize object
#001: ../../../src/H5Dint.c line 453 in H5D__create_named(): unable to create and link to dataset
major: Dataset
minor: Unable to initialize object
#002: ../../../src/H5L.c line 1638 in H5L_link_object(): unable to create new link to object
major: Links
minor: Unable to initialize object
#003: ../../../src/H5L.c line 1882 in H5L_create_real(): can't insert link
major: Symbol table
minor: Unable to insert object
#004: ../../../src/H5Gtraverse.c line 861 in H5G_traverse(): internal path traversal failed
major: Symbol table
minor: Object not found
#005: ../../../src/H5Gtraverse.c line 641 in H5G_traverse_real(): traversal operator failed
major: Symbol table
minor: Callback failed
#006: ../../../src/H5L.c line 1685 in H5L_link_cb(): unable to create object
major: Object header
minor: Unable to initialize object
#007: ../../../src/H5O.c line 3016 in H5O_obj_create(): unable to open object
major: Object header
minor: Can't open object
#008: ../../../src/H5Doh.c line 293 in H5O__dset_create(): unable to create dataset
major: Dataset
minor: Unable to initialize object
#009: ../../../src/H5Dint.c line 1056 in H5D__create(): unable to construct layout information
major: Dataset
minor: Unable to initialize object
#010: ../../../src/H5Dcontig.c line 422 in H5D__contig_construct(): extendible contiguous non-external dataset
major: Dataset
minor: Feature is unsupported
HDF5-DIAG: Error detected in HDF5 (1.8.16) thread 140274482874112:
#000: ../../../src/H5D.c line 415 in H5Dclose(): not a dataset
major: Invalid arguments to routine
minor: Inappropriate type
HDF5-DIAG: Error detected in HDF5 (1.8.16) thread 140274482874112:
#000: ../../../src/H5D.c line 194 in H5Dcreate2(): unable to create dataset
major: Dataset
minor: Unable to initialize object
#001: ../../../src/H5Dint.c line 453 in H5D__create_named(): unable to create and link to dataset
major: Dataset
minor: Unable to initialize object
#002: ../../../src/H5L.c line 1638 in H5L_link_object(): unable to create new link to object
major: Links
minor: Unable to initialize object
#003: ../../../src/H5L.c line 1882 in H5L_create_real(): can't insert link
major: Symbol table
minor: Unable to insert object
#004: ../../../src/H5Gtraverse.c line 861 in H5G_traverse(): internal path traversal failed
major: Symbol table
minor: Object not found
#005: ../../../src/H5Gtraverse.c line 641 in H5G_traverse_real(): traversal operator failed
major: Symbol table
minor: Callback failed
#006: ../../../src/H5L.c line 1685 in H5L_link_cb(): unable to create object
major: Object header
minor: Unable to initialize object
#007: ../../../src/H5O.c line 3016 in H5O_obj_create(): unable to open object
major: Object header
minor: Can't open object
#008: ../../../src/H5Doh.c line 293 in H5O__dset_create(): unable to create dataset
major: Dataset
minor: Unable to initialize object
#009: ../../../src/H5Dint.c line 1056 in H5D__create(): unable to construct layout information
major: Dataset
minor: Unable to initialize object
#010: ../../../src/H5Dcontig.c line 422 in H5D__contig_construct(): extendible contiguous non-external dataset
major: Dataset
minor: Feature is unsupported
HDF5-DIAG: Error detected in HDF5 (1.8.16) thread 140274482874112:
#000: ../../../src/H5D.c line 415 in H5Dclose(): not a dataset
major: Invalid arguments to routine
minor: Inappropriate type
Изменить :
Я обнаружил, что когда я удаляю ot_max_dims
из вызова h5screate_simple_f
, все работает, как ожидалось. Любопытно, что если я определю ot_max_dims
в HDF_init
и передам это как дополнительный параметр в HDF_init_ot
, все также будет работать. Это наводит на мысль, что H5S_UNLIMITED_F
- это частный параметр для HDF_init()
, возможно, связанный с экземпляром API (т.е. с h5open_f
)?