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