PROGRAM cartesian
! This program takes the input Latitude and Longitude of a point
!  on the Earth surface and returns x-, y-, z- Cartesian Coordinates
IMPLICIT NONE
REAL(KIND=8), PARAMETER :: pi=3.141592653589793
REAL(KIND=8), PARAMETER :: Rad = 6371.0
REAL(KIND=8) :: Lat, Lon
REAL(KIND=8) :: x, y, z
REAL(KIND=8) :: rho, phi, theta, dtr

!Define Lat and Lon
Lat = 30.0
Lon = 90.0

dtr = pi/180.0   !conversion from degrees to radians
rho = Rad
theta = Lon*dtr
phi = (90.0 - Lat)*dtr

x = rho*SIN(phi)*COS(theta)
y = rho*SIN(phi)*SIN(theta)
z = rho*COS(phi)

write(*,*) "Lat =", Lat
write(*,*) "Lon =", Lon 
write(*,*) "x =", x
write(*,*) "y =", y
write(*,*) "z =", z


END PROGRAM cartesian
