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 :: itemcount, localPet, i
type(ESMF_FieldBundle) :: srcFieldBundle, dstFieldBundle
type(ESMF_VM) :: vm
real(ESMF_KIND_R8), allocatable:: factorList(:)
integer, allocatable:: factorIndexList(:,:)
! Initialize return code
rc = ESMF_SUCCESS
print *, "User Coupler Init starting"
call ESMF_StateGet(importState, itemcount=itemcount, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
print *, "Import State contains ", itemcount, " items."
! Need to reconcile import and export states
call ESMF_CplCompGet(comp, vm=vm, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_StateReconcile(importState, vm=vm, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_StateReconcile(exportState, vm=vm, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! Get source FieldBundle out of import State
call ESMF_StateGet(importState, "fieldbundle data", srcFieldBundle, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! Get destination FieldBundle out of export State
call ESMF_StateGet(exportState, "fieldbundle data", dstFieldBundle, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! get localPet
call ESMF_VMGet(vm, localPet=localPet, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! Precompute and store an FieldBundleRegrid operation
call ESMF_FieldBundleRegridStore(srcFieldBundle=srcFieldBundle, &
dstFieldBundle=dstFieldBundle, &
routehandle=routehandle, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
print *, "User Coupler Init returning"
end subroutine user_init