subroutine check_field_value(expectations, state, short_name, description, rc)
type(ESMF_HConfig), intent(in) :: expectations
type(ESMF_State), intent(inout) :: state
character(*), intent(in) :: short_name
character(*), intent(in) :: description
integer, intent(out) :: rc
real :: expected_field_value
integer :: rank
type(ESMF_TypeKind_Flag) :: typekind
integer :: status
character(len=:), allocatable :: msg
type(ESMF_Field) :: field
type(ESMF_StateItem_Flag) :: itemtype
msg = description
itemtype = get_itemtype(state, short_name, _RC)
if (itemtype /= ESMF_STATEITEM_FIELD) then ! that's ok
rc = 0
return
end if
if (.not. ESMF_HConfigIsDefined(expectations,keyString='value')) then
rc = 0
return
end if
expected_field_value = ESMF_HConfigAsR4(expectations,keyString='value',_RC)
call ESMF_StateGet(state, short_name, field, _RC)
call ESMF_FieldGet(field, typekind=typekind, rank=rank, rc=status)
@assert_that('field get failed '//short_name, status, is(0))
if (typekind == ESMF_TYPEKIND_R4) then
block
real(kind=ESMF_KIND_R4), pointer :: x2(:,:),x3(:,:,:),x4(:,:,:,:)
select case(rank)
case(2)
call ESMF_FieldGet(field, farrayPtr=x2, _RC)
@assert_that('value of '//short_name, all(x2 == expected_field_value), is(true()))
case(3)
call ESMF_FieldGet(field, farrayPtr=x3, _RC)
@assert_that('value of '//short_name, all(x3 == expected_field_value), is(true()))
case(4)
call ESMF_FieldGet(field, farrayPtr=x4, _RC)
@assert_that('value of '//short_name, all(x4 == expected_field_value), is(true()))
end select
end block
elseif (typekind == ESMF_TYPEKIND_R8) then
block
real(kind=ESMF_KIND_R8), pointer :: x2(:,:),x3(:,:,:),x4(:,:,:,:)
select case(rank)
case(2)
call ESMF_FieldGet(field, farrayPtr=x2, _RC)
@assert_that('value of '//short_name, all(x2 == expected_field_value), is(true()))
case(3)
call ESMF_FieldGet(field, farrayPtr=x3, _RC)
@assert_that('value of '//short_name, all(x3 == expected_field_value), is(true()))
case(4)
call ESMF_FieldGet(field, farrayPtr=x4, _RC)
@assert_that('value of '//short_name, all(x4 == expected_field_value), is(true()))
end select
end block
else
_VERIFY(-1)
end if
rc = 0
end subroutine check_field_value