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

Last change on this file since 3076 was 2818, checked in by cmv, 20 years ago

Update de Xephem 3.7 cmv 21/08/2005

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