Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=ESMF_KIND_R8), | intent(in) | :: | x | |||
real(kind=ESMF_KIND_R8), | intent(in) | :: | y | |||
real(kind=ESMF_KIND_R8), | intent(in) | :: | z | |||
real(kind=ESMF_KIND_R8), | intent(out) | :: | lon | |||
real(kind=ESMF_KIND_R8), | intent(out) | :: | lat | |||
real(kind=ESMF_KIND_R8), | intent(out) | :: | r |
subroutine cartesian_to_spherical(x, y, z, lon, lat, r) real(ESMF_KIND_R8) , intent(IN) :: x, y, z real(ESMF_KIND_R8) , intent(OUT) :: lon, lat, r r = SQRT(x*x + y*y + z*z) if ( (abs(x) + abs(y)) < 1.E-10 ) then ! poles: lon = 0. else lon = ATAN2(y,x) ! range: [-pi,pi] endif #ifdef RIGHT_HAND lat = asin(z/r) #else lat = ACOS(z/r) - pi/2. #endif end subroutine cartesian_to_spherical