user_init Subroutine

public subroutine user_init(comp, importState, exportState, clock, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_GridComp) :: comp
type(ESMF_State) :: importState
type(ESMF_State) :: exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc

Source Code

  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_FieldBundle):: fieldbundle
    type(ESMF_VM)         :: vm
    integer               :: petCount, i
    character(len=ESMF_MAXSTR) :: names(3)
    real(ESMF_KIND_R8), pointer :: farrayPtr(:,:,:)   ! matching F90 array pointer
    integer               :: compLBnd(2),compUBnd(2)
    
    ! 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_GridCreateNoPeriDimUfrm( &
    maxIndex=(/100,150/), &
    regDecomp=(/1, petCount/), &
    minCornerCoord=(/0.0_ESMF_KIND_R8,-75.0_ESMF_KIND_R8/), &
    maxCornerCoord=(/100.0_ESMF_KIND_R8,75.0_ESMF_KIND_R8/), &
    staggerLocList=(/ESMF_STAGGERLOC_CORNER, ESMF_STAGGERLOC_CENTER/), &
    rc=rc)
    if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)

    ! Get Bounds
    call ESMF_GridGet(grid, localDe=0, staggerloc=ESMF_STAGGERLOC_CENTER, &
           computationalLBound=compLBnd, computationalUBound=compUBnd, rc=rc)
    if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)

    ! The packed dimension is the 2nd dimension. This is a different
    ! interleave from the src packed Field Bundle.
    ! (gridded, packed_fieldim, gridded)
    allocate(farrayPtr(compLBnd(1):compUBnd(1),3,compLBnd(2):compUBnd(2)))
    names(1) = 'field01'
    names(2) = 'field02'
    names(3) = 'field03'

    ! fielddim is 2, grid dims are 1,3
    fieldbundle = ESMF_FieldBundleCreate(fieldNameList=names, fieldDim=2, &
        grid=grid, farrayPtr=farrayPtr, &
        gridToFieldMap=(/1,3/), &
        name="fieldbundle data", rc=rc)
    if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)

    ! Initialize dst data to 0.
    call ESMF_FieldBundleGet(fieldbundle, farrayPtr=farrayPtr, rc=rc)
    if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
    farrayPtr = 0.

    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