subroutine myInitInFortran(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_Array) :: array
type(ESMF_ArraySpec) :: arrayspec
type (ESMF_DistGrid) :: distgrid
type (ESMF_VM) :: vm
integer :: petCount, i
character(ESMF_MAXSTR) :: name
! Initialize return code
rc = ESMF_SUCCESS
print *, "In myInitInFortran routine"
! Allocate the Fortran array and initialize data
allocate (farray(5,2))
do i=1,5
farray(i,:) = float(i)
end do
! This is where the model specific setup code goes.
call ESMF_GridCompPrint(comp, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
call ESMF_StatePrint(exportState, options="", rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
call ESMF_GridCompGet(comp, vm=vm, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
call ESMF_VMGet(vm, petCount=petCount, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
! Create and Array
call ESMF_ArraySpecSet(arrayspec, typekind=ESMF_TYPEKIND_R8, rank=2, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
distgrid = ESMF_DistGridCreate(minIndex=(/1,1/), maxIndex=(/5*petCount,2/),&
rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
array = ESMF_ArrayCreate(farray=farray, distgrid=distgrid, &
indexflag=ESMF_INDEX_DELOCAL, name="array1", rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
! Add Array to the export State
call ESMF_StateAdd(exportState, (/array/), rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
call ESMF_StatePrint(exportState, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
end subroutine myInitInFortran