

























































































































 


































































































































































 






















































































































































































 






















































 










 








































































































































































































































 










                                
                                

                                
                                

                                
                                

                                





































module conversion
  implicit none
  private
  
  public make_cylindrical2cartesian
  public make_spherical2cartesian
  public make_cartesian2spherical
  
contains
  
  subroutine make_cylindrical2cartesian (xx, tt)
    REAL*8, intent(in)  :: xx(3)
    REAL*8, intent(out) :: tt(3,3)
    REAL*8, parameter :: eps = 1.0d-20
    REAL*8 :: x,y,z
    REAL*8 :: rho
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    x = xx(1)
    y = xx(2)
    z = xx(3)
    
    rho = sqrt(x**2+y**2)
    
    tt(1,1) = x/(rho+eps)
    tt(2,1) = y/(rho+eps)
    tt(3,1) = 0
    tt(1,2) = -y/(rho**2+eps)
    tt(2,2) = x/(rho**2+eps)
    tt(3,2) = 0
    tt(1,3) = 0
    tt(2,3) = 0
    tt(3,3) = 1
    
  end subroutine make_cylindrical2cartesian
  
  subroutine make_spherical2cartesian (xx, tt)
    REAL*8, intent(in)  :: xx(3)
    REAL*8, intent(out) :: tt(3,3)
    REAL*8, parameter :: eps = 1.0d-20
    REAL*8 :: x,y,z
    REAL*8 :: rho,r
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    x = xx(1)
    y = xx(2)
    z = xx(3)
    
    rho = sqrt(x**2+y**2)
    r = sqrt(x**2+y**2+z**2)
    
    tt(1,1) =  x/(r+eps)
    tt(2,1) =  y/(r+eps)
    tt(3,1) =  z/(r+eps)
    tt(1,2) =  x*z/(r**2*rho+eps)
    tt(2,2) =  y*z/(r**2*rho+eps)
    tt(3,2) = -rho**2/(r**2*rho+eps)
    tt(1,3) = -y/(rho**2+eps)
    tt(2,3) =  x/(rho**2+eps)
    tt(3,3) =  0
    
  end subroutine make_spherical2cartesian
  
  subroutine make_cartesian2spherical (xx, tt)
    REAL*8, intent(in)  :: xx(3)
    REAL*8, intent(out) :: tt(3,3)
    REAL*8, parameter :: eps = 1.0d-20
    REAL*8 :: x,y,z
    REAL*8 :: rho,r
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    x = xx(1)
    y = xx(2)
    z = xx(3)
    
    rho = sqrt(x**2+y**2)
    r = sqrt(x**2+y**2+z**2)
    
    tt(1,1) =  x/(r+eps)
    tt(2,1) =  x * z/(rho+eps)
    tt(3,1) = -y
    tt(1,2) =  y/(r+eps)
    tt(2,2) =  y * z/(rho+eps)
    tt(3,2) =  x
    tt(1,3) =  z/(r+eps)
    tt(2,3) = -rho
    tt(3,3) =  0
    
  end subroutine make_cartesian2spherical
  
end module conversion
