Skip to content

Commit

Permalink
updated traverse example
Browse files Browse the repository at this point in the history
  • Loading branch information
brtnfld committed Dec 21, 2023
1 parent 3715772 commit 822c9d4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
4 changes: 3 additions & 1 deletion HDF5Examples/FORTRAN/H5G/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,10 @@ if (H5EX_BUILD_TESTING)
if (HDF5_VERSION_STRING VERSION_GREATER_EQUAL "1.10.0")
ADD_H5_CMP_TEST (h5ex_g_intermediate)
ADD_H5_CMP_TEST (h5ex_g_iterate)
ADD_H5_CMP_TEST (h5ex_g_traverse)
ADD_H5_CMP_TEST (h5ex_g_visit)
if (HDF5_VERSION_STRING VERSION_GREATER_EQUAL "1.14.3")
ADD_H5_CMP_TEST (h5ex_g_traverse)
endif()
else ()
if (HDF_ENABLE_F2003)
ADD_H5_CMP_TEST (h5ex_g_intermediate)
Expand Down
7 changes: 6 additions & 1 deletion HDF5Examples/FORTRAN/H5G/Fortran_sourcefiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ if (HDF5_VERSION_STRING VERSION_GREATER_EQUAL "1.10.0")
${common_examples}
h5ex_g_intermediate
h5ex_g_iterate
h5ex_g_traverse
h5ex_g_visit
)
if (HDF5_VERSION_STRING VERSION_GREATER_EQUAL "1.14.3")
set (common_examples
${common_examples}
h5ex_g_traverse
)
endif()
else ()
if (HDF_ENABLE_F2003)
set (common_examples
Expand Down
21 changes: 15 additions & 6 deletions HDF5Examples/FORTRAN/H5G/h5ex_g_traverse.F90
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ RECURSIVE INTEGER(KIND=C_INT) FUNCTION op_func(loc_id, name, info, operator_data
! H5Odecr_refcount.
!

i = group_check(od, infobuf%token)
i = group_check(loc_id, od, infobuf%token)

IF(i.EQ.1)THEN
WRITE(*,'(A)') space(1:spaces)//" Warning: Loop detected!"
Expand Down Expand Up @@ -164,24 +164,33 @@ END FUNCTION op_func
!
! ************************************************************/

INTEGER RECURSIVE FUNCTION group_check(od, target_token) result(g_c)
INTEGER RECURSIVE FUNCTION group_check(loc_id, od, target_token) result(g_c)

IMPLICIT NONE
INTEGER :: i
TYPE(opdata), POINTER :: od
#if H5_VERSION_GE(1, 12, 0)
INTEGER(HID_T) :: loc_id
INTEGER :: cmp_value
#if H5_VERSION_GE(1, 14, 3)
TYPE(H5O_TOKEN_T_F) :: target_token
INTEGER :: status
CALL h5otoken_cmp_f(loc_id, od%token, target_token, cmp_value, status)
#else
#if H5_VERSION_GE(1, 12, 0)
#error "example only supports HDF5 versions < 1.12.0 and > 1.14.2"
#else
INTEGER(haddr_t) :: target_token
cmp_value = -1
IF(od%token .EQ. target_token) cmp_value = 0
#endif

IF (od%token%token(1) .EQ. target_token%token(1))THEN
#endif
IF (cmp_value.EQ.0)THEN
g_c = 1 ! Addresses/token match
ELSE IF (od%recurs.EQ.0)THEN
g_c = 0 ! Root group reached with no matches
ELSE
! Recursively examine the next node
g_c = group_check(od%prev, target_token)
g_c = group_check(loc_id, od%prev, target_token)
END IF
END FUNCTION group_check

Expand Down

0 comments on commit 822c9d4

Please sign in to comment.