;Edward Burin des Roziers
;ASEN5050

;function MOON.PRO calculates the Moon's position.

function moon, t

;Earth Constants
mu_E = 3.986d5                                ;km^3/sec^2
Re = 6378.14d                                ;km

;Moon Constants
a_M = 60.27d * Re                        ;km
e_M = .0549d
inc_M = 5.145396d / !radeg                ;rad
Omega_M = 0.0                                ;rad
w_M = 0.0                                ;rad
tp_M = 0.0                                ;sec
p_M = a_M*(1-e_M^2)                        ;km
n_M = sqrt(mu_E/a_M^3)

;Function PMA2 used to iterate to find eccentric anomaly
ma_M = (tp_M+t)*n_M
maae_M = [ma_m,a_M,e_M]
eata_M = pma2(maae_M)
ta_M = eata_M[1]                        ;rad

;Calculate Moon position and velocity
peiOmegawnu_M = [p_M,e_M,inc_M,Omega_M,w_M,ta_M]
posvel_M = k2c(peiOmegawnu_M)
posijk_M = posvel_M[0:2]
velijk_M = posvel_M[3:5]

return, posvel_M

end