CalculateConnection Subroutine

private subroutine CalculateConnection(centerCount, minIndexPTile, maxIndexPTile, connectionList, rc)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: centerCount
integer, pointer :: minIndexPTile(:,:)
integer, pointer :: maxIndexPTile(:,:)
type(ESMF_DistGridConnection), pointer :: connectionList(:)
integer, intent(out) :: rc

Source Code

subroutine CalculateConnection(centerCount, minIndexPTile, &
                    maxIndexPTile, connectionList, rc)

! !ARGUMENTS:
    integer,             intent(in)            :: centerCount
    integer, pointer                           :: minIndexPTile(:,:)
    integer, pointer                           :: maxIndexPTile(:,:)
    type(ESMF_DistGridConnection), pointer     :: connectionList(:)
    integer,            intent(out)            :: rc
!IEOP

    integer                                    :: i, j, conn
    integer                                    :: tileCount, tile
    integer                                    :: connectionCount
    integer                                    :: localrc

    rc=ESMF_SUCCESS

    tileCount = 6

    ! - initialize Min/Max
    ! The full cubed sphere has 6 tiles. For testing, tiles can be
    ! turned on incrementally from 1 all the way to 6. Anything greater than
    ! 6 is incorrect.
    tile=0
    if (tile==tileCount) goto 10
    !- tile 1
    tile=1
    minIndexPTile(1,tile)=1
    minIndexPTile(2,tile)=1
    maxIndexPTile(1,tile)=minIndexPTile(1,tile)+centerCount-1
    maxIndexPTile(2,tile)=minIndexPTile(2,tile)+centerCount-1
    if (tile==tileCount) goto 10
    !- tile 2
    tile=2
    minIndexPTile(1,tile)=maxIndexPTile(1,tile-1)+1
    minIndexPTile(2,tile)=minIndexPTile(2,tile-1)
    maxIndexPTile(1,tile)=minIndexPTile(1,tile)+centerCount-1
    maxIndexPTile(2,tile)=minIndexPTile(2,tile)+centerCount-1
    if (tile==tileCount) goto 10
    !- tile 3
    tile=3
    minIndexPTile(1,tile)=minIndexPTile(1,tile-1)
    minIndexPTile(2,tile)=maxIndexPTile(2,tile-1)+1
    maxIndexPTile(1,tile)=minIndexPTile(1,tile)+centerCount-1
    maxIndexPTile(2,tile)=minIndexPTile(2,tile)+centerCount-1
    if (tile==tileCount) goto 10
    !- tile 4
    tile=4
    minIndexPTile(1,tile)=maxIndexPTile(1,tile-1)+1
    minIndexPTile(2,tile)=minIndexPTile(2,tile-1)
    maxIndexPTile(1,tile)=minIndexPTile(1,tile)+centerCount-1
    maxIndexPTile(2,tile)=minIndexPTile(2,tile)+centerCount-1
    if (tile==tileCount) goto 10
    !- tile 5
    tile=5
    minIndexPTile(1,tile)=minIndexPTile(1,tile-1)
    minIndexPTile(2,tile)=maxIndexPTile(2,tile-1)+1
    maxIndexPTile(1,tile)=minIndexPTile(1,tile)+centerCount-1
    maxIndexPTile(2,tile)=minIndexPTile(2,tile)+centerCount-1
    if (tile==tileCount) goto 10
    !- tile 6
    tile=6
    minIndexPTile(1,tile)=maxIndexPTile(1,tile-1)+1
    minIndexPTile(2,tile)=minIndexPTile(2,tile-1)
    maxIndexPTile(1,tile)=minIndexPTile(1,tile)+centerCount-1
    maxIndexPTile(2,tile)=minIndexPTile(2,tile)+centerCount-1
    if (tile==tileCount) goto 10

