ESMF_GridFillStaggerCoordsUfrm Subroutine

private subroutine ESMF_GridFillStaggerCoordsUfrm(grid, minCornerCoord, maxCornerCoord, staggerloc, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Grid), intent(in) :: grid
real(kind=ESMF_KIND_R8), intent(in) :: minCornerCoord(:)
real(kind=ESMF_KIND_R8), intent(in) :: maxCornerCoord(:)
type(ESMF_StaggerLoc), intent(in) :: staggerloc
integer, intent(out), optional :: rc

Source Code

  subroutine ESMF_GridFillStaggerCoordsUfrm(grid, &
        minCornerCoord, maxCornerCoord, staggerloc, &
        rc)

    type(ESMF_Grid),           intent(in) :: grid
    real(ESMF_KIND_R8),        intent(in) :: minCornerCoord(:)
    real(ESMF_KIND_R8),        intent(in) :: maxCornerCoord(:)
    type(ESMF_StaggerLoc),     intent(in) :: staggerloc
    integer,                   intent(out), optional :: rc


    integer :: localrc
    integer :: lDE, localDECount
     integer :: clbnd(ESMF_MAXDIM), cubnd(ESMF_MAXDIM), i
    real(ESMF_KIND_R8), pointer :: coordPtr(:)
    integer :: d, dimCount, loc
    real(ESMF_KIND_R8) :: p, p_plus1
    real(ESMF_KIND_R8) :: hcornerIndexDiffR8
    integer :: staggerMinIndex(ESMF_MAXDIM)
    integer :: staggerMaxIndex(ESMF_MAXDIM)
    integer :: hcornerMinIndex(ESMF_MAXDIM)
    integer :: hcornerMaxIndex(ESMF_MAXDIM)
    integer :: centerMinIndex(ESMF_MAXDIM)
    integer :: centerMaxIndex(ESMF_MAXDIM)


    ! Initialize return code; assume failure until success is certain
    localrc = ESMF_RC_NOT_IMPL
    if (present(rc)) rc = ESMF_RC_NOT_IMPL

     ! Get number of local DEs and dimCount
    call ESMF_GridGet(grid, localDECount=localDECount, dimCount=dimCount, rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return

    ! Calculate hypothetical span of corner index space without
    ! padding. To do this get corner min and add number of corners
    ! (which is the number of cells (center stagger) plus 1 in each dimension)
     call ESMF_GridGet(grid,1,ESMF_STAGGERLOC_CENTER, &
         minIndex=centerMinIndex, maxIndex=centerMaxIndex, &
         rc=localrc)
     if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
       ESMF_CONTEXT, rcToReturn=rc)) return

     call ESMF_GridGet(grid,1,ESMF_STAGGERLOC_CORNER, &
         minIndex=hcornerMinIndex, &
         rc=localrc)
     if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
       ESMF_CONTEXT, rcToReturn=rc)) return

     ! Compute hypothetical corner span
      ! use minCorners + off set of number of cells + 1
     do d=1,dimCount
        hcornerMaxIndex(d)=hcornerMinIndex(d)+ &
             (centerMaxIndex(d)-centerMinIndex(d))+1
     enddo

    ! Add coordinates
    call ESMF_GridAddCoord(grid, staggerloc=staggerloc, rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
       ESMF_CONTEXT, rcToReturn=rc)) return


    ! Get the min and max indices for this stagger
    ! Assuming 1 tile (because we're building the grid that way above)
     call ESMF_GridGet(grid,1,staggerloc, &
         minIndex=staggerMinIndex, maxIndex=staggerMaxIndex, &
         rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return


    ! Loop through dimensions setting coordinates
    do d=1,dimCount

       ! Get the location in the cell of this dimension in the stagger
       call ESMF_StaggerLocGet(staggerloc, d, loc, rc=localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       ! Compute width of corner index space
       hcornerIndexDiffR8=REAL(hcornerMaxIndex(d)-hcornerMinIndex(d),ESMF_KIND_R8)

       ! Loop through DEs setting coordinates
       do lDE=0,localDECount-1

          ! Get coordinate memory
          call ESMF_GridGetCoord(grid, localDE=lDE, staggerLoc=staggerloc, coordDim=d, &
               computationalLBound=clbnd, computationalUBound=cubnd, farrayPtr=coordPtr, rc=localrc)
           if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
               ESMF_CONTEXT, rcToReturn=rc)) return


          ! Set each coordinates for this dim
          do i=clbnd(1),cubnd(1)

             ! Compute [0.0,1.0] parametric position of this coord
             p=REAL(i-hcornerMinIndex(d),ESMF_KIND_R8)/hcornerIndexDiffR8

             ! If stagger is in the center of this dim, then compute p in
             ! the center
             if (loc .eq. 0) then
                p_plus1=REAL(i+1-hcornerMinIndex(d),ESMF_KIND_R8)/hcornerIndexDiffR8
                p=(p+p_plus1)/2.0_ESMF_KIND_R8
             endif

              ! Compute value of coord based on parametric position
             coordPtr(i)=minCornerCoord(d)*(1.0-p)+maxCornerCoord(d)*p
          enddo
       enddo
    enddo


    ! Return successfully
    if (present(rc)) rc = ESMF_SUCCESS
  end subroutine ESMF_GridFillStaggerCoordsUfrm