/* Obliquity of the ecliptic at Julian date J
 *
 * IAU Coefficients are from:
 * J. H. Lieske, T. Lederle, W. Fricke, and B. Morando,
 * "Expressions for the Precession Quantities Based upon the IAU
 * (1976) System of Astronomical Constants,"  Astronomy and Astrophysics
 * 58, 1-16 (1977).
 *
 * Before or after 200 years from J2000, the formula used is from:
 * J. Laskar, "Secular terms of classical planetary theories
 * using the results of general theory," Astronomy and Astrophysics
 * 157, 59070 (1986).
 *
 *  See precess.c and page B18 of the Astronomical Almanac.
 * 
 */

#include "prec.h"
/* The results of the program are returned in these
 * global variables:
 */
DOUBLE jdeps = -1.0; /* Date for which obliquity was last computed */
DOUBLE eps = 0.0; /* The computed obliquity in radians */
DOUBLE coseps = 0.0; /* Cosine of the obliquity */
DOUBLE sineps = 0.0; /* Sine of the obliquity */
extern DOUBLE eps, coseps, sineps, STR, J1900;
DOUBLE SIN(), COS(), FABS();

void epsiln(J)
DOUBLE J; /* Julian date input */
{
DOUBLE T;

if( J == jdeps )
	return;

#if 0
T = (J - 2451545.0)/36525.0;

/* This expansion is from the AA.
 * Note the official 1976 IAU number is 23d 26' 21.448", but
 * the JPL numerical integration found 21.4119".
 */
if( FABS(T) < ((DOUBLE )2.0) )
	eps = (((1.813e-3*T - 5.9e-4)*T - 46.8150)*T + 84381.448)*STR;
#endif
#if 1
T = (J - J1900)/36525.0;
if( FABS(T) < ((DOUBLE )2.0) )
	eps = (((1.811e-3*T - 5.90e-4)*T - 46.845)*T + 84428.2584)*STR;
#endif
/* This expansion is from Laskar, cited above.
 * Bretagnon and Simon say, in Planetary Programs and Tables, that it
 * is accurate to 0.1" over a span of 6000 years. Laskar estimates the
 * precision to be 0.01" after 1000 years and a few seconds of arc
 * after 10000 years.
 */
else
	{
	T /= 10.0;
	eps = ((((((((( 2.45e-10*T + 5.79e-9)*T + 2.787e-7)*T
        + 7.12e-7)*T - 3.905e-5)*T - 2.4967e-3)*T
	- 5.138e-3)*T + 1.99925)*T - 0.0155)*T - 468.093)*T
	+ 84381.448;
	eps *= STR;
	}

coseps = COS( eps );
sineps = SIN( eps );
jdeps = J;
}
