comp1_init Subroutine

public subroutine comp1_init(gcomp, istate, ostate, clock, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_GridComp) :: gcomp
type(ESMF_State) :: istate
type(ESMF_State) :: ostate
type(ESMF_Clock) :: clock
integer, intent(out) :: rc

Source Code

subroutine comp1_init(gcomp, istate, ostate, clock, rc)
    type(ESMF_GridComp)  :: gcomp
    type(ESMF_State)     :: istate, ostate
    type(ESMF_Clock)     :: clock
    integer, intent(out) :: rc

    type(ESMF_Field)      :: field
    type(ESMF_State)      :: neststate
    type(ESMF_FieldBundle):: fb
    type(ESMF_Grid)       :: grid
    integer               :: i
    character(40)         :: fieldName

    print *, "i am comp1_init"

    rc = ESMF_SUCCESS

    field = ESMF_FieldEmptyCreate(name="Comp1 Field", rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out

    call ESMF_StateAdd(istate, (/field/), rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out

    neststate = ESMF_StateCreate(name="Comp1 Nested State", rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out

    call ESMF_StateAdd(istate, (/neststate/), rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out

    field = ESMF_FieldEmptyCreate(name="Comp1 Field in Nested State", rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out

    call ESMF_StateAdd(neststate, (/field/), rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out

    fb = ESMF_FieldBundleCreate(name="Comp1 FieldBundle", rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out

    grid = ESMF_GridCreateNoPeriDim(name="Comp1 Grid", regDecomp=(/2,1/), &
      minIndex=(/1,1/), maxIndex=(/10,20/), rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out

    do i=1,FB_MEMBER_COUNT
      write(fieldName,'("Comp1 Field ", I2, " in FB")') i

      field = ESMF_FieldCreate(name=trim(fieldName), grid=grid, &
        typekind=ESMF_TYPEKIND_R8, rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, &
        file=FILENAME)) &
        return  ! bail out

      call ESMF_FieldBundleAdd(fb, (/field/), rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, &
        file=FILENAME)) &
        return  ! bail out
    enddo

    call ESMF_StateAdd(istate, (/fb/), rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out

    ! store the grid inside gcomp to provide access during run method for check
    call ESMF_GridCompSet(gcomp, grid=grid, rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
      line=__LINE__, &
      file=FILENAME)) &
      return  ! bail out

end subroutine comp1_init