source: Sophya/trunk/SophyaExt/XephemAstroLib/eq_ecl.c@ 4010

Last change on this file since 4010 was 3654, checked in by cmv, 16 years ago

mise a niveau Xephem 3.7.4, cmv 16/07/2009

File size: 2.1 KB
Line 
1#include <stdio.h>
2#include <math.h>
3
4#include "astro.h"
5
6static 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 */
19void
20eq_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 */
31void
32ecl_eq (double mj, double lt, double lg, double *ra, double *dec)
33{
34 ecleq_aux (ECLtoEQ, mj, lg, lt, ra, dec);
35}
36
37static void
38ecleq_aux (
39int sw, /* +1 for eq to ecliptic, -1 for vv. */
40double mj,
41double x, double y, /* sw==1: x==ra, y==dec. sw==-1: x==lg, y==lt. */
42double *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 */
72static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: eq_ecl.c,v $ $Date: 2009-07-16 10:34:37 $ $Revision: 1.8 $ $Name: not supported by cvs2svn $"};
Note: See TracBrowser for help on using the repository browser.