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
integer :: status = ESMF_SUCCESS
type(ESMF_Field) :: sorted_data
type(ESMF_DistGrid) :: distgrid
type(ESMF_Grid) :: grid
print *, "In user 2 final routine"
call ESMF_StateGet(importState, "sorted_data2", sorted_data, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_FieldGet(sorted_data, grid=grid, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_GridGet(grid, distgrid=distgrid, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! destroy the objects
call ESMF_FieldDestroy(sorted_data, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_GridDestroy(grid, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_DistGridDestroy(distgrid, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
rc = status
end subroutine user_final