| 1 | #include <stdio.h>
 | 
|---|
| 2 | #include <math.h>
 | 
|---|
| 3 | 
 | 
|---|
| 4 | #include "astro.h"
 | 
|---|
| 5 | 
 | 
|---|
| 6 | static void ecleq_aux (int sw, double mj, double x, double y,
 | 
|---|
| 7 |     double *p, double *q);
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #define EQtoECL 1
 | 
|---|
| 10 | #define ECLtoEQ (-1)
 | 
|---|
| 11 | 
 | 
|---|
| 12 | 
 | 
|---|
| 13 | /* given the modified Julian date, mj, and an equitorial ra and dec, each in
 | 
|---|
| 14 |  * radians, find the corresponding geocentric ecliptic latitude, *lt, and
 | 
|---|
| 15 |  * longititude, *lg, also each in radians.
 | 
|---|
| 16 |  * correction for the effect on the angle of the obliquity due to nutation is
 | 
|---|
| 17 |  * not included.
 | 
|---|
| 18 |  */
 | 
|---|
| 19 | void
 | 
|---|
| 20 | eq_ecl (double mj, double ra, double dec, double *lt, double *lg)
 | 
|---|
| 21 | {
 | 
|---|
| 22 |         ecleq_aux (EQtoECL, mj, ra, dec, lg, lt);
 | 
|---|
| 23 | }
 | 
|---|
| 24 | 
 | 
|---|
| 25 | /* given the modified Julian date, mj, and a geocentric ecliptic latitude,
 | 
|---|
| 26 |  * *lt, and longititude, *lg, each in radians, find the corresponding
 | 
|---|
| 27 |  * equitorial ra and dec, also each in radians.
 | 
|---|
| 28 |  * correction for the effect on the angle of the obliquity due to nutation is
 | 
|---|
| 29 |  * not included.
 | 
|---|
| 30 |  */
 | 
|---|
| 31 | void
 | 
|---|
| 32 | ecl_eq (double mj, double lt, double lg, double *ra, double *dec)
 | 
|---|
| 33 | {
 | 
|---|
| 34 |         ecleq_aux (ECLtoEQ, mj, lg, lt, ra, dec);
 | 
|---|
| 35 | }
 | 
|---|
| 36 | 
 | 
|---|
| 37 | static void
 | 
|---|
| 38 | ecleq_aux (
 | 
|---|
| 39 | int sw,                 /* +1 for eq to ecliptic, -1 for vv. */
 | 
|---|
| 40 | double mj,
 | 
|---|
| 41 | double x, double y,     /* sw==1: x==ra, y==dec.  sw==-1: x==lg, y==lt. */
 | 
|---|
| 42 | double *p, double *q)   /* sw==1: p==lg, q==lt. sw==-1: p==ra, q==dec. */
 | 
|---|
| 43 | {
 | 
|---|
| 44 |         static double lastmj = -10000;  /* last mj calculated */
 | 
|---|
| 45 |         static double seps, ceps;       /* sin and cos of mean obliquity */
 | 
|---|
| 46 |         double sx, cx, sy, cy, ty, sq;
 | 
|---|
| 47 | 
 | 
|---|
| 48 |         if (mj != lastmj) {
 | 
|---|
| 49 |             double eps;
 | 
|---|
| 50 |             obliquity (mj, &eps);               /* mean obliquity for date */
 | 
|---|
| 51 |             seps = sin(eps);
 | 
|---|
| 52 |             ceps = cos(eps);
 | 
|---|
| 53 |             lastmj = mj;
 | 
|---|
| 54 |         }
 | 
|---|
| 55 | 
 | 
|---|
| 56 |         sy = sin(y);
 | 
|---|
| 57 |         cy = cos(y);                            /* always non-negative */
 | 
|---|
| 58 |         if (fabs(cy)<1e-20) cy = 1e-20;         /* insure > 0 */
 | 
|---|
| 59 |         ty = sy/cy;
 | 
|---|
| 60 |         cx = cos(x);
 | 
|---|
| 61 |         sx = sin(x);
 | 
|---|
| 62 |         sq = (sy*ceps)-(cy*seps*sx*sw);
 | 
|---|
| 63 |         if (sq < -1) sq = -1;
 | 
|---|
| 64 |         if (sq >  1) sq =  1;
 | 
|---|
| 65 |         *q = asin(sq);
 | 
|---|
| 66 |         *p = atan(((sx*ceps)+(ty*seps*sw))/cx);
 | 
|---|
| 67 |         if (cx<0) *p += PI;             /* account for atan quad ambiguity */
 | 
|---|
| 68 |         range (p, 2*PI);
 | 
|---|
| 69 | }
 | 
|---|
| 70 | 
 | 
|---|
| 71 | /* For RCS Only -- Do Not Edit */
 | 
|---|
| 72 | static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: eq_ecl.c,v $ $Date: 2006-11-22 13:53:29 $ $Revision: 1.6 $ $Name: not supported by cvs2svn $"};
 | 
|---|