| [1457] | 1 | #include <stdio.h> | 
|---|
|  | 2 | #include <math.h> | 
|---|
|  | 3 |  | 
|---|
|  | 4 | #include "astro.h" | 
|---|
|  | 5 |  | 
|---|
| [2551] | 6 | static void ecleq_aux (int sw, double mj, double x, double y, | 
|---|
|  | 7 | double *p, double *q); | 
|---|
| [1457] | 8 |  | 
|---|
|  | 9 | #define EQtoECL 1 | 
|---|
|  | 10 | #define ECLtoEQ (-1) | 
|---|
|  | 11 |  | 
|---|
|  | 12 |  | 
|---|
| [2551] | 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. | 
|---|
| [1457] | 16 | * correction for the effect on the angle of the obliquity due to nutation is | 
|---|
|  | 17 | * not included. | 
|---|
|  | 18 | */ | 
|---|
|  | 19 | void | 
|---|
| [2551] | 20 | eq_ecl (double mj, double ra, double dec, double *lt, double *lg) | 
|---|
| [1457] | 21 | { | 
|---|
| [2551] | 22 | ecleq_aux (EQtoECL, mj, ra, dec, lg, lt); | 
|---|
| [1457] | 23 | } | 
|---|
|  | 24 |  | 
|---|
| [2551] | 25 | /* given the modified Julian date, mj, and a geocentric ecliptic latitude, | 
|---|
|  | 26 | * *lt, and longititude, *lg, each in radians, find the corresponding | 
|---|
| [1457] | 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 | 
|---|
| [2551] | 32 | ecl_eq (double mj, double lt, double lg, double *ra, double *dec) | 
|---|
| [1457] | 33 | { | 
|---|
| [2551] | 34 | ecleq_aux (ECLtoEQ, mj, lg, lt, ra, dec); | 
|---|
| [1457] | 35 | } | 
|---|
|  | 36 |  | 
|---|
|  | 37 | static void | 
|---|
| [2551] | 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. */ | 
|---|
| [1457] | 43 | { | 
|---|
| [2551] | 44 | static double lastmj = -10000;  /* last mj calculated */ | 
|---|
| [1457] | 45 | static double seps, ceps;       /* sin and cos of mean obliquity */ | 
|---|
| [1719] | 46 | double sx, cx, sy, cy, ty, sq; | 
|---|
| [1457] | 47 |  | 
|---|
| [2551] | 48 | if (mj != lastmj) { | 
|---|
| [1457] | 49 | double eps; | 
|---|
| [2551] | 50 | obliquity (mj, &eps);               /* mean obliquity for date */ | 
|---|
| [1457] | 51 | seps = sin(eps); | 
|---|
|  | 52 | ceps = cos(eps); | 
|---|
| [2551] | 53 | lastmj = mj; | 
|---|
| [1457] | 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); | 
|---|
| [1719] | 62 | sq = (sy*ceps)-(cy*seps*sx*sw); | 
|---|
|  | 63 | if (sq < -1) sq = -1; | 
|---|
|  | 64 | if (sq >  1) sq =  1; | 
|---|
|  | 65 | *q = asin(sq); | 
|---|
| [1457] | 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 */ | 
|---|
| [2818] | 72 | static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: eq_ecl.c,v $ $Date: 2005-08-21 10:02:37 $ $Revision: 1.5 $ $Name: not supported by cvs2svn $"}; | 
|---|