user_run Subroutine

public subroutine user_run(comp, importState, exportState, clock, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_GridComp) :: comp
type(ESMF_State) :: importState
type(ESMF_State) :: exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc

Source Code

    subroutine user_run(comp, importState, exportState, clock, rc)
      type(ESMF_GridComp) :: comp
      type(ESMF_State) :: importState, exportState
      type(ESMF_Clock) :: clock
      integer, intent(out) :: rc

!   ! Local variables
      type(ESMF_Field) :: dstField
      type(ESMF_Mesh) :: dstMesh
      type(ESMF_VM) :: vm
      integer :: localrc,i
      integer :: localPet, petCount
      real(ESMF_KIND_R8), pointer :: fptr1D(:)
      real(ESMF_KIND_R8) :: x,y
      integer :: numOwnedNodes
      real(ESMF_KIND_R8), pointer :: ownedNodeCoords(:)

      rc = ESMF_SUCCESS

      ! Query component for VM and create a layout with the right breakdown
      call ESMF_GridCompGet(comp, vm=vm, rc=rc)
      if(rc/=ESMF_SUCCESS) return
      call ESMF_VMGet(vm, localPet=localPet, petCount=petCount, rc=rc)
      if(rc/=ESMF_SUCCESS) return

      ! Get information from the component.
      call ESMF_StateGet(importState, "dst", dstField, rc=rc)
      if(rc/=ESMF_SUCCESS) return


      ! Get Grid from field
      call ESMF_FieldGet(dstField, mesh=dstMesh, rc=localrc)
      if (localrc /=ESMF_SUCCESS) then
          rc=ESMF_FAILURE
          return
      endif

      ! Check destination field
      ! Should only be 1 localDE
      call ESMF_FieldGet(dstField, 0, fptr1D,  rc=localrc)
      if (localrc /=ESMF_SUCCESS) then
         rc=ESMF_FAILURE
         return
      endif


      ! Get number of local nodes to allocate space
      ! to hold local node coords
      call ESMF_MeshGet(dstMesh, numOwnedNodes=numOwnedNodes, &
             rc=rc)

      ! Allocate space to hold local node coordinates
      ! (spatial dimension of Mesh*number of local nodes)
      allocate(ownedNodeCoords(2*numOwnedNodes))

      ! Get local node coordinates
      call ESMF_MeshGet(dstMesh, &
             ownedNodeCoords=ownedNodeCoords, rc=rc)


      ! loop through nodes and make sure interpolated values are reasonable
      do i=1,numOwnedNodes
         ! Get coordinates
         x=ownedNodeCoords(2*i-1)
         y=ownedNodeCoords(2*i)

         !! if error is too big report an error
         if ( abs( fptr1D(i)-(x+y+20.0) ) > 0.0001) then
              rc=ESMF_FAILURE
              return
         endif  
      enddo

      ! deallocate space to hold local node coordinates
      deallocate(ownedNodeCoords)

      ! RESET DESTINATION BACK TO 0
      fptr1D=0.0

      ! Return success
      rc = ESMF_SUCCESS

    end subroutine user_run