source: Sophya/trunk/SophyaExt/XephemAstroLib/precess.c@ 1681

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

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

File size: 4.4 KB
Line 
1#include <stdio.h>
2#include <math.h>
3
4#include "P_.h"
5#include "astro.h"
6
7static void precess_hiprec P_((double mjd1, double mjd2, double *ra,
8 double *dec));
9
10
11#define DCOS(x) cos(degrad(x))
12#define DSIN(x) sin(degrad(x))
13#define DASIN(x) raddeg(asin(x))
14#define DATAN2(y,x) raddeg(atan2((y),(x)))
15
16/* corrects ra and dec, both in radians, for precession from epoch 1 to epoch 2.
17 * the epochs are given by their modified JDs, mjd1 and mjd2, respectively.
18 * N.B. ra and dec are modifed IN PLACE.
19 */
20void
21precess (mjd1, mjd2, ra, dec)
22double mjd1, mjd2; /* initial and final epoch modified JDs */
23double *ra, *dec; /* ra/dec for mjd1 in, for mjd2 out */
24{
25 precess_hiprec (mjd1, mjd2, ra, dec);
26}
27
28/*
29 * Copyright (c) 1990 by Craig Counterman. All rights reserved.
30 *
31 * This software may be redistributed freely, not sold.
32 * This copyright notice and disclaimer of warranty must remain
33 * unchanged.
34 *
35 * No representation is made about the suitability of this
36 * software for any purpose. It is provided "as is" without express or
37 * implied warranty, to the extent permitted by applicable law.
38 *
39 * Rigorous precession. From Astronomical Ephemeris 1989, p. B18
40 *
41 * 96-06-20 Hayo Hase <hase@wettzell.ifag.de>: theta_a corrected
42 */
43static void
44precess_hiprec (mjd1, mjd2, ra, dec)
45double mjd1, mjd2; /* initial and final epoch modified JDs */
46double *ra, *dec; /* ra/dec for mjd1 in, for mjd2 out */
47{
48 static double last_mjd1 = -213.432, last_from;
49 static double last_mjd2 = -213.432, last_to;
50 double zeta_A, z_A, theta_A;
51 double T;
52 double A, B, C;
53 double alpha, delta;
54 double alpha_in, delta_in;
55 double from_equinox, to_equinox;
56 double alpha2000, delta2000;
57
58 /* convert mjds to years;
59 * avoid the remarkably expensive calls to mjd_year()
60 */
61 if (last_mjd1 == mjd1)
62 from_equinox = last_from;
63 else {
64 mjd_year (mjd1, &from_equinox);
65 last_mjd1 = mjd1;
66 last_from = from_equinox;
67 }
68 if (last_mjd2 == mjd2)
69 to_equinox = last_to;
70 else {
71 mjd_year (mjd2, &to_equinox);
72 last_mjd2 = mjd2;
73 last_to = to_equinox;
74 }
75
76 /* convert coords in rads to degs */
77 alpha_in = raddeg(*ra);
78 delta_in = raddeg(*dec);
79
80 /* precession progresses about 1 arc second in .047 years */
81 /* From from_equinox to 2000.0 */
82 if (fabs (from_equinox-2000.0) > .02) {
83 T = (from_equinox - 2000.0)/100.0;
84 zeta_A = 0.6406161* T + 0.0000839* T*T + 0.0000050* T*T*T;
85 z_A = 0.6406161* T + 0.0003041* T*T + 0.0000051* T*T*T;
86 theta_A = 0.5567530* T - 0.0001185* T*T - 0.0000116* T*T*T;
87
88 A = DSIN(alpha_in - z_A) * DCOS(delta_in);
89 B = DCOS(alpha_in - z_A) * DCOS(theta_A) * DCOS(delta_in)
90 + DSIN(theta_A) * DSIN(delta_in);
91 C = -DCOS(alpha_in - z_A) * DSIN(theta_A) * DCOS(delta_in)
92 + DCOS(theta_A) * DSIN(delta_in);
93
94 alpha2000 = DATAN2(A,B) - zeta_A;
95 range (&alpha2000, 360.0);
96 delta2000 = DASIN(C);
97 } else {
98 /* should get the same answer, but this could improve accruacy */
99 alpha2000 = alpha_in;
100 delta2000 = delta_in;
101 };
102
103
104 /* From 2000.0 to to_equinox */
105 if (fabs (to_equinox - 2000.0) > .02) {
106 T = (to_equinox - 2000.0)/100.0;
107 zeta_A = 0.6406161* T + 0.0000839* T*T + 0.0000050* T*T*T;
108 z_A = 0.6406161* T + 0.0003041* T*T + 0.0000051* T*T*T;
109 theta_A = 0.5567530* T - 0.0001185* T*T - 0.0000116* T*T*T;
110
111 A = DSIN(alpha2000 + zeta_A) * DCOS(delta2000);
112 B = DCOS(alpha2000 + zeta_A) * DCOS(theta_A) * DCOS(delta2000)
113 - DSIN(theta_A) * DSIN(delta2000);
114 C = DCOS(alpha2000 + zeta_A) * DSIN(theta_A) * DCOS(delta2000)
115 + DCOS(theta_A) * DSIN(delta2000);
116
117 alpha = DATAN2(A,B) + z_A;
118 range(&alpha, 360.0);
119 delta = DASIN(C);
120 } else {
121 /* should get the same answer, but this could improve accruacy */
122 alpha = alpha2000;
123 delta = delta2000;
124 };
125
126 *ra = degrad(alpha);
127 *dec = degrad(delta);
128}
129
130#if 0
131static void
132precess_fast (mjd1, mjd2, ra, dec)
133double mjd1, mjd2; /* initial and final epoch modified JDs */
134double *ra, *dec; /* ra/dec for mjd1 in, for mjd2 out */
135{
136#define N degrad (20.0468/3600.0)
137#define M hrrad (3.07234/3600.0)
138 double nyrs;
139
140 nyrs = (mjd2 - mjd1)/365.2425;
141 *dec += N * cos(*ra) * nyrs;
142 *ra += (M + (N * sin(*ra) * tan(*dec))) * nyrs;
143 range (ra, 2.0*PI);
144}
145#endif
146
147/* For RCS Only -- Do Not Edit */
148static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: precess.c,v $ $Date: 2001-04-10 14:40:47 $ $Revision: 1.1.1.1 $ $Name: not supported by cvs2svn $"};
Note: See TracBrowser for help on using the repository browser.