ESMFL_GridCoordGet Subroutine

public subroutine ESMFL_GridCoordGet(GRID, coord, name, location, units, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Grid), intent(inout) :: GRID
real, dimension(:,:), pointer :: coord
character(len=*), intent(in) :: name
type(ESMF_StaggerLoc) :: location
integer :: units
integer, optional :: rc

Calls

proc~~esmfl_gridcoordget~~CallsGraph proc~esmfl_gridcoordget ESMFL_GridCoordGet ESMF_GridGet ESMF_GridGet proc~esmfl_gridcoordget->ESMF_GridGet ESMF_GridGetCoord ESMF_GridGetCoord proc~esmfl_gridcoordget->ESMF_GridGetCoord interface~mapl_assert MAPL_Assert proc~esmfl_gridcoordget->interface~mapl_assert proc~mapl_gridget MAPL_GridGet proc~esmfl_gridcoordget->proc~mapl_gridget proc~mapl_return MAPL_Return proc~esmfl_gridcoordget->proc~mapl_return proc~mapl_verify MAPL_Verify proc~esmfl_gridcoordget->proc~mapl_verify proc~mapl_gridget->ESMF_GridGet proc~mapl_gridget->proc~mapl_return proc~mapl_gridget->proc~mapl_verify ESMF_AttributeGet ESMF_AttributeGet proc~mapl_gridget->ESMF_AttributeGet ESMF_DistGridGet ESMF_DistGridGet proc~mapl_gridget->ESMF_DistGridGet proc~mapl_distgridget MAPL_DistGridGet proc~mapl_gridget->proc~mapl_distgridget proc~mapl_getimsjms MAPL_GetImsJms proc~mapl_gridget->proc~mapl_getimsjms proc~mapl_gridhasde MAPL_GridHasDE proc~mapl_gridget->proc~mapl_gridhasde at at proc~mapl_return->at insert insert proc~mapl_return->insert proc~mapl_throw_exception MAPL_throw_exception proc~mapl_return->proc~mapl_throw_exception proc~mapl_verify->proc~mapl_throw_exception proc~mapl_distgridget->proc~mapl_verify proc~mapl_distgridget->ESMF_DistGridGet proc~mapl_getimsjms->interface~mapl_assert proc~mapl_getimsjms->proc~mapl_return proc~mapl_getimsjms->proc~mapl_verify interface~mapl_sort MAPL_Sort proc~mapl_getimsjms->interface~mapl_sort proc~mapl_gridhasde->ESMF_GridGet proc~mapl_gridhasde->proc~mapl_return proc~mapl_gridhasde->proc~mapl_verify proc~mapl_gridhasde->ESMF_DistGridGet ESMF_DELayoutGet ESMF_DELayoutGet proc~mapl_gridhasde->ESMF_DELayoutGet

Called by

proc~~esmfl_gridcoordget~~CalledByGraph proc~esmfl_gridcoordget ESMFL_GridCoordGet proc~mapl_genericinitialize MAPL_GenericInitialize proc~mapl_genericinitialize->proc~esmfl_gridcoordget

Source Code

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