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_Grid) :: grid
type(ESMF_Field) :: field
type(ESMF_FieldBundle) :: fieldbundle
integer :: k
! Initialize return code
rc = ESMF_SUCCESS
print *, "User Comp2 Final starting"
call ESMF_StateGet(importState, "fieldbundle data", fieldbundle, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_FieldBundleGet(fieldbundle, grid=grid, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
do k = 1, 3
call ESMF_FieldBundleGet(fieldbundle, fieldIndex=k, field=field, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_FieldDestroy(field, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
enddo
call ESMF_FieldBundleDestroy(fieldbundle, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_GridDestroy(grid, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
print *, "User Comp2 Final returning"
end subroutine user_final