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_Field) :: humidity
type(ESMF_VM) :: vm
type(ESMF_Grid) :: grid
type(ESMF_DistGrid) :: distgrid
type(ESMF_ArraySpec) :: arrayspec
integer(ESMF_KIND_I4), dimension(:), pointer :: dstfptr
integer :: npets, de_id
rc = ESMF_SUCCESS
! Initially import state contains a field with a grid but no data.
! Query component for VM and create a layout with the right breakdown
call ESMF_GridCompGet(comp, vm=vm, rc=rc)
if(rc/=ESMF_SUCCESS) return
call ESMF_VMGet(vm, localPet=de_id, petCount=npets, rc=rc)
if(rc/=ESMF_SUCCESS) return
print *, de_id, "User Comp 2 Init starting"
! Add a "humidity" field to the import state.
distgrid = ESMF_DistGridCreate(minIndex=(/1/), maxIndex=(/9/), rc=rc)
if(rc/=ESMF_SUCCESS) return
grid = ESMF_GridCreate(distgrid=distgrid, rc=rc)
if(rc/=ESMF_SUCCESS) return
call ESMF_ArraySpecSet(arrayspec, 1, ESMF_TYPEKIND_I4, rc=rc)
if(rc/=ESMF_SUCCESS) return
humidity = ESMF_FieldCreate(grid, arrayspec, &
name="humidity", rc=rc)
if(rc/=ESMF_SUCCESS) return
call ESMF_FieldGet(humidity, localDe=0, farrayPtr=dstfptr, rc=rc)
if(rc/=ESMF_SUCCESS) return
dstfptr = 0
call ESMF_StateAdd(importState, (/humidity/), rc=rc)
if(rc/=ESMF_SUCCESS) return
! call ESMF_StatePrint(importState, rc=rc)
print *, de_id, "User Comp 2 Init returning"
end subroutine user_init