subroutine user_init(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_ArraySpec) :: arrayspec
type(ESMF_Grid) :: grid
type(ESMF_Field) :: field(3)
type(ESMF_FieldBundle):: fieldbundle
type(ESMF_VM) :: vm
integer :: petCount, i
! Initialize return code
rc = ESMF_SUCCESS
print *, "User Comp2 Init starting"
! Determine petCount
call ESMF_GridCompGet(comp, vm=vm, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_VMGet(vm, petCount=petCount, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! Create the destination FieldBundle and add it to the import State
call ESMF_ArraySpecSet(arrayspec, typekind=ESMF_TYPEKIND_R8, rank=2, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
grid = ESMF_GridCreateNoPeriDim(minIndex=(/1,1/), maxIndex=(/100,150/), &
regDecomp=(/1,petCount/), &
gridEdgeLWidth=(/0,0/), gridEdgeUWidth=(/0,0/), & ! no stagger padding
indexflag=ESMF_INDEX_GLOBAL, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
#if 0
do i = 1, 3
field(i) = ESMF_FieldCreate(grid, arrayspec=arrayspec, &
staggerloc=ESMF_STAGGERLOC_CENTER, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
enddo
#else
field(1) = ESMF_FieldCreate(grid, name="Z", arrayspec=arrayspec, &
staggerloc=ESMF_STAGGERLOC_CENTER, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
field(2) = ESMF_FieldCreate(grid, name="Y", arrayspec=arrayspec, &
staggerloc=ESMF_STAGGERLOC_CENTER, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
field(3) = ESMF_FieldCreate(grid, name="X", arrayspec=arrayspec, &
staggerloc=ESMF_STAGGERLOC_CENTER, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
#endif
fieldbundle = ESMF_FieldBundleCreate(fieldList=field, &
name="fieldbundle data", rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_StateAdd(importState, fieldbundleList=(/fieldbundle/), rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
print *, "User Comp2 Init returning"
end subroutine user_init