10  continue

    ! - connectionList
    ! The full cubed sphere has 12 conections. For testing, connections can be
    ! turned on incrementally from 0 all the way to 12. Anything greater than
    ! 12 is incorrect.
    connectionCount = 12  ! between 0 ... and ... 12.

    ! Connections are either defined on the basis of centers or corners, they
    ! are NOT the same! Our current strategy is to define connections for
    ! centers, and add corners with padding and no connections. This way we
    ! can regrid center data bilinear and conservatively. We cannot handle
    ! regridding for data on corner stagger, plus we have degeneracies in that
    ! case of exlusive elements. However, we believe that the current
    ! application of this is for only data on center stagger.

    conn=0
    if (conn==connectionCount) goto 20

    conn=conn+1
    call ESMF_DistGridConnectionSet(connection=connectionList(conn), &
      tileIndexA=1, tileIndexB=2, positionVector=(/0, 0/), rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    if (conn==connectionCount) goto 20

    conn=conn+1
    call ESMF_DistGridConnectionSet(connection=connectionList(conn), &
      tileIndexA=2, tileIndexB=3, positionVector=(/0, 0/), rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    if (conn==connectionCount) goto 20

    conn=conn+1
    call ESMF_DistGridConnectionSet(connection=connectionList(conn), &
      tileIndexA=3, tileIndexB=4, positionVector=(/0, 0/), rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    if (conn==connectionCount) goto 20

    conn=conn+1
    call ESMF_DistGridConnectionSet(connection=connectionList(conn), &
      tileIndexA=4, tileIndexB=5, positionVector=(/0, 0/), rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    if (conn==connectionCount) goto 20

    conn=conn+1
    call ESMF_DistGridConnectionSet(connection=connectionList(conn), &
      tileIndexA=5, tileIndexB=6, positionVector=(/0, 0/), rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    if (conn==connectionCount) goto 20

    conn=conn+1
    call ESMF_DistGridConnectionSet(connection=connectionList(conn), &
      tileIndexA=1, tileIndexB=6, &
      positionVector=(/ &     ! only shift
      minIndexPTile(1,6)-minIndexPTile(1,1),  &
      maxIndexPTile(2,6)-minIndexPTile(2,1)+1/), &
      rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    if (conn==connectionCount) goto 20

    conn=conn+1
    call ESMF_DistGridConnectionSet(connection=connectionList(conn), &
      tileIndexA=1, tileIndexB=3, orientationVector=(/2, -1/), &  ! 270 deg rot
      positionVector=(/minIndexPTile(1,3)-1-maxIndexPTile(2,1), &
                       maxIndexPTile(2,3)+minIndexPTile(1,1)/), &
      rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    if (conn==connectionCount) goto 20

    conn=conn+1
    call ESMF_DistGridConnectionSet(connection=connectionList(conn), &
      tileIndexA=2, tileIndexB=4, orientationVector=(/-2, 1/), &  ! 90 deg rot
      positionVector=(/minIndexPTile(1,4)+maxIndexPTile(2,2),     &
                       minIndexPTile(2,4)-maxIndexPTile(1,2)-1/), &
      rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    if (conn==connectionCount) goto 20

    conn=conn+1
    call ESMF_DistGridConnectionSet(connection=connectionList(conn), &
      tileIndexA=3, tileIndexB=5, orientationVector=(/2, -1/), &  ! 270 deg rot
      positionVector=(/minIndexPTile(1,5)-1-maxIndexPTile(2,3), &
                       maxIndexPTile(2,5)+minIndexPTile(1,3)/), &
      rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    if (conn==connectionCount) goto 20

    conn=conn+1
    call ESMF_DistGridConnectionSet(connection=connectionList(conn), &
      tileIndexA=4, tileIndexB=6, orientationVector=(/-2, 1/), &  ! 90 deg rot
      positionVector=(/minIndexPTile(1,6)+maxIndexPTile(2,4),     &
                       minIndexPTile(2,6)-maxIndexPTile(1,4)-1/), &
      rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    if (conn==connectionCount) goto 20

    conn=conn+1
    call ESMF_DistGridConnectionSet(connection=connectionList(conn), &
      tileIndexA=5, tileIndexB=1, orientationVector=(/2, -1/), &  ! 270 deg rot
      positionVector=(/minIndexPTile(1,1)-1-maxIndexPTile(2,5), &
                       maxIndexPTile(2,1)+minIndexPTile(1,5)/), &
      rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    if (conn==connectionCount) goto 20

    conn=conn+1
    call ESMF_DistGridConnectionSet(connection=connectionList(conn), &
      tileIndexA=6, tileIndexB=2, orientationVector=(/-2, 1/), &  ! 90 deg rot
      positionVector=(/minIndexPTile(1,2)+maxIndexPTile(2,6),     &
                       minIndexPTile(2,2)-maxIndexPTile(1,6)-1/), &
      rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    if (conn==connectionCount) goto 20

20  continue

    return

end subroutine CalculateConnection