subroutine ESMFL_GridCoordGet(GRID, coord, name, Location, Units, rc)
!ARGUMENTS:
type(ESMF_Grid), intent(INout ) :: GRID
real, dimension(:,:), pointer :: coord
character (len=*) , intent(IN) :: name
type(ESMF_StaggerLoc) :: location
integer :: units
integer, optional :: rc
!EOP
! local variables
integer :: rank
type(ESMF_CoordSys_Flag) :: crdSys
type(ESMF_TypeKind_Flag) :: tk
integer :: counts(ESMF_MAXDIM)
integer :: crdOrder
real(ESMF_KIND_R4), pointer :: r4d2(:,:)
real(ESMF_KIND_R8), pointer :: r8d2(:,:)
real(ESMF_KIND_R8) :: conv2rad
integer :: STATUS
integer :: i
integer :: j
!ALT integer :: i1, in, j1, jn
integer :: coordDimCount(ESMF_MAXDIM)
character(len=ESMF_MAXSTR):: gridname
_UNUSED_DUMMY(Units)
call ESMF_GridGet(grid, coordSys=crdSys, coordTypeKind=tk, &
dimCount=rank, coordDimCount=coordDimCount, rc=status)
_VERIFY(STATUS)
if (name == "Longitude") then
crdOrder = 1
else if (name == "Latitude") then
crdOrder = 2
else
STATUS=ESMF_FAILURE
_VERIFY(STATUS)
endif
call ESMF_GridGet(grid, name=gridname, rc=status)
_VERIFY(STATUS)
if (gridname(1:10) == 'tile_grid_') then
call MAPL_GridGet(GRID, localCellCountPerDim=counts, rc=status)
_VERIFY(STATUS)
allocate(coord(counts(1), counts(2)), STAT=status)
_VERIFY(STATUS)
coord = 0.0 ! initialize just in case
!ALT call MAPL_GRID_INTERIOR(GRID,I1,IN,J1,JN)
do I=1, counts(1)
do J=1, counts(2)
if (crdOrder == 1) then
coord(i,j) = i !ALT + I1 - 1
else
coord(i,j) = j !ALT + J1 - 1
end if
end do
end do
coord = coord * (MAPL_PI_R8 / 180.d+0)
_RETURN(ESMF_SUCCESS)
end if
if (crdSys == ESMF_COORDSYS_SPH_DEG) then
conv2rad = MAPL_PI_R8 / 180._ESMF_KIND_R8
else if (crdSys == ESMF_COORDSYS_SPH_RAD) then
conv2rad = 1._ESMF_KIND_R8
else
_FAIL('Unsupported coordinate system: ESMF_COORDSYS_CART')
end if
if (tk == ESMF_TYPEKIND_R4) then
if (coordDimCount(crdOrder)==2) then
call ESMF_GridGetCoord(grid, localDE=0, coordDim=crdOrder, &
staggerloc=location, &
computationalCount=COUNTS, &
farrayPtr=R4D2, rc=status)
_VERIFY(STATUS)
allocate(coord(counts(1), counts(2)), STAT=status)
_VERIFY(STATUS)
coord = conv2rad * R4D2
else
_RETURN(ESMF_FAILURE)
endif
else if (tk == ESMF_TYPEKIND_R8) then
if (coordDimCount(crdOrder)==2) then
call ESMF_GridGetCoord(grid, localDE=0, coordDim=crdOrder, &
staggerloc=location, &
computationalCount=COUNTS, &
farrayPtr=R8D2, rc=status)
_VERIFY(STATUS)
allocate(coord(counts(1), counts(2)), STAT=status)
_VERIFY(STATUS)
coord = conv2rad * R8D2
else
_RETURN(ESMF_FAILURE)
endif
else
_RETURN(ESMF_FAILURE)
endif
_RETURN(ESMF_SUCCESS)
end subroutine ESMFL_GridCoordGet