-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnutation.c
273 lines (250 loc) · 8.06 KB
/
nutation.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
// HDS OPE file Editor
// nutation.c : imported from libnova
// 2012.10.22 A.Tajitsu
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Copyright (C) 2000 - 2005 Liam Girdwood
*/
#include "main.h"
#include <math.h>
#include "libnova/nutation.h"
#include "libnova/dynamical_time.h"
#include "libnova/utility.h"
#define TERMS 63
#define LN_NUTATION_EPOCH_THRESHOLD 0.1
struct nutation_arguments
{
double D;
double M;
double MM;
double F;
double O;
};
struct nutation_coefficients
{
double longitude1;
double longitude2;
double obliquity1;
double obliquity2;
};
/* arguments and coefficients taken from table 21A on page 133 */
const static struct nutation_arguments arguments[TERMS] = {
{0.0, 0.0, 0.0, 0.0, 1.0},
{-2.0, 0.0, 0.0, 2.0, 2.0},
{0.0, 0.0, 0.0, 2.0, 2.0},
{0.0, 0.0, 0.0, 0.0, 2.0},
{0.0, 1.0, 0.0, 0.0, 0.0},
{0.0, 0.0, 1.0, 0.0, 0.0},
{-2.0, 1.0, 0.0, 2.0, 2.0},
{0.0, 0.0, 0.0, 2.0, 1.0},
{0.0, 0.0, 1.0, 2.0, 2.0},
{-2.0, -1.0, 0.0, 2.0, 2.0},
{-2.0, 0.0, 1.0, 0.0, 0.0},
{-2.0, 0.0, 0.0, 2.0, 1.0},
{0.0, 0.0, -1.0, 2.0, 2.0},
{2.0, 0.0, 0.0, 0.0, 0.0},
{0.0, 0.0, 1.0, 0.0, 1.0},
{2.0, 0.0, -1.0, 2.0, 2.0},
{0.0, 0.0, -1.0, 0.0, 1.0},
{0.0, 0.0, 1.0, 2.0, 1.0},
{-2.0, 0.0, 2.0, 0.0, 0.0},
{0.0, 0.0, -2.0, 2.0, 1.0},
{2.0, 0.0, 0.0, 2.0, 2.0},
{0.0, 0.0, 2.0, 2.0, 2.0},
{0.0, 0.0, 2.0, 0.0, 0.0},
{-2.0, 0.0, 1.0, 2.0, 2.0},
{0.0, 0.0, 0.0, 2.0, 0.0},
{-2.0, 0.0, 0.0, 2.0, 0.0},
{0.0, 0.0, -1.0, 2.0, 1.0},
{0.0, 2.0, 0.0, 0.0, 0.0},
{2.0, 0.0, -1.0, 0.0, 1.0},
{-2.0, 2.0, 0.0, 2.0, 2.0},
{0.0, 1.0, 0.0, 0.0, 1.0},
{-2.0, 0.0, 1.0, 0.0, 1.0},
{0.0, -1.0, 0.0, 0.0, 1.0},
{0.0, 0.0, 2.0, -2.0, 0.0},
{2.0, 0.0, -1.0, 2.0, 1.0},
{2.0, 0.0, 1.0, 2.0, 2.0},
{0.0, 1.0, 0.0, 2.0, 2.0},
{-2.0, 1.0, 1.0, 0.0, 0.0},
{0.0, -1.0, 0.0, 2.0, 2.0},
{2.0, 0.0, 0.0, 2.0, 1.0},
{2.0, 0.0, 1.0, 0.0, 0.0},
{-2.0, 0.0, 2.0, 2.0, 2.0},
{-2.0, 0.0, 1.0, 2.0, 1.0},
{2.0, 0.0, -2.0, 0.0, 1.0},
{2.0, 0.0, 0.0, 0.0, 1.0},
{0.0, -1.0, 1.0, 0.0, 0.0},
{-2.0, -1.0, 0.0, 2.0, 1.0},
{-2.0, 0.0, 0.0, 0.0, 1.0},
{0.0, 0.0, 2.0, 2.0, 1.0},
{-2.0, 0.0, 2.0, 0.0, 1.0},
{-2.0, 1.0, 0.0, 2.0, 1.0},
{0.0, 0.0, 1.0, -2.0, 0.0},
{-1.0, 0.0, 1.0, 0.0, 0.0},
{-2.0, 1.0, 0.0, 0.0, 0.0},
{1.0, 0.0, 0.0, 0.0, 0.0},
{0.0, 0.0, 1.0, 2.0, 0.0},
{0.0, 0.0, -2.0, 2.0, 2.0},
{-1.0, -1.0, 1.0, 0.0, 0.0},
{0.0, 1.0, 1.0, 0.0, 0.0},
{0.0, -1.0, 1.0, 2.0, 2.0},
{2.0, -1.0, -1.0, 2.0, 2.0},
{0.0, 0.0, 3.0, 2.0, 2.0},
{2.0, -1.0, 0.0, 2.0, 2.0}};
const static struct nutation_coefficients coefficients[TERMS] = {
{-171996.0, -174.2, 92025.0,8.9},
{-13187.0, -1.6, 5736.0, -3.1},
{-2274.0, 0.2, 977.0, -0.5},
{2062.0, 0.2, -895.0, 0.5},
{1426.0, -3.4, 54.0, -0.1},
{712.0, 0.1, -7.0, 0.0},
{-517.0, 1.2, 224.0, -0.6},
{-386.0, -0.4, 200.0, 0.0},
{-301.0, 0.0, 129.0, -0.1},
{217.0, -0.5, -95.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0, 0.0, 0.0, 0.0},
{-3.0, 0.0, 0.0, 0.0},
{-3.0, 0.0, 0.0, 0.0},
{-3.0, 0.0, 0.0, 0.0},
{-3.0, 0.0, 0.0, 0.0},
{-3.0, 0.0, 0.0, 0.0}};
/* cache values */
static long double c_JD = 0.0, c_longitude = 0.0, c_obliquity = 0.0, c_ecliptic = 0.0;
/*! \fn void ln_get_nutation (double JD, struct ln_nutation * nutation)
* \param JD Julian Day.
* \param nutation Pointer to store nutation
*
* Calculate nutation of longitude and obliquity in degrees from Julian Ephemeris Day
*/
/* Chapter 21 pg 131-134 Using Table 21A
*/
void ln_get_nutation (double JD, struct ln_nutation * nutation)
{
long double D,M,MM,F,O,T,T2,T3,JDE;
long double coeff_sine, coeff_cos;
int i;
/* should we bother recalculating nutation */
if (fabsl(JD - c_JD) > LN_NUTATION_EPOCH_THRESHOLD) {
/* set the new epoch */
c_JD = JD;
/* set ecliptic */
c_ecliptic = 23.0 + 26.0 / 60.0 + 27.407 / 3600.0;
/* get julian ephemeris day */
JDE = ln_get_jde (JD);
/* calc T */
T = (JDE - 2451545.0)/36525;
T2 = T * T;
T3 = T2 * T;
/* calculate D,M,M',F and Omega */
D = 297.85036 + 445267.111480 * T - 0.0019142 * T2 + T3 / 189474.0;
M = 357.52772 + 35999.050340 * T - 0.0001603 * T2 - T3 / 300000.0;
MM = 134.96298 + 477198.867398 * T + 0.0086972 * T2 + T3 / 56250.0;
F = 93.2719100 + 483202.017538 * T - 0.0036825 * T2 + T3 / 327270.0;
O = 125.04452 - 1934.136261 * T + 0.0020708 * T2 + T3 / 450000.0;
/* convert to radians */
D = ln_deg_to_rad (D);
M = ln_deg_to_rad (M);
MM = ln_deg_to_rad (MM);
F = ln_deg_to_rad (F);
O = ln_deg_to_rad (O);
/* calc sum of terms in table 21A */
for (i=0; i< TERMS; i++) {
/* calc coefficients of sine and cosine */
coeff_sine = (coefficients[i].longitude1 + (coefficients[i].longitude2 * T));
coeff_cos = (coefficients[i].obliquity1 + (coefficients[i].obliquity2 * T));
/* sum the arguments */
if (arguments[i].D != 0) {
c_longitude += coeff_sine * (sin (arguments[i].D * D));
c_obliquity += coeff_cos * (cos (arguments[i].D * D));
}
if (arguments[i].M != 0) {
c_longitude += coeff_sine * (sin (arguments[i].M * M));
c_obliquity += coeff_cos * (cos (arguments[i].M * M));
}
if (arguments[i].MM != 0) {
c_longitude += coeff_sine * (sin (arguments[i].MM * MM));
c_obliquity += coeff_cos * (cos (arguments[i].MM * MM));
}
if (arguments[i].F != 0) {
c_longitude += coeff_sine * (sin (arguments[i].F * F));
c_obliquity += coeff_cos * (cos (arguments[i].F * F));
}
if (arguments[i].O != 0) {
c_longitude += coeff_sine * (sin (arguments[i].O * O));
c_obliquity += coeff_cos * (cos (arguments[i].O * O));
}
}
/* change to arcsecs */
c_longitude /= 10000;
c_obliquity /= 10000;
/* change to degrees */
c_longitude /= (60 * 60);
c_obliquity /= (60 * 60);
c_ecliptic += c_obliquity;
}
/* return results */
nutation->longitude = c_longitude;
nutation->obliquity = c_obliquity;
nutation->ecliptic = c_ecliptic;
}