cart_to_latlon Subroutine

private subroutine cart_to_latlon(np, q, xs, ys)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: np
real(kind=ESMF_KIND_R8), intent(inout) :: q(3,np)
real(kind=ESMF_KIND_R8), intent(inout) :: xs(np)
real(kind=ESMF_KIND_R8), intent(inout) :: ys(np)

Called by

proc~~cart_to_latlon~~CalledByGraph proc~cart_to_latlon cart_to_latlon proc~cell_center2 cell_center2 proc~cell_center2->proc~cart_to_latlon proc~gnomonic_angl gnomonic_angl proc~gnomonic_angl->proc~cart_to_latlon proc~gnomonic_dist gnomonic_dist proc~gnomonic_dist->proc~cart_to_latlon proc~gnomonic_ed gnomonic_ed proc~gnomonic_ed->proc~cart_to_latlon proc~mirror_latlon mirror_latlon proc~gnomonic_ed->proc~mirror_latlon proc~mirror_latlon->proc~cart_to_latlon proc~esmf_utilcreatecscoords ESMF_UtilCreateCSCoords proc~esmf_utilcreatecscoords->proc~cell_center2 proc~gnomonic_grids gnomonic_grids proc~esmf_utilcreatecscoords->proc~gnomonic_grids proc~esmf_utilcreatecscoordspar ESMF_UtilCreateCSCoordsPar proc~esmf_utilcreatecscoordspar->proc~cell_center2 proc~esmf_utilcreatecscoordspar->proc~gnomonic_grids proc~gnomonic_grids->proc~gnomonic_angl proc~gnomonic_grids->proc~gnomonic_dist proc~gnomonic_grids->proc~gnomonic_ed proc~esmf_gridcreatecubedsphereireg ESMF_GridCreateCubedSphereIReg proc~esmf_gridcreatecubedsphereireg->proc~esmf_utilcreatecscoordspar proc~esmf_gridcreatecubedspherereg ESMF_GridCreateCubedSphereReg proc~esmf_gridcreatecubedspherereg->proc~esmf_utilcreatecscoordspar proc~esmf_meshcreatecubedsphere ESMF_MeshCreateCubedSphere proc~esmf_meshcreatecubedsphere->proc~esmf_utilcreatecscoords interface~esmf_gridcreatecubedsphere ESMF_GridCreateCubedSphere interface~esmf_gridcreatecubedsphere->proc~esmf_gridcreatecubedsphereireg interface~esmf_gridcreatecubedsphere->proc~esmf_gridcreatecubedspherereg proc~test_bilinear_regrid_csmesh test_bilinear_regrid_csmesh proc~test_bilinear_regrid_csmesh->proc~esmf_meshcreatecubedsphere proc~test_conserve_regrid_csmesh test_conserve_regrid_csmesh proc~test_conserve_regrid_csmesh->proc~esmf_meshcreatecubedsphere proc~test_nearest_regrid_csmesh test_nearest_regrid_csmesh proc~test_nearest_regrid_csmesh->proc~esmf_meshcreatecubedsphere proc~test_patch_regrid_csmesh test_patch_regrid_csmesh proc~test_patch_regrid_csmesh->proc~esmf_meshcreatecubedsphere program~esmf_meshex ESMF_MeshEx program~esmf_meshex->proc~esmf_meshcreatecubedsphere

Source Code

 subroutine cart_to_latlon(np, q, xs, ys)
! vector version of cart_to_latlon1
  integer, intent(in):: np
  real(ESMF_KIND_R8), intent(inout):: q(3,np)
  real(ESMF_KIND_R8), intent(inout):: xs(np), ys(np)
! local
  real(ESMF_KIND_R8), parameter:: esl=1.e-10
  real(ESMF_KIND_R8) :: p(3)
  real(ESMF_KIND_R8) :: dist, lat, lon
  integer i,k

  do i=1,np
     do k=1,3
        p(k) = q(k,i)
     enddo
     dist = sqrt(p(1)**2 + p(2)**2 + p(3)**2)
     do k=1,3
        p(k) = p(k) / dist
     enddo

     if ( (abs(p(1))+abs(p(2)))  < esl ) then
          lon = 0.
     else
          lon = atan2( p(2), p(1) )   ! range [-pi,pi]
     endif

     if ( lon < 0.) lon = 2.*pi + lon
     lat = asin(p(3))
     
     xs(i) = lon
     ys(i) = lat
! q Normalized:
     do k=1,3
        q(k,i) = p(k)
     enddo
  enddo

 end  subroutine cart_to_latlon