xyz2latlon.F90 Source File


This file depends on

sourcefile~~xyz2latlon.f90~~EfferentGraph sourcefile~xyz2latlon.f90 xyz2latlon.F90 sourcefile~base_base.f90 Base_Base.F90 sourcefile~xyz2latlon.f90->sourcefile~base_base.f90 sourcefile~constants.f90 Constants.F90 sourcefile~xyz2latlon.f90->sourcefile~constants.f90 sourcefile~vectorbasis.f90 VectorBasis.F90 sourcefile~xyz2latlon.f90->sourcefile~vectorbasis.f90 sourcefile~base_base.f90->sourcefile~constants.f90 sourcefile~keywordenforcer.f90 KeywordEnforcer.F90 sourcefile~base_base.f90->sourcefile~keywordenforcer.f90 sourcefile~mapl_range.f90 MAPL_Range.F90 sourcefile~base_base.f90->sourcefile~mapl_range.f90 sourcefile~maplgrid.f90 MaplGrid.F90 sourcefile~base_base.f90->sourcefile~maplgrid.f90 sourcefile~internalconstants.f90 InternalConstants.F90 sourcefile~constants.f90->sourcefile~internalconstants.f90 sourcefile~mathconstants.f90 MathConstants.F90 sourcefile~constants.f90->sourcefile~mathconstants.f90 sourcefile~physicalconstants.f90 PhysicalConstants.F90 sourcefile~constants.f90->sourcefile~physicalconstants.f90 sourcefile~errorhandling.f90 ErrorHandling.F90 sourcefile~vectorbasis.f90->sourcefile~errorhandling.f90 sourcefile~fieldblas.f90 FieldBLAS.F90 sourcefile~vectorbasis.f90->sourcefile~fieldblas.f90 sourcefile~fieldpointerutilities.f90 FieldPointerUtilities.F90 sourcefile~vectorbasis.f90->sourcefile~fieldpointerutilities.f90 sourcefile~mapl_throw.f90 MAPL_Throw.F90 sourcefile~errorhandling.f90->sourcefile~mapl_throw.f90 sourcefile~fieldblas.f90->sourcefile~fieldpointerutilities.f90 sourcefile~mapl_exceptionhandling.f90 MAPL_ExceptionHandling.F90 sourcefile~fieldblas.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~fieldpointerutilities.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~mapl_range.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~maplgrid.f90->sourcefile~constants.f90 sourcefile~maplgrid.f90->sourcefile~errorhandling.f90 sourcefile~maplgrid.f90->sourcefile~keywordenforcer.f90 sourcefile~mapl_sort.f90 MAPL_Sort.F90 sourcefile~maplgrid.f90->sourcefile~mapl_sort.f90 sourcefile~pflogger_stub.f90 pflogger_stub.F90 sourcefile~maplgrid.f90->sourcefile~pflogger_stub.f90 sourcefile~physicalconstants.f90->sourcefile~mathconstants.f90 sourcefile~mapl_exceptionhandling.f90->sourcefile~errorhandling.f90 sourcefile~mapl_exceptionhandling.f90->sourcefile~mapl_throw.f90 sourcefile~mapl_sort.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~pfl_keywordenforcer.f90 PFL_KeywordEnforcer.F90 sourcefile~pflogger_stub.f90->sourcefile~pfl_keywordenforcer.f90 sourcefile~wraparray.f90 WrapArray.F90 sourcefile~pflogger_stub.f90->sourcefile~wraparray.f90

Source Code

#include "MAPL_ErrLog.h"

submodule (mapl3g_VectorBasis) xyz2latlon_smod
   use mapl_base, only: MAPL_GridGetCorners
contains

   pure module function xyz2latlon(xyz_coord) result(sph_coord)
      use MAPL_Constants, only: PI => MAPL_PI_R8
      real(kind=ESMF_KIND_R8), intent(in):: xyz_coord(3)
      real(kind=ESMF_KIND_R8) :: sph_coord(2)
      real(kind=ESMF_KIND_R8), parameter:: esl=1.e-10
      real(kind=ESMF_KIND_R8):: p(3)
      real(kind=ESMF_KIND_R8):: dist, lat, lon
      integer k

      p = xyz_coord
      dist =sqrt( dot_product(p,p))
      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))

      sph_coord(1) = lon
      sph_coord(2) = lat

   end function xyz2latlon

end submodule xyz2latlon_smod