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
integer :: status = ESMF_SUCCESS
type(ESMF_Field) :: sorted_data
integer, dimension(9), target :: d = (/3,7,8,5,2,1,9,5,4/)
integer, dimension(:), pointer :: rdptr ! raw data ptr
integer, dimension(:), pointer :: sdptr ! sorted data ptr
integer :: i
print *, "In user 2 run 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, localDe=0, farrayPtr=sdptr, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! sort local data
rdptr => d
call quicksortI4(rdptr, 1, 9)
! compare local sorted data with data sorted on component 1
! any mismatch indicates failure
! write(*, '(A16, 9I3)') 'local rdptr', rdptr
do i = lbound(sdptr, 1), ubound(sdptr, 1)
if(rdptr(i) .ne. sdptr(i)) status = ESMF_FAILURE
enddo
rc = status
end subroutine user_run