subroutine user_initP3(comp, importState, exportState, clock, rc)
type(ESMF_CplComp) :: comp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
! Local variables
type(ESMF_Field) :: srcField, dstField, finalField
type(ESMF_RouteHandle) :: rh
! Initialize return code
rc = ESMF_SUCCESS
print *, "User Coupler Init phase=3 starting"
call ESMF_LogWrite (msg='User Coupler Init phase=3 starting', &
logmsgFlag=ESMF_LOGMSG_TRACE)
! Re-reconcile import and export states, just in case something changed
call ESMF_LogWrite (msg='User Coupler Init phase=3 Reconcile importState', &
logmsgFlag=ESMF_LOGMSG_TRACE)
call ESMF_StateReconcile(importState, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
call ESMF_LogWrite (msg='User Coupler Init phase=3 Reconcile exportState', &
logmsgFlag=ESMF_LOGMSG_TRACE)
call ESMF_StateReconcile(exportState, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
! Access source, final, and destination Fields
call ESMF_LogWrite (msg='User Coupler Init phase=3 access Fields', &
logmsgFlag=ESMF_LOGMSG_TRACE)
call ESMF_StateGet(importState, "srcField", srcField, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
call ESMF_StateGet(importState, "finalField", finalField, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
call ESMF_StateGet(exportState, "dstField", dstField, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
! Precompute the Redist operation, give it a name and keep it in importState
call ESMF_LogWrite (msg='User Coupler Init phase=3 FieldRegridStore srcField->dstField', &
logmsgFlag=ESMF_LOGMSG_TRACE)
call ESMF_FieldRedistStore(srcField, dstField, routehandle=rh, rc=rc)
call ESMF_LogWrite (msg='User Coupler Init phase=3 FieldRegridStore srcField->dstField complete', &
logmsgFlag=ESMF_LOGMSG_TRACE)
if (rc/=ESMF_SUCCESS) return ! bail out
call ESMF_RouteHandleSet(rh, name="Redist", rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
call ESMF_StateAdd(importState, (/rh/), rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
! Precompute the Regrid operation, give it a name and keep it in importState
call ESMF_LogWrite (msg='User Coupler Init phase=3 FieldRegridStore dstField->finalField', &
logmsgFlag=ESMF_LOGMSG_TRACE)
call ESMF_FieldRegridStore(dstField, finalField, routehandle=rh, rc=rc)
call ESMF_LogWrite (msg='User Coupler Init phase=3 FieldRegridStore dstField->finalField complete', &
logmsgFlag=ESMF_LOGMSG_TRACE)
if (rc/=ESMF_SUCCESS) return ! bail out
call ESMF_RouteHandleSet(rh, name="Regrid", rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
call ESMF_StateAdd(importState, (/rh/), rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
call ESMF_LogWrite (msg='User Coupler Init phase=3 complete', &
logmsgFlag=ESMF_LOGMSG_TRACE)
print *, "User Coupler Init phase=3 returning"
end subroutine user_initP3