1 | /* code to convert between equitorial and galactic coordinates */
|
---|
2 |
|
---|
3 | #include <stdio.h>
|
---|
4 | #include <math.h>
|
---|
5 |
|
---|
6 | #include "P_.h"
|
---|
7 | #include "astro.h"
|
---|
8 |
|
---|
9 | static void galeq_aux P_((int sw, double x, double y, double *p, double *q));
|
---|
10 | static void galeq_init P_((void));
|
---|
11 |
|
---|
12 | #define EQtoGAL 1
|
---|
13 | #define GALtoEQ (-1)
|
---|
14 | #define SMALL (1e-20)
|
---|
15 |
|
---|
16 | static double an = degrad(32.93192); /* G lng of asc node on equator */
|
---|
17 | static double gpr = degrad(192.85948); /* RA of North Gal Pole, 2000 */
|
---|
18 | static double gpd = degrad(27.12825); /* Dec of " */
|
---|
19 | static double cgpd, sgpd; /* cos() and sin() of gpd */
|
---|
20 | static double mjd2000; /* mjd of 2000 */
|
---|
21 | static int before; /* whether these have been set yet */
|
---|
22 |
|
---|
23 | /* given ra and dec, each in radians, for the given epoch, find the
|
---|
24 | * corresponding galactic latitude, *lat, and longititude, *lng, also each in
|
---|
25 | * radians.
|
---|
26 | */
|
---|
27 | void
|
---|
28 | eq_gal (mjd, ra, dec, lat, lng)
|
---|
29 | double mjd, ra, dec;
|
---|
30 | double *lat, *lng;
|
---|
31 | {
|
---|
32 | galeq_init();
|
---|
33 | precess (mjd, mjd2000, &ra, &dec);
|
---|
34 | galeq_aux (EQtoGAL, ra, dec, lng, lat);
|
---|
35 | }
|
---|
36 |
|
---|
37 | /* given galactic latitude, lat, and longititude, lng, each in radians, find
|
---|
38 | * the corresponding equitorial ra and dec, also each in radians, at the
|
---|
39 | * given epoch.
|
---|
40 | */
|
---|
41 | void
|
---|
42 | gal_eq (mjd, lat, lng, ra, dec)
|
---|
43 | double mjd, lat, lng;
|
---|
44 | double *ra, *dec;
|
---|
45 | {
|
---|
46 | galeq_init();
|
---|
47 | galeq_aux (GALtoEQ, lng, lat, ra, dec);
|
---|
48 | precess (mjd2000, mjd, ra, dec);
|
---|
49 | }
|
---|
50 |
|
---|
51 | static void
|
---|
52 | galeq_aux (sw, x, y, p, q)
|
---|
53 | int sw; /* +1 for eq to gal, -1 for vv. */
|
---|
54 | double x, y; /* sw==1: x==ra, y==dec. sw==-1: x==lng, y==lat. */
|
---|
55 | double *p, *q; /* sw==1: p==lng, q==lat. sw==-1: p==ra, q==dec. */
|
---|
56 | {
|
---|
57 | double sy, cy, a, ca, sa, b, sq, c, d;
|
---|
58 |
|
---|
59 | cy = cos(y);
|
---|
60 | sy = sin(y);
|
---|
61 | a = x - an;
|
---|
62 | if (sw == EQtoGAL)
|
---|
63 | a = x - gpr;
|
---|
64 | ca = cos(a);
|
---|
65 | sa = sin(a);
|
---|
66 | b = sa;
|
---|
67 | if (sw == EQtoGAL)
|
---|
68 | b = ca;
|
---|
69 | sq = (cy*cgpd*b) + (sy*sgpd);
|
---|
70 | *q = asin (sq);
|
---|
71 |
|
---|
72 | if (sw == GALtoEQ) {
|
---|
73 | c = cy*ca;
|
---|
74 | d = (sy*cgpd) - (cy*sgpd*sa);
|
---|
75 | if (fabs(d) < SMALL)
|
---|
76 | d = SMALL;
|
---|
77 | *p = atan (c/d) + gpr;
|
---|
78 | } else {
|
---|
79 | c = sy - (sq*sgpd);
|
---|
80 | d = cy*sa*cgpd;
|
---|
81 | if (fabs(d) < SMALL)
|
---|
82 | d = SMALL;
|
---|
83 | *p = atan (c/d) + an;
|
---|
84 | }
|
---|
85 |
|
---|
86 | if (d < 0) *p += PI;
|
---|
87 | if (*p < 0) *p += 2*PI;
|
---|
88 | if (*p > 2*PI) *p -= 2*PI;
|
---|
89 | }
|
---|
90 |
|
---|
91 | /* set up the definitions */
|
---|
92 | static void
|
---|
93 | galeq_init()
|
---|
94 | {
|
---|
95 | if (!before) {
|
---|
96 | cgpd = cos (gpd);
|
---|
97 | sgpd = sin (gpd);
|
---|
98 | mjd2000 = J2000;
|
---|
99 | before = 1;
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | /* For RCS Only -- Do Not Edit */
|
---|
104 | static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: eq_gal.c,v $ $Date: 2001-10-22 12:08:27 $ $Revision: 1.2 $ $Name: not supported by cvs2svn $"};
|
---|