verifyResults Subroutine

public subroutine verifyResults(humidity, myDE, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Field) :: humidity
integer :: myDE
integer, intent(out) :: rc

Source Code

    subroutine verifyResults(humidity, myDE, rc)
      type(ESMF_Field) :: humidity
      integer  :: myDE
      integer, intent(out) :: rc

      ! Local variables
      integer :: i, j, i1, j1, haloWidth, counts(2), haloUWidth(2,1), tlb(2), tub(2)
      type(ESMF_Grid) :: grid
      real(ESMF_KIND_R8) :: pi, error, maxError, maxPerError
      real(ESMF_KIND_R8) :: minCValue, maxCValue, minDValue, maxDValue
      real(ESMF_KIND_R8), dimension(:,:), pointer :: calc, data, coordX, coordY

      rc = ESMF_SUCCESS
      print *, "User verifyResults starting"  

      pi = 3.14159

      ! get the grid and coordinates
      call ESMF_FieldGet(humidity, grid=grid, &
                         totalUWidth=haloUWidth, rc=rc)
      if(rc/=ESMF_SUCCESS) return
      haloWidth=haloUWidth(1,1)
      call ESMF_GridGetCoord(grid, localDE=0, coordDim=1, &
                            computationalLBound=tlb, computationalUBound=tub, &
                           farrayPtr=coordX, rc=rc)
      if(rc/=ESMF_SUCCESS) return
      call ESMF_GridGetCoord(grid, localDE=0, coordDim=2, &
                           farrayPtr=coordY, rc=rc)
      if(rc/=ESMF_SUCCESS) return

      ! update field values here
      ! Get a pointer to the start of the data
      call ESMF_FieldGet(humidity, farrayPtr=data, rc=rc)
      if(rc/=ESMF_SUCCESS) return
      print *, "rc from array get data = ", rc
      !if (associated(data)) print *, "pointer is associated"
      !if (.not.associated(data)) print *, "pointer is *NOT* associated"
      ! call ESMF_ArrayPrint(array)
      !print *, "data in validate: ", data(1,1), data(1, 2), data(2, 1)

      ! allocate array for computed results and fill it
      allocate(calc(tlb(1):tub(1), tlb(2):tub(2)))
      do j   = tlb(2), tub(2)
        do i = tlb(1), tub(1)
          calc(i,j) = 10.0 + 5.0*sin(coordX(i,j)/60.0*pi) &
                           + 2.0*sin(coordY(i,j)/50.0*pi)
        enddo
      enddo

     ! calculate data error from computed results
      maxError    = 0.0
      maxPerError = 0.0
      maxCValue   = 0.0
      minCValue   = 1000.0
      maxDValue   = 0.0
      minDValue   = 1000.0
      do j   = tlb(2), tub(2)
        j1   = j + haloWidth
        do i = tlb(1), tub(1)
          i1 = i + haloWidth
          error       = abs(data(i1,j1)) - abs(calc(i,j))
          minCValue   = min(minCValue, abs(calc(i,j)))
          maxCValue   = max(maxCValue, abs(calc(i,j)))
          minDValue   = min(minDValue, abs(data(i1,j1)))
          maxDValue   = max(maxDValue, abs(data(i1,j1)))
          maxError    = max(maxError, abs(error))
          maxPerError = max(maxPerError, 100.*abs(error)/abs(calc(i,j)))
        enddo
      enddo
      deallocate(calc)

      write(*,*) "Results for DE #", myDE, ":"
      write(*,*) "   minimum regridded value = ", minDValue
      write(*,*) "   maximum regridded value = ", maxDValue
      write(*,*) "   minimum computed value  = ", minCValue
      write(*,*) "   maximum computed value  = ", maxCValue
      write(*,*) "   maximum error           = ", maxError
      write(*,*) "   maximum percent error   = ", maxPerError
      print *, "User verifyResults returning"
   
      ! only accept this test as successful if the max percent
      ! error is below 2%
      if (maxPerError .gt. 2.0) then
          write(*,*) "Test Failing because percentage error too large"
          rc = ESMF_FAILURE 
      endif

    end subroutine verifyResults