spherical_from_cartesian Subroutine

public pure subroutine spherical_from_cartesian(x, y, z, xo, yo, zo, r, theta, phi)

Uses

    • constants
  • proc~~spherical_from_cartesian~~UsesGraph proc~spherical_from_cartesian spherical_from_cartesian constants constants proc~spherical_from_cartesian->constants

Compute the spherical polar coordinates of a point relative to a point , starting from the Cartesian coordinates of the points and

FT 14.01.2021


Arguments

Type IntentOptional Attributes Name
double precision, intent(in) :: x

coordinate of the point

double precision, intent(in) :: y

coordinate of the point

double precision, intent(in) :: z

coordinate of the point

double precision, intent(in) :: xo

coordinate of the point

double precision, intent(in) :: yo

coordinate of the point

double precision, intent(in) :: zo

coordinate of the point

double precision, intent(out) :: r

coordinate of the point , relative to

double precision, intent(out) :: theta

coordinate (colatitude) of the point , relative to

double precision, intent(out) :: phi

coordinate (azimuth) of the point , relative to


Called by

proc~~spherical_from_cartesian~~CalledByGraph proc~spherical_from_cartesian spherical_from_cartesian none~place_and_print_ghost_particles place_and_print_ghost_particles none~place_and_print_ghost_particles->proc~spherical_from_cartesian proc~construct_particles_std construct_particles_std proc~construct_particles_std->proc~spherical_from_cartesian interface~perform_apm perform_apm proc~construct_particles_std->interface~perform_apm proc~interpolate_mass_density interpolate_mass_density proc~interpolate_mass_density->proc~spherical_from_cartesian proc~perform_apm perform_apm proc~perform_apm->proc~spherical_from_cartesian proc~perform_apm->none~place_and_print_ghost_particles interface~construct_particles_std construct_particles_std interface~construct_particles_std->proc~construct_particles_std interface~interpolate_mass_density interpolate_mass_density interface~interpolate_mass_density->proc~interpolate_mass_density interface~perform_apm->proc~perform_apm interface~particles particles interface~particles->interface~construct_particles_std program~convergence_test convergence_test program~convergence_test->interface~particles program~sphincs_id sphincs_id program~sphincs_id->interface~particles

Contents


Variables

Type Visibility Attributes Name Initial
double precision, public :: xd
double precision, public :: yd
double precision, public :: zd

Source Code

  PURE SUBROUTINE spherical_from_cartesian( x, y, z, xo, yo, zo, r, theta, phi )

    !****************************************************************
    !
    !# Compute the spherical polar coordinates of a point \(p\)
    !  relative to a point \(O\), starting from the Cartesian
    !  coordinates of the points \(p\) and \(O\)
    !
    !  FT 14.01.2021
    !
    !****************************************************************

    USE constants, ONLY: pi

    IMPLICIT NONE

    DOUBLE PRECISION, INTENT(IN):: x
    !! \(x\) coordinate of the point \(p\)
    DOUBLE PRECISION, INTENT(IN):: y
    !! \(y\) coordinate of the point \(p\)
    DOUBLE PRECISION, INTENT(IN):: z
    !! \(z\) coordinate of the point \(p\)

    DOUBLE PRECISION, INTENT(IN):: xo
    !! \(x\) coordinate of the point \(O\)
    DOUBLE PRECISION, INTENT(IN):: yo
    !! \(y\) coordinate of the point \(O\)
    DOUBLE PRECISION, INTENT(IN):: zo
    !! \(z\) coordinate of the point \(O\)

    DOUBLE PRECISION, INTENT(OUT):: r
    !! \(r\) coordinate of the point \(p\), relative to \(O\)
    DOUBLE PRECISION, INTENT(OUT):: theta
    !! \(\theta\) coordinate (colatitude) of the point \(p\), relative to \(O\)
    DOUBLE PRECISION, INTENT(OUT):: phi
    !! \(\phi\) coordinate (azimuth) of the point \(p\), relative to \(O\)

    DOUBLE PRECISION:: xd, yd, zd

    xd= x - xo
    yd= y - yo
    zd= z - zo

    IF( xd > zero )THEN

      phi= ATAN( yd/xd )

    ELSEIF( xd < zero )THEN

      phi= ATAN( yd/xd ) + pi

    ELSE

      phi= pi/two

    ENDIF

    DO WHILE(phi < zero)

      phi= phi + two*pi

    ENDDO

    r= SQRT( xd**2 + yd**2 + zd**2 )

    theta= ACOS( zd/r )

  END SUBROUTINE spherical_from_cartesian