subroutine IOCompUTestCompare(inputFields, outputFields, maxdiffI4, maxdiffR4, maxdiffR8, rc)
type(ESMF_Field), dimension(:), intent(in) :: inputFields, outputFields
integer(ESMF_KIND_I4), dimension(:), intent(out) :: maxdiffI4
real (ESMF_KIND_R4), dimension(:), intent(out) :: maxdiffR4
real (ESMF_KIND_R8), dimension(:), intent(out) :: maxdiffR8
integer, intent(out) :: rc
! -- local variables
integer :: fieldCount, item, localDe, localDeCount
integer(ESMF_KIND_I4) :: maxdI4
real (ESMF_KIND_R4) :: maxdR4
real (ESMF_KIND_R8) :: maxdR8
integer(ESMF_KIND_I4), dimension(:,:), pointer :: fpInpI4, fpOutI4
real (ESMF_KIND_R4), dimension(:,:), pointer :: fpInpR4, fpOutR4
real (ESMF_KIND_R8), dimension(:,:), pointer :: fpInpR8, fpOutR8
type(ESMF_TypeKind_Flag) :: typekind
! -- begin
rc = ESMF_SUCCESS
maxdiffI4 = 0_ESMF_KIND_I4
maxdiffR4 = 0._ESMF_KIND_R4
maxdiffR8 = 0._ESMF_KIND_R8
fieldCount = size(inputFields)
if (fieldCount /= size(outputFields)) then
call ESMF_LogSetError(ESMF_RC_ARG_SIZE, &
msg="Size of input and output Fields arrays must match.", &
line=__LINE__, file=__FILE__, rcToReturn=rc)
return
end if
if ((fieldCount /= size(maxdiffI4)) .or. &
(fieldCount /= size(maxdiffR4)) .or. &
(fieldCount /= size(maxdiffR8))) then
call ESMF_LogSetError(ESMF_RC_ARG_SIZE, &
msg="Size of maxdiff arguments must match size of input/output Field arrays", &
line=__LINE__, file=__FILE__, rcToReturn=rc)
return
end if
do item = 1, size(inputFields)
call ESMF_FieldGet(inputFields(item), localDeCount=localDeCount, &
typekind=typekind, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=__FILE__)) return
if (typekind == ESMF_TYPEKIND_I4) then
print *,'Comparing ESMF_TYPEKIND_I4 Fields'
do localDe = 0, localDeCount-1
call ESMF_FieldGet(inputFields(item), localDE=localDe, &
farrayPtr=fpInpI4, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=__FILE__)) return
call ESMF_FieldGet(outputFields(item), localDE=localDe, &
farrayPtr=fpOutI4, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=__FILE__)) return
print *,'|write |, min/max: ', minval(fpOutI4), maxval(fpOutI4)
print *,'|read |, min/max: ', minval(fpInpI4), maxval(fpInpI4)
maxdI4 = maxval(abs(fpOutI4-fpInpI4))
print *,'|read-write|, min/max: ', minval(abs(fpOutI4-fpInpI4)), maxdI4
maxdiffI4(item) = max(maxdiffI4(item), maxdI4)
end do
else if (typekind == ESMF_TYPEKIND_R4) then
print *,'Comparing ESMF_TYPEKIND_R4 Fields'
do localDe = 0, localDeCount-1
call ESMF_FieldGet(inputFields(item), localDE=localDe, &
farrayPtr=fpInpR4, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=__FILE__)) return
call ESMF_FieldGet(outputFields(item), localDE=localDe, &
farrayPtr=fpOutR4, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=__FILE__)) return
print *,'|write |, min/max: ', minval(fpOutR4), maxval(fpOutR4)
print *,'|read |, min/max: ', minval(fpInpR4), maxval(fpInpR4)
maxdR4 = maxval(abs(fpOutR4-fpInpR4))
print *,'|read-write|, min/max: ', minval(abs(fpOutR4-fpInpR4)), maxdR4
maxdiffR4(item) = max(maxdiffR4(item), maxdR4)
end do
else if (typekind == ESMF_TYPEKIND_R8) then
print *,'Comparing ESMF_TYPEKIND_R8 Fields'
do localDe = 0, localDeCount-1
call ESMF_FieldGet(inputFields(item), localDE=localDe, &
farrayPtr=fpInpR8, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=__FILE__)) return
call ESMF_FieldGet(outputFields(item), localDE=localDe, &
farrayPtr=fpOutR8, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=__FILE__)) return
print *,'|write |, min/max: ', minval(fpOutR8), maxval(fpOutR8)
print *,'|read |, min/max: ', minval(fpInpR8), maxval(fpInpR8)
maxdR8 = maxval(abs(fpOutR8-fpInpR8))
print *,'|read-write|, min/max: ', minval(abs(fpOutR8-fpInpR8)), maxdR8
maxdiffR8(item) = max(maxdiffR8(item), maxdR8)
end do
end if
flush(6)
end do
end subroutine IOCompUTestCompare