subroutine user_init(comp, importState, exportState, clock, rc)
type(ESMF_CplComp) :: comp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer,intent(out) :: rc
! Local variables
integer :: status = ESMF_SUCCESS
integer :: itemcount, dimCount
type(ESMF_Field) :: sorted_data1, sorted_data2
type(ESMF_VM) :: vm
integer :: pet_id
print *, "User Coupler Init starting"
status = ESMF_FAILURE
! Get VM from coupler component
call ESMF_CplCompGet(comp, vm=vm, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_VMGet(vm, localPET=pet_id, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Since the components we are coupling between are running concurrently,
! they have each separately created ESMF objects. We are planning to
! use a communications call (Redist) here, so first we must make a new
! call to reconcile the object lists in all the import and export states.
! New routine:
! Must be called on each state which is going to be accessed from
! this coupler. When the call returns all objects which were not
! in existence on all PETs now have an object which represents them.
call ESMF_StateReconcile(importState, vm=vm, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
!call ESMF_StatePrint(importState, rc=status)
!if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
! ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_StateReconcile(exportState, vm=vm, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
!call ESMF_StatePrint(exportState, rc=status)
!if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
! ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_StateGet(importState, itemcount=itemcount, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
!print *, "Import State contains ", itemcount, " items."
call ESMF_StateGet(exportState, itemcount=itemcount, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
!print *, "Export State contains ", itemcount, " items."
! Get the src and dst arrays
call ESMF_StateGet(importState, "sorted_data1", sorted_data1, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_StateGet(exportState, "sorted_data2", sorted_data2, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! check dimCount
call ESMF_FieldGet(sorted_data1, dimCount=dimCount, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
if(dimCount /= 1) then
call ESMF_LogSetError(ESMF_RC_OBJ_BAD, &
msg="dimCount not properly reconciled", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! precompute redist handle
call ESMF_FieldRedistStore(srcField=sorted_data1, &
dstField=sorted_data2, routehandle=redistRH12, rc=status)
if (ESMF_LogFoundError(status, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
rc = status
end subroutine user_init