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

Last change on this file since 1465 was 1457, checked in by cmv, 24 years ago

import de la partie libastro de Xephem cmv+rz 10/4/2001

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