subroutine user_init(comp, importState, exportState, clock, rc)
type(ESMF_GridComp), intent(inout) :: comp
type(ESMF_State), intent(inout) :: importState, exportState
type(ESMF_Clock), intent(in) :: clock
integer, intent(out) :: rc
! ! Local variables
type(ESMF_Field) :: humidity
type(ESMF_VM) :: vm
type(ESMF_DELayout) :: delayout
type(ESMF_IGrid) :: igrid1
type(ESMF_ArraySpec) :: arrayspec
real(ESMF_KIND_R8), dimension(:,:), pointer :: idata
real(ESMF_KIND_R8) :: min(2), max(2)
real(ESMF_KIND_R8) :: delta1(40), delta2(50)
integer :: countsPerDE1(3), countsPerDE2(2), counts(2)
integer :: npets, de_id
type(ESMF_IGridHorzStagger) :: horz_stagger
integer :: status
! Initially import state contains a field with a igrid but no data.
! Query component for VM and create a layout with the right breakdown
call ESMF_GridCompGet(comp, vm=vm, rc=status)
if (status .ne. ESMF_SUCCESS) goto 10
call ESMF_VMGet(vm, petCount=npets, rc=status)
if (status .ne. ESMF_SUCCESS) goto 10
delayout = ESMF_DELayoutCreate(vm, (/ npets/2, 2 /), rc=status)
if (status .ne. ESMF_SUCCESS) goto 10
! and get our local de number
call ESMF_DELayoutGetDeprecated(delayout, localDE=de_id, rc=status)
if (status .ne. ESMF_SUCCESS) goto 10
print *, de_id, "User Comp 2 Init starting"
! Add a "humidity" field to the import state.
countsPerDE1 = (/ 10, 18, 12 /)
countsPerDE2 = (/ 22, 28 /)
min(1) = 0.0
delta1 = (/ 1.0, 1.0, 1.0, 1.1, 1.1, 1.1, 1.2, 1.2, 1.3, 1.4, &
1.4, 1.5, 1.6, 1.6, 1.6, 1.8, 1.8, 1.7, 1.7, 1.6, &
1.6, 1.6, 1.8, 1.8, 2.0, 2.0, 2.2, 2.2, 2.2, 2.2, &
2.0, 1.7, 1.5, 1.3, 1.2, 1.1, 1.0, 1.0, 1.0, 0.9 /)
min(2) = 0.0
delta2 = (/ 0.8, 0.8, 0.8, 0.8, 0.8, 0.7, 0.7, 0.6, 0.7, 0.8, &
0.9, 0.9, 0.9, 0.9, 1.0, 1.0, 1.0, 1.0, 0.9, 1.0, &
1.0, 1.0, 1.0, 1.1, 1.2, 1.3, 1.3, 1.3, 1.4, 1.4, &
1.4, 1.4, 1.4, 1.4, 1.4, 1.3, 1.3, 1.3, 1.2, 1.2, &
1.1, 1.0, 1.0, 0.9, 0.8, 0.7, 0.6, 0.6, 0.5, 0.5 /)
counts(1) = 200
counts(2) = 100
min(1) = 0.0
max(1) = 60.0
min(2) = 0.0
max(2) = 50.0
horz_stagger = ESMF_IGRID_HORZ_STAGGER_D_NE
igrid1 = ESMF_IGridCreateHorzXYUni(counts=counts, &
minGlobalCoordPerDim=min, &
maxGlobalCoordPerDim=max, &
horzStagger=horz_stagger, &
name="source igrid", rc=status)
if (status .ne. ESMF_SUCCESS) goto 10
call ESMF_IGridDistribute(igrid1, delayout=delayout, rc=status)
if (status .ne. ESMF_SUCCESS) goto 10
! Set up a 2D real array
call ESMF_ArraySpecSet(arrayspec, rank=2, &
typekind=ESMF_TYPEKIND_R8)
if (status .ne. ESMF_SUCCESS) goto 10
! Create the field and have it create the array internally
humidity = ESMF_FieldCreate(igrid1, arrayspec, &
horzRelloc=ESMF_CELL_NFACE, &
haloWidth=0, name="humidity", rc=status)
if (status .ne. ESMF_SUCCESS) goto 10
! Get the allocated array back and get an F90 array pointer
call ESMF_FieldGetDataPointer(humidity, idata, rc=status)
if (status .ne. ESMF_SUCCESS) goto 10
call ESMF_StateAddField(importState, (/array/), status)
if (status .ne. ESMF_SUCCESS) goto 10
! call ESMF_StatePrint(importState, rc=status)
print *, de_id, "User Comp 2 Init returning"
rc = ESMF_SUCCESS
return
! get here only on error exit
10 continue
rc = status
end subroutine user_init