Skip to content

Commit

Permalink
Merge pull request #2998 from GEOS-ESM/feature/bmauer/fixes-#2996
Browse files Browse the repository at this point in the history
fixes #2996
  • Loading branch information
bena-nasa authored Aug 28, 2024
2 parents 90b295e + 5bd7e14 commit 755082c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
5 changes: 5 additions & 0 deletions generic3g/ESMF_HConfigUtilities.F90
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ module mapl3g_ESMF_HConfigUtilities
public :: write(formatted)
public :: MAPL_HConfigMatch

character(*), parameter :: CORE_SCHEMA_INT_TAG = 'tag:yaml.org,2002:int'
character(*), parameter :: CORE_SCHEMA_FLOAT_TAG = 'tag:yaml.org,2002:float'
character(*), parameter :: CORE_SCHEMA_STR_TAG = 'tag:yaml.org,2002:str'
character(*), parameter :: CORE_SCHEMA_BOOL_TAG = 'tag:yaml.org,2002:bool'

interface write(formatted)
procedure write_hconfig
end interface write(formatted)
Expand Down
48 changes: 22 additions & 26 deletions generic3g/ESMF_HConfigUtilities/MAPL_HConfigMatch.F90
Original file line number Diff line number Diff line change
Expand Up @@ -95,44 +95,40 @@ recursive logical function MAPL_HConfigMatchScalar(a, b, rc) result(match)

integer :: status
character(:), allocatable :: a_str, b_str
logical :: a_is, b_is
character(:), allocatable :: a_tag, b_tag
logical :: a_as_bool, b_as_bool
integer(kind=ESMF_KIND_I8) :: a_as_int, b_as_int
real(kind=ESMF_KIND_R8) :: a_as_float, b_as_float

match = .false. ! nless

a_as_bool = ESMF_HConfigAsLogical(a, asOkay=a_is, _RC)
b_as_bool = ESMF_HConfigAsLogical(b, asOkay=b_is, _RC)
_RETURN_UNLESS(a_is .eqv. b_is)

if (a_is) then
a_tag = ESMF_HConfigGetTag(a, _RC)
b_tag = ESMF_HConfigGetTag(b, _RC)
_RETURN_UNLESS(a_tag == b_tag)

select case(a_tag)
case (CORE_SCHEMA_BOOL_TAG)
a_as_bool = ESMF_HConfigAsLogical(a, _RC)
b_as_bool = ESMF_HConfigAsLogical(b, _RC)
match = a_as_bool .eqv. b_as_bool
_RETURN(_SUCCESS)
end if

a_as_int = ESMF_HConfigAsI8(a, asOkay=a_is, _RC)
b_as_int = ESMF_HConfigAsI8(b, asOkay=b_is, _RC)
_RETURN_UNLESS(a_is .eqv. b_is)

if (a_is) then
case (CORE_SCHEMA_INT_TAG)
a_as_int = ESMF_HConfigAsI8(a, _RC)
b_as_int = ESMF_HConfigAsI8(b, _RC)
match = (a_as_int == b_as_int)
_RETURN(_SUCCESS)
end if

a_as_float = ESMF_HConfigAsR8(a, asOkay=a_is, _RC)
b_as_float = ESMF_HConfigAsR8(b, asOkay=b_is, _RC)
_RETURN_UNLESS(a_is .eqv. b_is)

if (a_is) then
case (CORE_SCHEMA_FLOAT_TAG)
a_as_float = ESMF_HConfigAsR8(a, _RC)
b_as_float = ESMF_HConfigAsR8(b, _RC)
match = (a_as_float == b_as_float)
_RETURN(_SUCCESS)
end if

! Otherwise they are strings ...
a_str = ESMF_HConfigAsString(a, _RC)
b_str = ESMF_HConfigAsString(b, _RC)
match = (a_str == b_str)
case default
! Otherwise they are strings ...
a_str = ESMF_HConfigAsString(a, _RC)
b_str = ESMF_HConfigAsString(b, _RC)
match = (a_str == b_str)

end select

_RETURN(_SUCCESS)
end function MAPL_HConfigMatchScalar
Expand Down
5 changes: 0 additions & 5 deletions generic3g/tests/Test_HConfigMatch.pf
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,7 @@ contains
call ESMF_HConfigDestroy(b, _RC)
end subroutine test_match_int_ignore_sign

! The remaining tests are disable for now because
! of bug in ESMF_HConfig that prevents disambiguation
! of quoted strings.
@test
@disable
! YAML distinguish strings like `"no"` from bool `no`.
subroutine test_match_bool_str_mismatch()
type(ESMF_HConfig) :: a, b
Expand All @@ -291,7 +287,6 @@ contains
end subroutine test_match_bool_str_mismatch

@test
@disable
subroutine test_match_int_str_mismatch()
type(ESMF_HConfig) :: a, b
logical :: match
Expand Down

0 comments on commit 755082c

Please sign in to comment.