source: Sophya/trunk/SophyaExt/XephemAstroLib/eq_gal.c@ 1457

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

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

File size: 2.5 KB
Line 
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
9static void galeq_aux P_((int sw, double x, double y, double *p, double *q));
10static void galeq_init P_((void));
11
12#define EQtoGAL 1
13#define GALtoEQ (-1)
14#define SMALL (1e-20)
15
16static double an = degrad(32.93192); /* G lng of asc node on equator */
17static double gpr = degrad(192.85948); /* RA of North Gal Pole, 2000 */
18static double gpd = degrad(27.12825); /* Dec of " */
19static double cgpd, sgpd; /* cos() and sin() of gpd */
20static double mjd2000; /* mjd of 2000 */
21static 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 */
27void
28eq_gal (mjd, ra, dec, lat, lng)
29double mjd, ra, dec;
30double *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 */
41void
42gal_eq (mjd, lat, lng, ra, dec)
43double mjd, lat, lng;
44double *ra, *dec;
45{
46 galeq_init();
47 galeq_aux (GALtoEQ, lng, lat, ra, dec);
48 precess (mjd2000, mjd, ra, dec);
49}
50
51static void
52galeq_aux (sw, x, y, p, q)
53int sw; /* +1 for eq to gal, -1 for vv. */
54double x, y; /* sw==1: x==ra, y==dec. sw==-1: x==lng, y==lat. */
55double *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 */
92static void
93galeq_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 */
104static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: eq_gal.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.