MAPL_GridGetLatLons Subroutine

subroutine MAPL_GridGetLatLons(grid, lons, lats)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Grid) :: grid
real, pointer :: lons(:)
real, pointer :: lats(:)

Calls

proc~~mapl_gridgetlatlons~~CallsGraph proc~mapl_gridgetlatlons MAPL_GridGetLatLons ESMF_GridGet ESMF_GridGet proc~mapl_gridgetlatlons->ESMF_GridGet ESMF_GridGetCoord ESMF_GridGetCoord proc~mapl_gridgetlatlons->ESMF_GridGetCoord esmf_arraygetdata esmf_arraygetdata proc~mapl_gridgetlatlons->esmf_arraygetdata interface~arraygather ArrayGather proc~mapl_gridgetlatlons->interface~arraygather mapl_verify mapl_verify proc~mapl_gridgetlatlons->mapl_verify

Called by

proc~~mapl_gridgetlatlons~~CalledByGraph proc~mapl_gridgetlatlons MAPL_GridGetLatLons proc~mygridcreate_ MyGridCreate_ proc~mygridcreate_->proc~mapl_gridgetlatlons proc~test_main test_main proc~test_main->proc~mygridcreate_ program~utcfio utCFIO program~utcfio->proc~test_main

Source Code

  subroutine MAPL_GridGetLatLons ( grid, lons, lats )

    implicit NONE
    type(ESMF_Grid) :: grid

    real, pointer   :: lons(:), lats(:)

!                     ---

    type(ESMF_Array)       :: eARRAY(2)

    real(KIND=8), pointer  :: R8D2(:,:)
    real, pointer          :: lons2d(:,:), lats2d(:,:)
    real, pointer          :: LONSLocal(:,:), LATSlocal(:,:)
    integer                :: IM_WORLD, JM_WORLD, dims(3)

!                          ----

!      Get world dimensions
!      --------------------
       call ESMF_GridGet ( grid, horzRelloc=ESMF_CELL_CENTER, &
                           vertRelLoc=ESMF_CELL_CENTER, &
                           globalCellCountPerDim=DIMS, RC=STATUS)
       _VERIFY(STATUS)

       IM_WORLD = dims(1)
       JM_WORLD = dims(2)

!      Allocate memory for output if necessary
!      ---------------------------------------
       if ( .not. associated(lons) ) then
            allocate(lons(IM_WORLD), stat=STATUS)
       else
            if(size(LONS,1) /= IM_WORLD) STATUS = 1
       end if
       _VERIFY(status)
       if ( .not. associated(lats) ) then
            allocate(lats(JM_WORLD), stat=STATUS)
       else
            if(size(LATS,1) /= JM_WORLD) STATUS = 1
       end if
       _VERIFY(status)

!      Retrieve the ESMF array with coordinates 
!      ----------------------------------------
       call ESMF_GridGetCoord ( grid, horzRelLoc =ESMF_CELL_CENTER, &
                                centerCoord=eARRAY, RC=STATUS ) 
       _VERIFY(STATUS) 

!      Local work space
!      ----------------
       allocate(LONS2d(IM_WORLD,JM_WORLD), LATS2d(IM_WORLD,JM_WORLD), &
                STAT=status)             
       _VERIFY(status)

!      Get the local longitudes and gather them into a global array
!      ------------------------------------------------------------
       call ESMF_ArrayGetData(EARRAY(1), R8D2, RC=STATUS)
       _VERIFY(STATUS)

       allocate(LONSLOCAL(size(R8D2,1),size(R8D2,2)), STAT=status)             
       _VERIFY(status)

       LONSLOCAL = R8D2*(180/MAPL_PI)

       call ArrayGather(LONSLOCAL, LONS2D, GRID, RC=STATUS)

!      Get the local longitudes and gather them into a global array
!      ------------------------------------------------------------
       call ESMF_ArrayGetData(eARRAY(2), R8D2, RC=STATUS)
       _VERIFY(STATUS)

       allocate(LATSLOCAL(size(R8D2,1),size(R8D2,2)), STAT=status)             
       _VERIFY(status)

       LATSlocal = R8D2*(180/MAPL_PI)

       call ArrayGather(LATSLOCAL, LATS2D, GRID, RC=STATUS)
       _VERIFY(STATUS)

!      Return 1D arrays
!      ----------------
       LONS = LONS2D(:,1)
       LATS = LATS2D(1,:)

       DEALLOCATE(LONSLOCAL, LATSLOCAL, LONS2d, LATS2d )
        
     end subroutine MAPL_GridGetLatLons