Skip to content

Commit

Permalink
track insertion order for base group
Browse files Browse the repository at this point in the history
this results in correct ordering for increments in HDFView (which are by default
mixed up due to alphanumeric ordering). Note that the status is wrongly
reported:
- HDFGroup/hdfview#347
- HDFGroup/hdf5#5183
  • Loading branch information
MarDiehl committed Dec 17, 2024
1 parent 4bf32db commit 4a03b8a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
23 changes: 15 additions & 8 deletions src/HDF5_utilities.f90
Original file line number Diff line number Diff line change
Expand Up @@ -184,42 +184,49 @@ integer(HID_T) function HDF5_openFile(fileName,mode,parallel)
logical, intent(in), optional :: parallel

character :: m
integer(HID_T) :: plist_id
integer(HID_T) :: p_access,p_create
integer :: hdferr
logical :: exist


m = misc_optional(mode,'r')

call H5Pcreate_f(H5P_FILE_ACCESS_F, plist_id, hdferr)
call H5Pcreate_f(H5P_FILE_CREATE_F, p_create, hdferr)
call HDF5_chkerr(hdferr)
call H5Pset_link_creation_order_f(p_create, ior(H5P_CRT_ORDER_INDEXED_F,H5P_CRT_ORDER_TRACKED_F), hdferr)
call HDF5_chkerr(hdferr)

call H5Pcreate_f(H5P_FILE_ACCESS_F, p_access, hdferr)
call HDF5_chkerr(hdferr)
#ifdef PETSC
if (misc_optional(parallel,.true.)) &
#if (PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR>14) && !defined(PETSC_HAVE_MPI_F90MODULE_VISIBILITY)
call H5Pset_fapl_mpio_f(plist_id, PETSC_COMM_WORLD, MPI_INFO_NULL_F90, hdferr)
call H5Pset_fapl_mpio_f(p_access, PETSC_COMM_WORLD, MPI_INFO_NULL_F90, hdferr)
#else
call H5Pset_fapl_mpio_f(plist_id, PETSC_COMM_WORLD, MPI_INFO_NULL, hdferr)
call H5Pset_fapl_mpio_f(p_access, PETSC_COMM_WORLD, MPI_INFO_NULL, hdferr)
#endif
call HDF5_chkerr(hdferr)
#endif

if (m == 'w') then
call H5Fcreate_f(fileName,H5F_ACC_TRUNC_F,HDF5_openFile,hdferr,access_prp = plist_id)
call H5Fcreate_f(fileName,H5F_ACC_TRUNC_F,HDF5_openFile,hdferr,&
access_prp=p_access,creation_prp=p_create)
call HDF5_chkerr(hdferr)
elseif (m == 'a') then
call H5Fopen_f(fileName,H5F_ACC_RDWR_F,HDF5_openFile,hdferr,access_prp = plist_id)
call H5Fopen_f(fileName,H5F_ACC_RDWR_F,HDF5_openFile,hdferr,access_prp=p_access)
call HDF5_chkerr(hdferr)
elseif (m == 'r') then
inquire(file=fileName,exist=exist)
if (.not. exist) call IO_error(100,trim(fileName))
call H5Fopen_f(fileName,H5F_ACC_RDONLY_F,HDF5_openFile,hdferr,access_prp = plist_id)
call H5Fopen_f(fileName,H5F_ACC_RDONLY_F,HDF5_openFile,hdferr,access_prp=p_access)
call HDF5_chkerr(hdferr)
else
error stop 'unknown access mode'
end if

call H5Pclose_f(plist_id, hdferr)
call H5Pclose_f(p_access, hdferr)
call HDF5_chkerr(hdferr)
call H5Pclose_f(p_create, hdferr)
call HDF5_chkerr(hdferr)

end function HDF5_openFile
Expand Down
13 changes: 11 additions & 2 deletions src/test/test_HDF5_utilities.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ end subroutine test_HDF5_utilities_run

subroutine read_write()

integer(HID_T) :: f
integer(HID_T) :: f, create_list
integer :: hdferr, order

real(pREAL), dimension(3) :: real_d1_in,real_d1_out
real(pREAL), dimension(3,3) :: real_d2_in,real_d2_out
Expand Down Expand Up @@ -92,7 +93,15 @@ subroutine read_write()
call HDF5_closeFile(f)

f = HDF5_openFile('test.hdf5','r')

call H5Fget_create_plist_f(f,create_list,hdferr)
call HDF5_chkerr(hdferr)
call H5Pget_link_creation_order_f(create_list,order,hdferr)
call HDF5_chkerr(hdferr)
! https://github.com/HDFGroup/hdf5/issues/5183
!if (iand(order,H5P_CRT_ORDER_INDEXED_F) /= H5P_CRT_ORDER_INDEXED_F) error stop 'CRT_ORDER_INDEXED'
!if (iand(order,H5P_CRT_ORDER_TRACKED_F) /= H5P_CRT_ORDER_TRACKED_F) error stop 'CRT_ORDER_TRACKED'
call H5Pclose_f(create_list,hdferr)
call HDF5_chkerr(hdferr)

call HDF5_read(real_d1_out,f,'real_d1')
call HDF5_read(real_d2_out,f,'real_d2')
Expand Down

0 comments on commit 4a03b8a

Please sign in to comment.