subroutine user_final(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) :: field
type(ESMF_Grid) :: grid
type(ESMF_VM) :: vm
integer :: de_id
rc = ESMF_SUCCESS
print *, "User Comp Final starting"
call ESMF_GridCompGet(comp, vm=vm, rc=rc)
if(rc/=ESMF_SUCCESS) return
call ESMF_VMGet(vm, localPet=de_id, rc=rc)
if(rc/=ESMF_SUCCESS) return
! set this up to run the validate code on all fields
! so we can see and compare the output. but if any of
! the verify routines return error, return error at the end.
! check validity of results
! Get Fields from import state
call ESMF_StateGet(importState, "humidity", field, rc=rc)
if(rc/=ESMF_SUCCESS) return
call verifyResults(field, de_id, rc)
if(rc/=ESMF_SUCCESS) return
! come straight here if you cannot get the data from the state.
! otherwise error codes are accumulated but ignored until the
! end so we can see the output from all the cases to help track
! down errors.
! garbage collection
call ESMF_FieldGet(field, grid=grid, rc=rc)
if (rc .ne. ESMF_SUCCESS) return
call ESMF_FieldDestroy(field, rc=rc)
if (rc .ne. ESMF_SUCCESS) return
call ESMF_GridDestroy(grid, rc=rc)
if (rc .ne. ESMF_SUCCESS) return
print *, "User Comp Final returning"
end subroutine user_final