swe4r 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1824 @@
1
+ /* SWISSEPH
2
+ $Header: /home/dieter/sweph/RCS/swemmoon.c,v 1.74 2008/06/16 10:07:20 dieter Exp $
3
+ *
4
+ * Steve Moshier's analytical lunar ephemeris
5
+
6
+ **************************************************************/
7
+ /* Copyright (C) 1997 - 2008 Astrodienst AG, Switzerland. All rights reserved.
8
+
9
+ License conditions
10
+ ------------------
11
+
12
+ This file is part of Swiss Ephemeris.
13
+
14
+ Swiss Ephemeris is distributed with NO WARRANTY OF ANY KIND. No author
15
+ or distributor accepts any responsibility for the consequences of using it,
16
+ or for whether it serves any particular purpose or works at all, unless he
17
+ or she says so in writing.
18
+
19
+ Swiss Ephemeris is made available by its authors under a dual licensing
20
+ system. The software developer, who uses any part of Swiss Ephemeris
21
+ in his or her software, must choose between one of the two license models,
22
+ which are
23
+ a) GNU public license version 2 or later
24
+ b) Swiss Ephemeris Professional License
25
+
26
+ The choice must be made before the software developer distributes software
27
+ containing parts of Swiss Ephemeris to others, and before any public
28
+ service using the developed software is activated.
29
+
30
+ If the developer choses the GNU GPL software license, he or she must fulfill
31
+ the conditions of that license, which includes the obligation to place his
32
+ or her whole software project under the GNU GPL or a compatible license.
33
+ See http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
34
+
35
+ If the developer choses the Swiss Ephemeris Professional license,
36
+ he must follow the instructions as found in http://www.astro.com/swisseph/
37
+ and purchase the Swiss Ephemeris Professional Edition from Astrodienst
38
+ and sign the corresponding license contract.
39
+
40
+ The License grants you the right to use, copy, modify and redistribute
41
+ Swiss Ephemeris, but only under certain conditions described in the License.
42
+ Among other things, the License requires that the copyright notices and
43
+ this notice be preserved on all copies.
44
+
45
+ Authors of the Swiss Ephemeris: Dieter Koch and Alois Treindl
46
+
47
+ The authors of Swiss Ephemeris have no control or influence over any of
48
+ the derived works, i.e. over software or services created by other
49
+ programmers which use Swiss Ephemeris functions.
50
+
51
+ The names of the authors or of the copyright holder (Astrodienst) must not
52
+ be used for promoting any software, product or service which uses or contains
53
+ the Swiss Ephemeris. This copyright notice is the ONLY place where the
54
+ names of the authors can legally appear, except in cases where they have
55
+ given special permission in writing.
56
+
57
+ The trademarks 'Swiss Ephemeris' and 'Swiss Ephemeris inside' may be used
58
+ for promoting such software, products or services.
59
+ */
60
+
61
+
62
+ /*
63
+ * Expansions for the geocentric ecliptic longitude,
64
+ * latitude, and distance of the Moon referred to the mean equinox
65
+ * and ecliptic of date.
66
+ *
67
+ * This version of cmoon.c adjusts the ELP2000-85 analytical Lunar
68
+ * theory of Chapront-Touze and Chapront to fit the Jet Propulsion
69
+ * Laboratory's DE404 long ephemeris on the interval from 3000 B.C.
70
+ * to 3000 A.D.
71
+ *
72
+ * The fit is much better in the remote past and future if
73
+ * secular terms are included in the arguments of the oscillatory
74
+ * perturbations. Such adjustments cannot easily be incorporated
75
+ * into the 1991 lunar tables. In this program the traditional
76
+ * literal arguments are used instead, with mean elements adjusted
77
+ * for a best fit to the reference ephemeris.
78
+ *
79
+ * This program omits many oscillatory terms from the analytical
80
+ * theory which, if they were included, would yield a much higher
81
+ * accuracy for modern dates. Detailed statistics of the precision
82
+ * are given in the table below. Comparing at 64-day intervals
83
+ * over the period -3000 to +3000, the maximum discrepancies noted
84
+ * were 7" longitude, 5" latitude, and 5 x 10^-8 au radius.
85
+ * The expressions used for precession in this comparision were
86
+ * those of Simon et al (1994).
87
+ *
88
+ * The adjusted coefficients were found by an unweighted least squares
89
+ * fit to the numerical ephemeris in the mentioned test interval.
90
+ * The approximation error increases rapidly outside this interval.
91
+ * J. Chapront (1994) has described the basic fitting procedure.
92
+ *
93
+ * A major change from DE200 to DE404 is in the coefficient
94
+ * of tidal acceleration of the Moon, which causes the Moon's
95
+ * longitude to depart by about -0.9" per century squared
96
+ * from DE200. Uncertainty in this quantity continues to
97
+ * be the limiting factor in long term projections of the Moon's
98
+ * ephemeris.
99
+ *
100
+ * Since the Lunar theory is cast in the ecliptic of date, it makes
101
+ * some difference what formula you use for precession. The adjustment
102
+ * to DE404 was carried out relative to the mean equinox and ecliptic
103
+ * of date as defined in Williams (1994). An earlier version of this
104
+ * program used the precession given by Simon et al (1994). The difference
105
+ * between these two precession formulas amounts to about 12" in Lunar
106
+ * longitude at 3000 B.C.
107
+ *
108
+ * Maximum deviations between DE404 and this program
109
+ * in a set of 34274 samples spaced 64 days apart
110
+ *
111
+ * Interval Longitude Latitude Radius
112
+ * Julian Year arc sec arc sec 10^-8 au
113
+ * -3000 to -2500 5.66 4.66 4.93
114
+ * -2500 to -2000 5.49 3.98 4.56
115
+ * -2000 to -1500 6.98 4.17 4.81
116
+ * -1500 to -1000 5.74 3.53 4.87
117
+ * -1000 to -500 5.95 3.42 4.67
118
+ * -500 to 0 4.94 3.07 4.04
119
+ * 0 to 500 4.42 2.65 4.55
120
+ * 500 to 1000 5.68 3.30 3.99
121
+ * 1000 to 1500 4.32 3.21 3.83
122
+ * 1500 to 2000 2.70 2.69 3.71
123
+ * 2000 to 2500 3.35 2.32 3.85
124
+ * 2500 to 3000 4.62 2.39 4.11
125
+ *
126
+ *
127
+ *
128
+ * References:
129
+ *
130
+ * James G. Williams, "Contributions to the Earth's obliquity rate,
131
+ * precession, and nutation," Astron. J. 108, 711-724 (1994)
132
+ *
133
+ * DE403 and DE404 ephemerides by E. M. Standish, X. X. Newhall, and
134
+ * J. G. Williams are at the JPL computer site navigator.jpl.nasa.gov.
135
+ *
136
+ * J. L. Simon, P. Bretagnon, J. Chapront, M. Chapront-Touze', G. Francou,
137
+ * and J. Laskar, "Numerical Expressions for precession formulae and
138
+ * mean elements for the Moon and the planets," Astronomy and Astrophysics
139
+ * 282, 663-683 (1994)
140
+ *
141
+ * P. Bretagnon and Francou, G., "Planetary theories in rectangular
142
+ * and spherical variables. VSOP87 solutions," Astronomy and
143
+ * Astrophysics 202, 309-315 (1988)
144
+ *
145
+ * M. Chapront-Touze' and J. Chapront, "ELP2000-85: a semi-analytical
146
+ * lunar ephemeris adequate for historical times," Astronomy and
147
+ * Astrophysics 190, 342-352 (1988).
148
+ *
149
+ * M. Chapront-Touze' and J. Chapront, _Lunar Tables and
150
+ * Programs from 4000 B.C. to A.D. 8000_, Willmann-Bell (1991)
151
+ *
152
+ * J. Laskar, "Secular terms of classical planetary theories
153
+ * using the results of general theory," Astronomy and Astrophysics
154
+ * 157, 59070 (1986)
155
+ *
156
+ * S. L. Moshier, "Comparison of a 7000-year lunar ephemeris
157
+ * with analytical theory," Astronomy and Astrophysics 262,
158
+ * 613-616 (1992)
159
+ *
160
+ * J. Chapront, "Representation of planetary ephemerides by frequency
161
+ * analysis. Application to the five outer planets," Astronomy and
162
+ * Astrophysics Suppl. Ser. 109, 181-192 (1994)
163
+ *
164
+ *
165
+ * Entry swi_moshmoon2() returns the geometric position of the Moon
166
+ * relative to the Earth. Its calling procedure is as follows:
167
+ *
168
+ * double JD; input Julian Ephemeris Date
169
+ * double pol[3]; output ecliptic polar coordinatees in radians and au
170
+ * pol[0] longitude, pol[1] latitude, pol[2] radius
171
+ * swi_moshmoon2( JD, pol );
172
+ *
173
+ * - S. L. Moshier, August, 1991
174
+ * DE200 fit: July, 1992
175
+ * DE404 fit: October, 1995
176
+ *
177
+ * Dieter Koch: adaptation to SWISSEPH, April 1996
178
+ * 18-feb-2006 replaced LP by SWELP because of name collision
179
+ */
180
+
181
+ #include <string.h>
182
+ #include "swephexp.h"
183
+ #include "sweph.h"
184
+ #include "swephlib.h"
185
+
186
+ static void mean_elements(void);
187
+ static void mean_elements_pl(void);
188
+ static double mods3600(double x);
189
+ static void ecldat_equ2000(double tjd, double *xpm);
190
+ static void chewm(short *pt, int nlines, int nangles,
191
+ int typflg, double *ans );
192
+ static void sscc(int k, double arg, int n );
193
+ static void moon1(void);
194
+ static void moon2(void);
195
+ static void moon3(void);
196
+ static void moon4(void);
197
+
198
+
199
+ #ifdef MOSH_MOON_200
200
+ /* The following coefficients were calculated by a simultaneous least
201
+ * squares fit between the analytical theory and the continued DE200
202
+ * numerically integrated ephemeris from 9000 BC to 13000 AD.
203
+ * See references to the array z[] later on in the program.
204
+ * The 71 coefficients were estimated from 42,529 Lunar positions.
205
+ */
206
+ static double z[] = {
207
+ -1.225346551567e+001, /* F, t^2 */
208
+ -1.096676093208e-003, /* F, t^3 */
209
+ -2.165750777942e-006, /* F, t^4 */
210
+ -2.790392351314e-009, /* F, t^5 */
211
+ 4.189032191814e-011, /* F, t^6 */
212
+ 4.474984866301e-013, /* F, t^7 */
213
+ 3.239398410335e+001, /* l, t^2 */
214
+ 5.185305877294e-002, /* l, t^3 */
215
+ -2.536291235258e-004, /* l, t^4 */
216
+ -2.506365935364e-008, /* l, t^5 */
217
+ 3.452144225877e-011, /* l, t^6 */
218
+ -1.755312760154e-012, /* l, t^7 */
219
+ -5.870522364514e+000, /* D, t^2 */
220
+ 6.493037519768e-003, /* D, t^3 */
221
+ -3.702060118571e-005, /* D, t^4 */
222
+ 2.560078201452e-009, /* D, t^5 */
223
+ 2.555243317839e-011, /* D, t^6 */
224
+ -3.207663637426e-013, /* D, t^7 */
225
+ -4.776684245026e+000, /* L, t^2 */
226
+ 6.580112707824e-003, /* L, t^3 */
227
+ -6.073960534117e-005, /* L, t^4 */
228
+ -1.024222633731e-008, /* L, t^5 */
229
+ 2.235210987108e-010, /* L, t^6 */
230
+ 7.200592540556e-014, /* L, t^7 */
231
+ -8.552017636339e+001, /* t^2 cos(18V - 16E - l) */
232
+ -2.055794304596e+002, /* t^2 sin(18V - 16E - l) */
233
+ -1.097555241866e+000, /* t^3 cos(18V - 16E - l) */
234
+ 5.219423171002e-001, /* t^3 sin(18V - 16E - l) */
235
+ 2.088802640755e-003, /* t^4 cos(18V - 16E - l) */
236
+ 4.616541527921e-003, /* t^4 sin(18V - 16E - l) */
237
+ 4.794930645807e+000, /* t^2 cos(10V - 3E - l) */
238
+ -4.595134364283e+001, /* t^2 sin(10V - 3E - l) */
239
+ -6.659812174691e-002, /* t^3 cos(10V - 3E - l) */
240
+ -2.570048828246e-001, /* t^3 sin(10V - 3E - l) */
241
+ 6.229863046223e-004, /* t^4 cos(10V - 3E - l) */
242
+ 5.504368344700e-003, /* t^4 sin(10V - 3E - l) */
243
+ -3.084830597278e+000, /* t^2 cos(8V - 13E) */
244
+ -1.000471012253e+001, /* t^2 sin(8V - 13E) */
245
+ 6.590112074510e-002, /* t^3 cos(8V - 13E) */
246
+ -3.212573348278e-003, /* t^3 sin(8V - 13E) */
247
+ 5.409038312567e-004, /* t^4 cos(8V - 13E) */
248
+ 1.293377988163e-003, /* t^4 sin(8V - 13E) */
249
+ 2.311794636111e+001, /* t^2 cos(4E - 8M + 3J) */
250
+ -3.157036220040e+000, /* t^2 sin(4E - 8M + 3J) */
251
+ -3.019293162417e+000, /* t^2 cos(18V - 16E) */
252
+ -9.211526858975e+000, /* t^2 sin(18V - 16E) */
253
+ -4.993704215784e-002, /* t^3 cos(18V - 16E) */
254
+ 2.991187525454e-002, /* t^3 sin(18V - 16E) */
255
+ -3.827414182969e+000, /* t^2 cos(18V - 16E - 2l) */
256
+ -9.891527703219e+000, /* t^2 sin(18V - 16E - 2l) */
257
+ -5.322093802878e-002, /* t^3 cos(18V - 16E - 2l) */
258
+ 3.164702647371e-002, /* t^3 sin(18V - 16E - 2l) */
259
+ 7.713905234217e+000, /* t^2 cos(2J - 5S) */
260
+ -6.077986950734e+000, /* t^3 sin(2J - 5S) */
261
+ -1.278232501462e-001, /* t^2 cos(L - F) */
262
+ 4.760967236383e-001, /* t^2 sin(L - F) */
263
+ -6.759005756460e-001, /* t^3 sin(l') */
264
+ 1.655727996357e-003, /* t^4 sin(l') */
265
+ 1.646526117252e-001, /* t^3 sin(2D - l') */
266
+ -4.167078100233e-004, /* t^4 sin(2D - l') */
267
+ 2.067529538504e-001, /* t^3 sin(2D - l' - l) */
268
+ -5.219127398748e-004, /* t^4 sin(2D - l' - l) */
269
+ -1.526335222289e-001, /* t^3 sin(l' - l) */
270
+ -1.120545131358e-001, /* t^3 sin(l' + l) */
271
+ 4.619472391553e-002, /* t^3 sin(2D - 2l') */
272
+ 4.863621236157e-004, /* t^4 sin(2D - 2l') */
273
+ -4.280059182608e-002, /* t^3 sin(2l') */
274
+ -4.328378207833e-004, /* t^4 sin(2l') */
275
+ -8.371028286974e-003, /* t^3 sin(2D - l) */
276
+ 4.089447328174e-002, /* t^3 sin(2D - 2l' - l) */
277
+ -1.238363006354e-002, /* t^3 sin(2D + 2l' - l) */
278
+ };
279
+ #else
280
+ /* The following coefficients were calculated by a simultaneous least
281
+ * squares fit between the analytical theory and DE404 on the finite
282
+ * interval from -3000 to +3000.
283
+ * The coefficients were estimated from 34,247 Lunar positions.
284
+ */
285
+ static double FAR z[] = {
286
+ /* The following are scaled in arc seconds, time in Julian centuries.
287
+ They replace the corresponding terms in the mean elements. */
288
+ -1.312045233711e+01, /* F, t^2 */
289
+ -1.138215912580e-03, /* F, t^3 */
290
+ -9.646018347184e-06, /* F, t^4 */
291
+ 3.146734198839e+01, /* l, t^2 */
292
+ 4.768357585780e-02, /* l, t^3 */
293
+ -3.421689790404e-04, /* l, t^4 */
294
+ -6.847070905410e+00, /* D, t^2 */
295
+ -5.834100476561e-03, /* D, t^3 */
296
+ -2.905334122698e-04, /* D, t^4 */
297
+ -5.663161722088e+00, /* L, t^2 */
298
+ 5.722859298199e-03, /* L, t^3 */
299
+ -8.466472828815e-05, /* L, t^4 */
300
+ /* The following longitude terms are in arc seconds times 10^5. */
301
+ -8.429817796435e+01, /* t^2 cos(18V - 16E - l) */
302
+ -2.072552484689e+02, /* t^2 sin(18V - 16E - l) */
303
+ 7.876842214863e+00, /* t^2 cos(10V - 3E - l) */
304
+ 1.836463749022e+00, /* t^2 sin(10V - 3E - l) */
305
+ -1.557471855361e+01, /* t^2 cos(8V - 13E) */
306
+ -2.006969124724e+01, /* t^2 sin(8V - 13E) */
307
+ 2.152670284757e+01, /* t^2 cos(4E - 8M + 3J) */
308
+ -6.179946916139e+00, /* t^2 sin(4E - 8M + 3J) */
309
+ -9.070028191196e-01, /* t^2 cos(18V - 16E) */
310
+ -1.270848233038e+01, /* t^2 sin(18V - 16E) */
311
+ -2.145589319058e+00, /* t^2 cos(2J - 5S) */
312
+ 1.381936399935e+01, /* t^2 sin(2J - 5S) */
313
+ -1.999840061168e+00, /* t^3 sin(l') */
314
+ };
315
+ #endif /* ! MOSH_MOON_200 */
316
+
317
+ /* Perturbation tables
318
+ */
319
+ #define NLR 118
320
+ static short FAR LR[8*NLR] = {
321
+ /*
322
+ Longitude Radius
323
+ D l' l F 1" .0001" 1km .0001km */
324
+
325
+ 0, 0, 1, 0, 22639, 5858,-20905,-3550,
326
+ 2, 0,-1, 0, 4586, 4383, -3699,-1109,
327
+ 2, 0, 0, 0, 2369, 9139, -2955,-9676,
328
+ 0, 0, 2, 0, 769, 257, -569,-9251,
329
+ 0, 1, 0, 0, -666,-4171, 48, 8883,
330
+ 0, 0, 0, 2, -411,-5957, -3,-1483,
331
+ 2, 0,-2, 0, 211, 6556, 246, 1585,
332
+ 2,-1,-1, 0, 205, 4358, -152,-1377,
333
+ 2, 0, 1, 0, 191, 9562, -170,-7331,
334
+ 2,-1, 0, 0, 164, 7285, -204,-5860,
335
+ 0, 1,-1, 0, -147,-3213, -129,-6201,
336
+ 1, 0, 0, 0, -124,-9881, 108, 7427,
337
+ 0, 1, 1, 0, -109,-3803, 104, 7552,
338
+ 2, 0, 0,-2, 55, 1771, 10, 3211,
339
+ 0, 0, 1, 2, -45, -996, 0, 0,
340
+ 0, 0, 1,-2, 39, 5333, 79, 6606,
341
+ 4, 0,-1, 0, 38, 4298, -34,-7825,
342
+ 0, 0, 3, 0, 36, 1238, -23,-2104,
343
+ 4, 0,-2, 0, 30, 7726, -21,-6363,
344
+ 2, 1,-1, 0, -28,-3971, 24, 2085,
345
+ 2, 1, 0, 0, -24,-3582, 30, 8238,
346
+ 1, 0,-1, 0, -18,-5847, -8,-3791,
347
+ 1, 1, 0, 0, 17, 9545, -16,-6747,
348
+ 2,-1, 1, 0, 14, 5303, -12,-8314,
349
+ 2, 0, 2, 0, 14, 3797, -10,-4448,
350
+ 4, 0, 0, 0, 13, 8991, -11,-6500,
351
+ 2, 0,-3, 0, 13, 1941, 14, 4027,
352
+ 0, 1,-2, 0, -9,-6791, -7, -27,
353
+ 2, 0,-1, 2, -9,-3659, 0, 7740,
354
+ 2,-1,-2, 0, 8, 6055, 10, 562,
355
+ 1, 0, 1, 0, -8,-4531, 6, 3220,
356
+ 2,-2, 0, 0, 8, 502, -9,-8845,
357
+ 0, 1, 2, 0, -7,-6302, 5, 7509,
358
+ 0, 2, 0, 0, -7,-4475, 1, 657,
359
+ 2,-2,-1, 0, 7, 3712, -4,-9501,
360
+ 2, 0, 1,-2, -6,-3832, 4, 1311,
361
+ 2, 0, 0, 2, -5,-7416, 0, 0,
362
+ 4,-1,-1, 0, 4, 3740, -3,-9580,
363
+ 0, 0, 2, 2, -3,-9976, 0, 0,
364
+ 3, 0,-1, 0, -3,-2097, 3, 2582,
365
+ 2, 1, 1, 0, -2,-9145, 2, 6164,
366
+ 4,-1,-2, 0, 2, 7319, -1,-8970,
367
+ 0, 2,-1, 0, -2,-5679, -2,-1171,
368
+ 2, 2,-1, 0, -2,-5212, 2, 3536,
369
+ 2, 1,-2, 0, 2, 4889, 0, 1437,
370
+ 2,-1, 0,-2, 2, 1461, 0, 6571,
371
+ 4, 0, 1, 0, 1, 9777, -1,-4226,
372
+ 0, 0, 4, 0, 1, 9337, -1,-1169,
373
+ 4,-1, 0, 0, 1, 8708, -1,-5714,
374
+ 1, 0,-2, 0, -1,-7530, -1,-7385,
375
+ 2, 1, 0,-2, -1,-4372, 0,-1357,
376
+ 0, 0, 2,-2, -1,-3726, -4,-4212,
377
+ 1, 1, 1, 0, 1, 2618, 0,-9333,
378
+ 3, 0,-2, 0, -1,-2241, 0, 8624,
379
+ 4, 0,-3, 0, 1, 1868, 0,-5142,
380
+ 2,-1, 2, 0, 1, 1770, 0,-8488,
381
+ 0, 2, 1, 0, -1,-1617, 1, 1655,
382
+ 1, 1,-1, 0, 1, 777, 0, 8512,
383
+ 2, 0, 3, 0, 1, 595, 0,-6697,
384
+ 2, 0, 1, 2, 0,-9902, 0, 0,
385
+ 2, 0,-4, 0, 0, 9483, 0, 7785,
386
+ 2,-2, 1, 0, 0, 7517, 0,-6575,
387
+ 0, 1,-3, 0, 0,-6694, 0,-4224,
388
+ 4, 1,-1, 0, 0,-6352, 0, 5788,
389
+ 1, 0, 2, 0, 0,-5840, 0, 3785,
390
+ 1, 0, 0,-2, 0,-5833, 0,-7956,
391
+ 6, 0,-2, 0, 0, 5716, 0,-4225,
392
+ 2, 0,-2,-2, 0,-5606, 0, 4726,
393
+ 1,-1, 0, 0, 0,-5569, 0, 4976,
394
+ 0, 1, 3, 0, 0,-5459, 0, 3551,
395
+ 2, 0,-2, 2, 0,-5357, 0, 7740,
396
+ 2, 0,-1,-2, 0, 1790, 8, 7516,
397
+ 3, 0, 0, 0, 0, 4042, -1,-4189,
398
+ 2,-1,-3, 0, 0, 4784, 0, 4950,
399
+ 2,-1, 3, 0, 0, 932, 0, -585,
400
+ 2, 0, 2,-2, 0,-4538, 0, 2840,
401
+ 2,-1,-1, 2, 0,-4262, 0, 373,
402
+ 0, 0, 0, 4, 0, 4203, 0, 0,
403
+ 0, 1, 0, 2, 0, 4134, 0,-1580,
404
+ 6, 0,-1, 0, 0, 3945, 0,-2866,
405
+ 2,-1, 0, 2, 0,-3821, 0, 0,
406
+ 2,-1, 1,-2, 0,-3745, 0, 2094,
407
+ 4, 1,-2, 0, 0,-3576, 0, 2370,
408
+ 1, 1,-2, 0, 0, 3497, 0, 3323,
409
+ 2,-3, 0, 0, 0, 3398, 0,-4107,
410
+ 0, 0, 3, 2, 0,-3286, 0, 0,
411
+ 4,-2,-1, 0, 0,-3087, 0,-2790,
412
+ 0, 1,-1,-2, 0, 3015, 0, 0,
413
+ 4, 0,-1,-2, 0, 3009, 0,-3218,
414
+ 2,-2,-2, 0, 0, 2942, 0, 3430,
415
+ 6, 0,-3, 0, 0, 2925, 0,-1832,
416
+ 2, 1, 2, 0, 0,-2902, 0, 2125,
417
+ 4, 1, 0, 0, 0,-2891, 0, 2445,
418
+ 4,-1, 1, 0, 0, 2825, 0,-2029,
419
+ 3, 1,-1, 0, 0, 2737, 0,-2126,
420
+ 0, 1, 1, 2, 0, 2634, 0, 0,
421
+ 1, 0, 0, 2, 0, 2543, 0, 0,
422
+ 3, 0, 0,-2, 0,-2530, 0, 2010,
423
+ 2, 2,-2, 0, 0,-2499, 0,-1089,
424
+ 2,-3,-1, 0, 0, 2469, 0,-1481,
425
+ 3,-1,-1, 0, 0,-2314, 0, 2556,
426
+ 4, 0, 2, 0, 0, 2185, 0,-1392,
427
+ 4, 0,-1, 2, 0,-2013, 0, 0,
428
+ 0, 2,-2, 0, 0,-1931, 0, 0,
429
+ 2, 2, 0, 0, 0,-1858, 0, 0,
430
+ 2, 1,-3, 0, 0, 1762, 0, 0,
431
+ 4, 0,-2, 2, 0,-1698, 0, 0,
432
+ 4,-2,-2, 0, 0, 1578, 0,-1083,
433
+ 4,-2, 0, 0, 0, 1522, 0,-1281,
434
+ 3, 1, 0, 0, 0, 1499, 0,-1077,
435
+ 1,-1,-1, 0, 0,-1364, 0, 1141,
436
+ 1,-3, 0, 0, 0,-1281, 0, 0,
437
+ 6, 0, 0, 0, 0, 1261, 0, -859,
438
+ 2, 0, 2, 2, 0,-1239, 0, 0,
439
+ 1,-1, 1, 0, 0,-1207, 0, 1100,
440
+ 0, 0, 5, 0, 0, 1110, 0, -589,
441
+ 0, 3, 0, 0, 0,-1013, 0, 213,
442
+ 4,-1,-3, 0, 0, 998, 0, 0,
443
+ };
444
+
445
+
446
+ #ifdef MOSH_MOON_200
447
+ #define NMB 56
448
+ static short FAR MB[6*NMB] = {
449
+ /*
450
+ Latitude
451
+ D l' l F 1" .0001" */
452
+
453
+ 0, 0, 0, 1,18461, 2387,
454
+ 0, 0, 1, 1, 1010, 1671,
455
+ 0, 0, 1,-1, 999, 6936,
456
+ 2, 0, 0,-1, 623, 6524,
457
+ 2, 0,-1, 1, 199, 4837,
458
+ 2, 0,-1,-1, 166, 5741,
459
+ 2, 0, 0, 1, 117, 2607,
460
+ 0, 0, 2, 1, 61, 9120,
461
+ 2, 0, 1,-1, 33, 3572,
462
+ 0, 0, 2,-1, 31, 7597,
463
+ 2,-1, 0,-1, 29, 5766,
464
+ 2, 0,-2,-1, 15, 5663,
465
+ 2, 0, 1, 1, 15, 1216,
466
+ 2, 1, 0,-1, -12, -941,
467
+ 2,-1,-1, 1, 8, 8681,
468
+ 2,-1, 0, 1, 7, 9586,
469
+ 2,-1,-1,-1, 7, 4346,
470
+ 0, 1,-1,-1, -6,-7314,
471
+ 4, 0,-1,-1, 6, 5796,
472
+ 0, 1, 0, 1, -6,-4601,
473
+ 0, 0, 0, 3, -6,-2965,
474
+ 0, 1,-1, 1, -5,-6324,
475
+ 1, 0, 0, 1, -5,-3684,
476
+ 0, 1, 1, 1, -5,-3113,
477
+ 0, 1, 1,-1, -5, -759,
478
+ 0, 1, 0,-1, -4,-8396,
479
+ 1, 0, 0,-1, -4,-8057,
480
+ 0, 0, 3, 1, 3, 9841,
481
+ 4, 0, 0,-1, 3, 6745,
482
+ 4, 0,-1, 1, 2, 9985,
483
+ 0, 0, 1,-3, 2, 7986,
484
+ 4, 0,-2, 1, 2, 4139,
485
+ 2, 0, 0,-3, 2, 1863,
486
+ 2, 0, 2,-1, 2, 1462,
487
+ 2,-1, 1,-1, 1, 7660,
488
+ 2, 0,-2, 1, -1,-6244,
489
+ 0, 0, 3,-1, 1, 5813,
490
+ 2, 0, 2, 1, 1, 5198,
491
+ 2, 0,-3,-1, 1, 5156,
492
+ 2, 1,-1, 1, -1,-3178,
493
+ 2, 1, 0, 1, -1,-2643,
494
+ 4, 0, 0, 1, 1, 1919,
495
+ 2,-1, 1, 1, 1, 1346,
496
+ 2,-2, 0,-1, 1, 859,
497
+ 0, 0, 1, 3, -1, -194,
498
+ 2, 1, 1,-1, 0,-8227,
499
+ 1, 1, 0,-1, 0, 8042,
500
+ 1, 1, 0, 1, 0, 8026,
501
+ 0, 1,-2,-1, 0,-7932,
502
+ 2, 1,-1,-1, 0,-7910,
503
+ 1, 0, 1, 1, 0,-6674,
504
+ 2,-1,-2,-1, 0, 6502,
505
+ 0, 1, 2, 1, 0,-6388,
506
+ 4, 0,-2,-1, 0, 6337,
507
+ 4,-1,-1,-1, 0, 5958,
508
+ 1, 0, 1,-1, 0,-5889,
509
+ };
510
+ #else
511
+ #define NMB 77
512
+ static short FAR MB[6*NMB] = {
513
+ /*
514
+ Latitude
515
+ D l' l F 1" .0001" */
516
+
517
+ 0, 0, 0, 1,18461, 2387,
518
+ 0, 0, 1, 1, 1010, 1671,
519
+ 0, 0, 1,-1, 999, 6936,
520
+ 2, 0, 0,-1, 623, 6524,
521
+ 2, 0,-1, 1, 199, 4837,
522
+ 2, 0,-1,-1, 166, 5741,
523
+ 2, 0, 0, 1, 117, 2607,
524
+ 0, 0, 2, 1, 61, 9120,
525
+ 2, 0, 1,-1, 33, 3572,
526
+ 0, 0, 2,-1, 31, 7597,
527
+ 2,-1, 0,-1, 29, 5766,
528
+ 2, 0,-2,-1, 15, 5663,
529
+ 2, 0, 1, 1, 15, 1216,
530
+ 2, 1, 0,-1, -12, -941,
531
+ 2,-1,-1, 1, 8, 8681,
532
+ 2,-1, 0, 1, 7, 9586,
533
+ 2,-1,-1,-1, 7, 4346,
534
+ 0, 1,-1,-1, -6,-7314,
535
+ 4, 0,-1,-1, 6, 5796,
536
+ 0, 1, 0, 1, -6,-4601,
537
+ 0, 0, 0, 3, -6,-2965,
538
+ 0, 1,-1, 1, -5,-6324,
539
+ 1, 0, 0, 1, -5,-3684,
540
+ 0, 1, 1, 1, -5,-3113,
541
+ 0, 1, 1,-1, -5, -759,
542
+ 0, 1, 0,-1, -4,-8396,
543
+ 1, 0, 0,-1, -4,-8057,
544
+ 0, 0, 3, 1, 3, 9841,
545
+ 4, 0, 0,-1, 3, 6745,
546
+ 4, 0,-1, 1, 2, 9985,
547
+ 0, 0, 1,-3, 2, 7986,
548
+ 4, 0,-2, 1, 2, 4139,
549
+ 2, 0, 0,-3, 2, 1863,
550
+ 2, 0, 2,-1, 2, 1462,
551
+ 2,-1, 1,-1, 1, 7660,
552
+ 2, 0,-2, 1, -1,-6244,
553
+ 0, 0, 3,-1, 1, 5813,
554
+ 2, 0, 2, 1, 1, 5198,
555
+ 2, 0,-3,-1, 1, 5156,
556
+ 2, 1,-1, 1, -1,-3178,
557
+ 2, 1, 0, 1, -1,-2643,
558
+ 4, 0, 0, 1, 1, 1919,
559
+ 2,-1, 1, 1, 1, 1346,
560
+ 2,-2, 0,-1, 1, 859,
561
+ 0, 0, 1, 3, -1, -194,
562
+ 2, 1, 1,-1, 0,-8227,
563
+ 1, 1, 0,-1, 0, 8042,
564
+ 1, 1, 0, 1, 0, 8026,
565
+ 0, 1,-2,-1, 0,-7932,
566
+ 2, 1,-1,-1, 0,-7910,
567
+ 1, 0, 1, 1, 0,-6674,
568
+ 2,-1,-2,-1, 0, 6502,
569
+ 0, 1, 2, 1, 0,-6388,
570
+ 4, 0,-2,-1, 0, 6337,
571
+ 4,-1,-1,-1, 0, 5958,
572
+ 1, 0, 1,-1, 0,-5889,
573
+ 4, 0, 1,-1, 0, 4734,
574
+ 1, 0,-1,-1, 0,-4299,
575
+ 4,-1, 0,-1, 0, 4149,
576
+ 2,-2, 0, 1, 0, 3835,
577
+ 3, 0, 0,-1, 0,-3518,
578
+ 4,-1,-1, 1, 0, 3388,
579
+ 2, 0,-1,-3, 0, 3291,
580
+ 2,-2,-1, 1, 0, 3147,
581
+ 0, 1, 2,-1, 0,-3129,
582
+ 3, 0,-1,-1, 0,-3052,
583
+ 0, 1,-2, 1, 0,-3013,
584
+ 2, 0, 1,-3, 0,-2912,
585
+ 2,-2,-1,-1, 0, 2686,
586
+ 0, 0, 4, 1, 0, 2633,
587
+ 2, 0,-3, 1, 0, 2541,
588
+ 2, 0,-1, 3, 0,-2448,
589
+ 2, 1, 1, 1, 0,-2370,
590
+ 4,-1,-2, 1, 0, 2138,
591
+ 4, 0, 1, 1, 0, 2126,
592
+ 3, 0,-1, 1, 0,-2059,
593
+ 4, 1,-1,-1, 0,-1719,
594
+ };
595
+ #endif /* ! MOSH_MOON_200 */
596
+
597
+ #define NLRT 38
598
+ static short FAR LRT[8*NLRT] = {
599
+ /*
600
+ Multiply by T
601
+ Longitude Radius
602
+ D l' l F .1" .00001" .1km .00001km */
603
+
604
+ 0, 1, 0, 0, 16, 7680, -1,-2302,
605
+ 2,-1,-1, 0, -5,-1642, 3, 8245,
606
+ 2,-1, 0, 0, -4,-1383, 5, 1395,
607
+ 0, 1,-1, 0, 3, 7115, 3, 2654,
608
+ 0, 1, 1, 0, 2, 7560, -2,-6396,
609
+ 2, 1,-1, 0, 0, 7118, 0,-6068,
610
+ 2, 1, 0, 0, 0, 6128, 0,-7754,
611
+ 1, 1, 0, 0, 0,-4516, 0, 4194,
612
+ 2,-2, 0, 0, 0,-4048, 0, 4970,
613
+ 0, 2, 0, 0, 0, 3747, 0, -540,
614
+ 2,-2,-1, 0, 0,-3707, 0, 2490,
615
+ 2,-1, 1, 0, 0,-3649, 0, 3222,
616
+ 0, 1,-2, 0, 0, 2438, 0, 1760,
617
+ 2,-1,-2, 0, 0,-2165, 0,-2530,
618
+ 0, 1, 2, 0, 0, 1923, 0,-1450,
619
+ 0, 2,-1, 0, 0, 1292, 0, 1070,
620
+ 2, 2,-1, 0, 0, 1271, 0,-6070,
621
+ 4,-1,-1, 0, 0,-1098, 0, 990,
622
+ 2, 0, 0, 0, 0, 1073, 0,-1360,
623
+ 2, 0,-1, 0, 0, 839, 0, -630,
624
+ 2, 1, 1, 0, 0, 734, 0, -660,
625
+ 4,-1,-2, 0, 0, -688, 0, 480,
626
+ 2, 1,-2, 0, 0, -630, 0, 0,
627
+ 0, 2, 1, 0, 0, 587, 0, -590,
628
+ 2,-1, 0,-2, 0, -540, 0, -170,
629
+ 4,-1, 0, 0, 0, -468, 0, 390,
630
+ 2,-2, 1, 0, 0, -378, 0, 330,
631
+ 2, 1, 0,-2, 0, 364, 0, 0,
632
+ 1, 1, 1, 0, 0, -317, 0, 240,
633
+ 2,-1, 2, 0, 0, -295, 0, 210,
634
+ 1, 1,-1, 0, 0, -270, 0, -210,
635
+ 2,-3, 0, 0, 0, -256, 0, 310,
636
+ 2,-3,-1, 0, 0, -187, 0, 110,
637
+ 0, 1,-3, 0, 0, 169, 0, 110,
638
+ 4, 1,-1, 0, 0, 158, 0, -150,
639
+ 4,-2,-1, 0, 0, -155, 0, 140,
640
+ 0, 0, 1, 0, 0, 155, 0, -250,
641
+ 2,-2,-2, 0, 0, -148, 0, -170,
642
+ };
643
+
644
+ #define NBT 16
645
+ static short FAR BT[5*NBT] = {
646
+ /*
647
+ Multiply by T
648
+ Latitude
649
+ D l' l F .00001" */
650
+
651
+ 2,-1, 0,-1, -7430,
652
+ 2, 1, 0,-1, 3043,
653
+ 2,-1,-1, 1, -2229,
654
+ 2,-1, 0, 1, -1999,
655
+ 2,-1,-1,-1, -1869,
656
+ 0, 1,-1,-1, 1696,
657
+ 0, 1, 0, 1, 1623,
658
+ 0, 1,-1, 1, 1418,
659
+ 0, 1, 1, 1, 1339,
660
+ 0, 1, 1,-1, 1278,
661
+ 0, 1, 0,-1, 1217,
662
+ 2,-2, 0,-1, -547,
663
+ 2,-1, 1,-1, -443,
664
+ 2, 1,-1, 1, 331,
665
+ 2, 1, 0, 1, 317,
666
+ 2, 0, 0,-1, 295,
667
+ };
668
+
669
+ #define NLRT2 25
670
+ static short FAR LRT2[6*NLRT2] = {
671
+ /*
672
+ Multiply by T^2
673
+ Longitude Radius
674
+ D l' l F .00001" .00001km */
675
+
676
+ 0, 1, 0, 0, 487, -36,
677
+ 2,-1,-1, 0, -150, 111,
678
+ 2,-1, 0, 0, -120, 149,
679
+ 0, 1,-1, 0, 108, 95,
680
+ 0, 1, 1, 0, 80, -77,
681
+ 2, 1,-1, 0, 21, -18,
682
+ 2, 1, 0, 0, 20, -23,
683
+ 1, 1, 0, 0, -13, 12,
684
+ 2,-2, 0, 0, -12, 14,
685
+ 2,-1, 1, 0, -11, 9,
686
+ 2,-2,-1, 0, -11, 7,
687
+ 0, 2, 0, 0, 11, 0,
688
+ 2,-1,-2, 0, -6, -7,
689
+ 0, 1,-2, 0, 7, 5,
690
+ 0, 1, 2, 0, 6, -4,
691
+ 2, 2,-1, 0, 5, -3,
692
+ 0, 2,-1, 0, 5, 3,
693
+ 4,-1,-1, 0, -3, 3,
694
+ 2, 0, 0, 0, 3, -4,
695
+ 4,-1,-2, 0, -2, 0,
696
+ 2, 1,-2, 0, -2, 0,
697
+ 2,-1, 0,-2, -2, 0,
698
+ 2, 1, 1, 0, 2, -2,
699
+ 2, 0,-1, 0, 2, 0,
700
+ 0, 2, 1, 0, 2, 0,
701
+ };
702
+
703
+ #define NBT2 12
704
+ static short FAR BT2[5*NBT2] = {
705
+ /*
706
+ Multiply by T^2
707
+ Latitiude
708
+ D l' l F .00001" */
709
+
710
+ 2,-1, 0,-1, -22,
711
+ 2, 1, 0,-1, 9,
712
+ 2,-1, 0, 1, -6,
713
+ 2,-1,-1, 1, -6,
714
+ 2,-1,-1,-1, -5,
715
+ 0, 1, 0, 1, 5,
716
+ 0, 1,-1,-1, 5,
717
+ 0, 1, 1, 1, 4,
718
+ 0, 1, 1,-1, 4,
719
+ 0, 1, 0,-1, 4,
720
+ 0, 1,-1, 1, 4,
721
+ 2,-2, 0,-1, -2,
722
+ };
723
+
724
+ /* The following times are set up by update() and refer
725
+ * to the same instant. The distinction between them
726
+ * is required by altaz().
727
+ */
728
+ static double FAR ss[5][8];
729
+ static double FAR cc[5][8];
730
+
731
+ static double l; /* Moon's ecliptic longitude */
732
+ static double B; /* Ecliptic latitude */
733
+
734
+ static double moonpol[3];
735
+
736
+ /* Orbit calculation begins.
737
+ */
738
+ static double SWELP;
739
+ static double M;
740
+ static double MP;
741
+ static double D;
742
+ static double NF;
743
+ static double T;
744
+ static double T2;
745
+
746
+ static double T3;
747
+ static double T4;
748
+ static double f;
749
+ static double g;
750
+ static double Ve;
751
+ static double Ea;
752
+ static double Ma;
753
+ static double Ju;
754
+ static double Sa;
755
+ static double cg;
756
+ static double sg;
757
+ static double l1;
758
+ static double l2;
759
+ static double l3;
760
+ static double l4;
761
+
762
+ /* Calculate geometric coordinates of Moon
763
+ * without light time or nutation correction.
764
+ */
765
+ int swi_moshmoon2(double J, double *pol)
766
+ {
767
+ int i;
768
+ T = (J-J2000)/36525.0;
769
+ T2 = T*T;
770
+ mean_elements();
771
+ mean_elements_pl();
772
+ moon1();
773
+ moon2();
774
+ moon3();
775
+ moon4();
776
+ for( i=0; i<3; i++ )
777
+ pol[i] = moonpol[i];
778
+ return(0);
779
+ }
780
+
781
+ /* Moshier's moom
782
+ * tjd julian day
783
+ * xpm array of 6 doubles for moon's position and speed vectors
784
+ * serr pointer to error string
785
+ */
786
+ int swi_moshmoon(double tjd, AS_BOOL do_save, double *xpmret, char *serr)
787
+ {
788
+ int i;
789
+ double a, b, x1[6], x2[6], t;
790
+ double xx[6], *xpm;
791
+ struct plan_data *pdp = &swed.pldat[SEI_MOON];
792
+ char s[AS_MAXCH];
793
+ if (do_save)
794
+ xpm = pdp->x;
795
+ else
796
+ xpm = xx;
797
+ /* allow 0.2 day tolerance so that true node interval fits in */
798
+ if (tjd < MOSHLUEPH_START - 0.2 || tjd > MOSHLUEPH_END + 0.2) {
799
+ if (serr != NULL) {
800
+ sprintf(s, "jd %f outside Moshier's Moon range %.2f .. %.2f ",
801
+ tjd, MOSHLUEPH_START, MOSHLUEPH_END);
802
+ if (strlen(serr) + strlen(s) < AS_MAXCH)
803
+ strcat(serr, s);
804
+ }
805
+ return(ERR);
806
+ }
807
+ /* if moon has already been computed */
808
+ if (tjd == pdp->teval && pdp->iephe == SEFLG_MOSEPH) {
809
+ if (xpmret != NULL)
810
+ for (i = 0; i <= 5; i++)
811
+ xpmret[i] = pdp->x[i];
812
+ return(OK);
813
+ }
814
+ /* else compute moon */
815
+ swi_moshmoon2(tjd, xpm);
816
+ if (do_save) {
817
+ pdp->teval = tjd;
818
+ pdp->xflgs = -1;
819
+ pdp->iephe = SEFLG_MOSEPH;
820
+ }
821
+ /* Moshier moon is referred to ecliptic of date. But we need
822
+ * equatorial positions for several reasons.
823
+ * e.g. computation of earth from emb and moon
824
+ * of heliocentric moon
825
+ * Besides, this helps to keep the program structure simpler
826
+ */
827
+ ecldat_equ2000(tjd, xpm);
828
+ /* speed */
829
+ /* from 2 other positions. */
830
+ /* one would be good enough for computation of osculating node,
831
+ * but not for osculating apogee */
832
+ t = tjd + MOON_SPEED_INTV;
833
+ swi_moshmoon2(t, x1);
834
+ ecldat_equ2000(t, x1);
835
+ t = tjd - MOON_SPEED_INTV;
836
+ swi_moshmoon2(t, x2);
837
+ ecldat_equ2000(t, x2);
838
+ for (i = 0; i <= 2; i++) {
839
+ #if 0
840
+ xpm[i+3] = (x1[i] - x2[i]) / MOON_SPEED_INTV / 2;
841
+ #else
842
+ b = (x1[i] - x2[i]) / 2;
843
+ a = (x1[i] + x2[i]) / 2 - xpm[i];
844
+ xpm[i+3] = (2 * a + b) / MOON_SPEED_INTV;
845
+ #endif
846
+ }
847
+ if (xpmret != NULL)
848
+ for (i = 0; i <= 5; i++)
849
+ xpmret[i] = xpm[i];
850
+ return(OK);
851
+ }
852
+
853
+ #ifdef MOSH_MOON_200
854
+ static void moon1()
855
+ {
856
+ double a;
857
+
858
+ sscc( 0, STR*D, 6 );
859
+ sscc( 1, STR*M, 4 );
860
+ sscc( 2, STR*MP, 4 );
861
+ sscc( 3, STR*NF, 4 );
862
+
863
+ moonpol[0] = 0.0;
864
+ moonpol[1] = 0.0;
865
+ moonpol[2] = 0.0;
866
+
867
+ /* terms in T^2, scale 1.0 = 10^-5" */
868
+ chewm( LRT2, NLRT2, 4, 2, moonpol );
869
+ chewm( BT2, NBT2, 4, 4, moonpol );
870
+
871
+ f = 18 * Ve - 16 * Ea;
872
+
873
+ g = STR*(f - MP ); /* 18V - 16E - l */
874
+ cg = cos(g);
875
+ sg = sin(g);
876
+ l = 6.367278 * cg + 12.747036 * sg; /* t^0 */
877
+ l1 = 23123.70 * cg - 10570.02 * sg; /* t^1 */
878
+ l2 = z[24] * cg + z[25] * sg; /* t^2 */
879
+ l3 = z[26] * cg + z[27] * sg; /* t^3 */
880
+ l4 = z[28] * cg + z[29] * sg; /* t^4 */
881
+ moonpol[2] += 5.01 * cg + 2.72 * sg;
882
+
883
+ g = STR * (10.*Ve - 3.*Ea - MP);
884
+ cg = cos(g);
885
+ sg = sin(g);
886
+ l += -0.253102 * cg + 0.503359 * sg;
887
+ l1 += 1258.46 * cg + 707.29 * sg;
888
+ l2 += z[30] * cg + z[31] * sg;
889
+ l3 += z[32] * cg + z[33] * sg;
890
+ l4 += z[34] * cg + z[35] * sg;
891
+
892
+ g = STR*(8.*Ve - 13.*Ea);
893
+ cg = cos(g);
894
+ sg = sin(g);
895
+ l += -0.187231 * cg - 0.127481 * sg;
896
+ l1 += -319.87 * cg - 18.34 * sg;
897
+ l2 += z[36] * cg + z[37] * sg;
898
+ l3 += z[38] * cg + z[39] * sg;
899
+ l4 += z[40] * cg + z[41] * sg;
900
+
901
+ a = 4.0*Ea - 8.0*Ma + 3.0*Ju;
902
+ g = STR * a;
903
+ cg = cos(g);
904
+ sg = sin(g);
905
+ l += -0.866287 * cg + 0.248192 * sg;
906
+ l1 += 41.87 * cg + 1053.97 * sg;
907
+ l2 += z[42] * cg + z[43] * sg;
908
+
909
+ g = STR*(a - MP);
910
+ cg = cos(g);
911
+ sg = sin(g);
912
+ l += -0.165009 * cg + 0.044176 * sg;
913
+ l1 += 4.67 * cg + 201.55 * sg;
914
+
915
+
916
+ g = STR*f; /* 18V - 16E */
917
+ cg = cos(g);
918
+ sg = sin(g);
919
+ l += 0.330401 * cg + 0.661362 * sg;
920
+ l1 += 1202.67 * cg - 555.59 * sg;
921
+ l2 += z[44] * cg + z[45] * sg;
922
+ l3 += z[46] * cg + z[47] * sg;
923
+
924
+ g = STR*(f - 2.0*MP ); /* 18V - 16E - 2l */
925
+ cg = cos(g);
926
+ sg = sin(g);
927
+ l += 0.352185 * cg + 0.705041 * sg;
928
+ l1 += 1283.59 * cg - 586.43 * sg;
929
+ l2 += z[48] * cg + z[49] * sg;
930
+ l3 += z[50] * cg + z[51] * sg;
931
+
932
+ g = STR * (2.0*Ju - 5.0*Sa);
933
+ cg = cos(g);
934
+ sg = sin(g);
935
+ l += -0.034700 * cg + 0.160041 * sg;
936
+ l2 += z[52] * cg + z[53] * sg;
937
+
938
+ g = STR * (SWELP - NF);
939
+ cg = cos(g);
940
+ sg = sin(g);
941
+ l += 0.000116 * cg + 7.063040 * sg;
942
+ l1 += 298.8 * sg;
943
+ l2 += z[54] * cg + z[55] * sg;
944
+
945
+
946
+ /* T^3 terms */
947
+ sg = sin( STR * M );
948
+ l3 += z[56] * sg;
949
+ l4 += z[57] * sg;
950
+
951
+ g = STR * (2.0*D - M);
952
+ sg = sin(g);
953
+ cg = cos(g);
954
+ l3 += z[58] * sg;
955
+ l4 += z[59] * sg;
956
+ moonpol[2] += -0.2655 * cg * T;
957
+
958
+ g = g - STR * MP;
959
+ sg = sin(g);
960
+ l3 += z[60] * sg;
961
+ l4 += z[61] * sg;
962
+
963
+ g = STR * (M - MP);
964
+ l3 += z[62] * sin( g );
965
+ moonpol[2] += -0.1568 * cos( g ) * T;
966
+
967
+ g = STR * (M + MP);
968
+ l3 += z[63] * sin( g );
969
+ moonpol[2] += 0.1309 * cos( g ) * T;
970
+
971
+ g = STR * 2.0 * (D - M);
972
+ sg = sin(g);
973
+ l3 += z[64] * sg;
974
+ l4 += z[65] * sg;
975
+
976
+ g = STR * 2.0 * M;
977
+ sg = sin(g);
978
+ l3 += z[66] * sg;
979
+ l4 += z[67] * sg;
980
+
981
+ g = STR * (2.0*D - MP);
982
+ sg = sin(g);
983
+ l3 += z[68] * sg;
984
+
985
+ g = STR * (2.0*(D - M) - MP);
986
+ sg = sin(g);
987
+ l3 += z[69] * sg;
988
+
989
+ g = STR * (2.0*(D + M) - MP);
990
+ sg = sin(g);
991
+ cg = cos(g);
992
+ l3 += z[70] * sg;
993
+ moonpol[2] += 0.5568 * cg * T;
994
+
995
+ l2 += moonpol[0];
996
+
997
+ g = STR*(2.0*D - M - MP);
998
+ moonpol[2] += -0.1910 * cos( g ) * T;
999
+
1000
+
1001
+ moonpol[1] *= T;
1002
+ moonpol[2] *= T;
1003
+
1004
+ /* terms in T */
1005
+ moonpol[0] = 0.0;
1006
+ chewm( BT, NBT, 4, 4, moonpol );
1007
+ chewm( LRT, NLRT, 4, 1, moonpol );
1008
+ g = STR*(f - MP - NF - 2355767.6); /* 18V - 16E - l - F */
1009
+ moonpol[1] += -1127. * sin(g);
1010
+ g = STR*(f - MP + NF - 235353.6); /* 18V - 16E - l + F */
1011
+ moonpol[1] += -1123. * sin(g);
1012
+ g = STR*(Ea + D + 51987.6);
1013
+ moonpol[1] += 1303. * sin(g);
1014
+ g = STR*SWELP;
1015
+ moonpol[1] += 342. * sin(g);
1016
+
1017
+
1018
+ g = STR*(2.*Ve - 3.*Ea);
1019
+ cg = cos(g);
1020
+ sg = sin(g);
1021
+ l += -0.343550 * cg - 0.000276 * sg;
1022
+ l1 += 105.90 * cg + 336.53 * sg;
1023
+
1024
+ g = STR*(f - 2.*D); /* 18V - 16E - 2D */
1025
+ cg = cos(g);
1026
+ sg = sin(g);
1027
+ l += 0.074668 * cg + 0.149501 * sg;
1028
+ l1 += 271.77 * cg - 124.20 * sg;
1029
+
1030
+ g = STR*(f - 2.*D - MP);
1031
+ cg = cos(g);
1032
+ sg = sin(g);
1033
+ l += 0.073444 * cg + 0.147094 * sg;
1034
+ l1 += 265.24 * cg - 121.16 * sg;
1035
+
1036
+ g = STR*(f + 2.*D - MP);
1037
+ cg = cos(g);
1038
+ sg = sin(g);
1039
+ l += 0.072844 * cg + 0.145829 * sg;
1040
+ l1 += 265.18 * cg - 121.29 * sg;
1041
+
1042
+ g = STR*(f + 2.*(D - MP));
1043
+ cg = cos(g);
1044
+ sg = sin(g);
1045
+ l += 0.070201 * cg + 0.140542 * sg;
1046
+ l1 += 255.36 * cg - 116.79 * sg;
1047
+
1048
+ g = STR*(Ea + D - NF);
1049
+ cg = cos(g);
1050
+ sg = sin(g);
1051
+ l += 0.288209 * cg - 0.025901 * sg;
1052
+ l1 += -63.51 * cg - 240.14 * sg;
1053
+
1054
+ g = STR*(2.*Ea - 3.*Ju + 2.*D - MP);
1055
+ cg = cos(g);
1056
+ sg = sin(g);
1057
+ l += 0.077865 * cg + 0.438460 * sg;
1058
+ l1 += 210.57 * cg + 124.84 * sg;
1059
+
1060
+ g = STR*(Ea - 2.*Ma);
1061
+ cg = cos(g);
1062
+ sg = sin(g);
1063
+ l += -0.216579 * cg + 0.241702 * sg;
1064
+ l1 += 197.67 * cg + 125.23 * sg;
1065
+
1066
+ g = STR*(a + MP);
1067
+ cg = cos(g);
1068
+ sg = sin(g);
1069
+ l += -0.165009 * cg + 0.044176 * sg;
1070
+ l1 += 4.67 * cg + 201.55 * sg;
1071
+
1072
+ g = STR*(a + 2.*D - MP);
1073
+ cg = cos(g);
1074
+ sg = sin(g);
1075
+ l += -0.133533 * cg + 0.041116 * sg;
1076
+ l1 += 6.95 * cg + 187.07 * sg;
1077
+
1078
+ g = STR*(a - 2.*D + MP);
1079
+ cg = cos(g);
1080
+ sg = sin(g);
1081
+ l += -0.133430 * cg + 0.041079 * sg;
1082
+ l1 += 6.28 * cg + 169.08 * sg;
1083
+
1084
+ g = STR*(3.*Ve - 4.*Ea);
1085
+ cg = cos(g);
1086
+ sg = sin(g);
1087
+ l += -0.175074 * cg + 0.003035 * sg;
1088
+ l1 += 49.17 * cg + 150.57 * sg;
1089
+
1090
+ g = STR*(2.*(Ea + D - MP) - 3.*Ju + 213534.);
1091
+ l1 += 158.4 * sin(g);
1092
+ l1 += moonpol[0];
1093
+
1094
+ a = 0.1 * T; /* set amplitude scale of 1.0 = 10^-4 arcsec */
1095
+ moonpol[1] *= a;
1096
+ moonpol[2] *= a;
1097
+ }
1098
+ #else
1099
+ static void moon1()
1100
+ {
1101
+ double a;
1102
+ /* This code added by Bhanu Pinnamaneni, 17-aug-2009 */
1103
+ /* Note by Dieter: Bhanu noted that ss and cc are not sufficiently
1104
+ * initialised and random values are used for the calculation.
1105
+ * However, this may be only part of the bug.
1106
+ * The bug could be in sscc(). Or may be the bug is rather in
1107
+ * the 116th line of NLR, where the value "5" may be wrong.
1108
+ * Still, this will make a maximum difference of only 0.1", while the error
1109
+ * of the Moshier lunar ephemeris can reach 7". */
1110
+ int i, j;
1111
+ for (i = 0; i < 5; i++) {
1112
+ for (j = 0; j < 8; j++) {
1113
+ ss[i][j] = 0;
1114
+ cc[i][j] = 0;
1115
+ }
1116
+ }
1117
+ /* End of code addition */
1118
+ sscc( 0, STR*D, 6 );
1119
+ sscc( 1, STR*M, 4 );
1120
+ sscc( 2, STR*MP, 4 );
1121
+ sscc( 3, STR*NF, 4 );
1122
+ moonpol[0] = 0.0;
1123
+ moonpol[1] = 0.0;
1124
+ moonpol[2] = 0.0;
1125
+ /* terms in T^2, scale 1.0 = 10^-5" */
1126
+ chewm( LRT2, NLRT2, 4, 2, moonpol );
1127
+ chewm( BT2, NBT2, 4, 4, moonpol );
1128
+ f = 18 * Ve - 16 * Ea;
1129
+ g = STR*(f - MP ); /* 18V - 16E - l */
1130
+ cg = cos(g);
1131
+ sg = sin(g);
1132
+ l = 6.367278 * cg + 12.747036 * sg; /* t^0 */
1133
+ l1 = 23123.70 * cg - 10570.02 * sg; /* t^1 */
1134
+ l2 = z[12] * cg + z[13] * sg; /* t^2 */
1135
+ moonpol[2] += 5.01 * cg + 2.72 * sg;
1136
+ g = STR * (10.*Ve - 3.*Ea - MP);
1137
+ cg = cos(g);
1138
+ sg = sin(g);
1139
+ l += -0.253102 * cg + 0.503359 * sg;
1140
+ l1 += 1258.46 * cg + 707.29 * sg;
1141
+ l2 += z[14] * cg + z[15] * sg;
1142
+ g = STR*(8.*Ve - 13.*Ea);
1143
+ cg = cos(g);
1144
+ sg = sin(g);
1145
+ l += -0.187231 * cg - 0.127481 * sg;
1146
+ l1 += -319.87 * cg - 18.34 * sg;
1147
+ l2 += z[16] * cg + z[17] * sg;
1148
+ a = 4.0*Ea - 8.0*Ma + 3.0*Ju;
1149
+ g = STR * a;
1150
+ cg = cos(g);
1151
+ sg = sin(g);
1152
+ l += -0.866287 * cg + 0.248192 * sg;
1153
+ l1 += 41.87 * cg + 1053.97 * sg;
1154
+ l2 += z[18] * cg + z[19] * sg;
1155
+ g = STR*(a - MP);
1156
+ cg = cos(g);
1157
+ sg = sin(g);
1158
+ l += -0.165009 * cg + 0.044176 * sg;
1159
+ l1 += 4.67 * cg + 201.55 * sg;
1160
+ g = STR*f; /* 18V - 16E */
1161
+ cg = cos(g);
1162
+ sg = sin(g);
1163
+ l += 0.330401 * cg + 0.661362 * sg;
1164
+ l1 += 1202.67 * cg - 555.59 * sg;
1165
+ l2 += z[20] * cg + z[21] * sg;
1166
+ g = STR*(f - 2.0*MP ); /* 18V - 16E - 2l */
1167
+ cg = cos(g);
1168
+ sg = sin(g);
1169
+ l += 0.352185 * cg + 0.705041 * sg;
1170
+ l1 += 1283.59 * cg - 586.43 * sg;
1171
+ g = STR * (2.0*Ju - 5.0*Sa);
1172
+ cg = cos(g);
1173
+ sg = sin(g);
1174
+ l += -0.034700 * cg + 0.160041 * sg;
1175
+ l2 += z[22] * cg + z[23] * sg;
1176
+ g = STR * (SWELP - NF);
1177
+ cg = cos(g);
1178
+ sg = sin(g);
1179
+ l += 0.000116 * cg + 7.063040 * sg;
1180
+ l1 += 298.8 * sg;
1181
+ /* T^3 terms */
1182
+ sg = sin( STR * M );
1183
+ /* l3 += z[24] * sg; moshier! l3 not initialized! */
1184
+ l3 = z[24] * sg;
1185
+ l4 = 0;
1186
+ g = STR * (2.0*D - M);
1187
+ sg = sin(g);
1188
+ cg = cos(g);
1189
+ moonpol[2] += -0.2655 * cg * T;
1190
+ g = STR * (M - MP);
1191
+ moonpol[2] += -0.1568 * cos( g ) * T;
1192
+ g = STR * (M + MP);
1193
+ moonpol[2] += 0.1309 * cos( g ) * T;
1194
+ g = STR * (2.0*(D + M) - MP);
1195
+ sg = sin(g);
1196
+ cg = cos(g);
1197
+ moonpol[2] += 0.5568 * cg * T;
1198
+ l2 += moonpol[0];
1199
+ g = STR*(2.0*D - M - MP);
1200
+ moonpol[2] += -0.1910 * cos( g ) * T;
1201
+ moonpol[1] *= T;
1202
+ moonpol[2] *= T;
1203
+ /* terms in T */
1204
+ moonpol[0] = 0.0;
1205
+ chewm( BT, NBT, 4, 4, moonpol );
1206
+ chewm( LRT, NLRT, 4, 1, moonpol );
1207
+ g = STR*(f - MP - NF - 2355767.6); /* 18V - 16E - l - F */
1208
+ moonpol[1] += -1127. * sin(g);
1209
+ g = STR*(f - MP + NF - 235353.6); /* 18V - 16E - l + F */
1210
+ moonpol[1] += -1123. * sin(g);
1211
+ g = STR*(Ea + D + 51987.6);
1212
+ moonpol[1] += 1303. * sin(g);
1213
+ g = STR*SWELP;
1214
+ moonpol[1] += 342. * sin(g);
1215
+ g = STR*(2.*Ve - 3.*Ea);
1216
+ cg = cos(g);
1217
+ sg = sin(g);
1218
+ l += -0.343550 * cg - 0.000276 * sg;
1219
+ l1 += 105.90 * cg + 336.53 * sg;
1220
+ g = STR*(f - 2.*D); /* 18V - 16E - 2D */
1221
+ cg = cos(g);
1222
+ sg = sin(g);
1223
+ l += 0.074668 * cg + 0.149501 * sg;
1224
+ l1 += 271.77 * cg - 124.20 * sg;
1225
+ g = STR*(f - 2.*D - MP);
1226
+ cg = cos(g);
1227
+ sg = sin(g);
1228
+ l += 0.073444 * cg + 0.147094 * sg;
1229
+ l1 += 265.24 * cg - 121.16 * sg;
1230
+ g = STR*(f + 2.*D - MP);
1231
+ cg = cos(g);
1232
+ sg = sin(g);
1233
+ l += 0.072844 * cg + 0.145829 * sg;
1234
+ l1 += 265.18 * cg - 121.29 * sg;
1235
+ g = STR*(f + 2.*(D - MP));
1236
+ cg = cos(g);
1237
+ sg = sin(g);
1238
+ l += 0.070201 * cg + 0.140542 * sg;
1239
+ l1 += 255.36 * cg - 116.79 * sg;
1240
+ g = STR*(Ea + D - NF);
1241
+ cg = cos(g);
1242
+ sg = sin(g);
1243
+ l += 0.288209 * cg - 0.025901 * sg;
1244
+ l1 += -63.51 * cg - 240.14 * sg;
1245
+ g = STR*(2.*Ea - 3.*Ju + 2.*D - MP);
1246
+ cg = cos(g);
1247
+ sg = sin(g);
1248
+ l += 0.077865 * cg + 0.438460 * sg;
1249
+ l1 += 210.57 * cg + 124.84 * sg;
1250
+ g = STR*(Ea - 2.*Ma);
1251
+ cg = cos(g);
1252
+ sg = sin(g);
1253
+ l += -0.216579 * cg + 0.241702 * sg;
1254
+ l1 += 197.67 * cg + 125.23 * sg;
1255
+ g = STR*(a + MP);
1256
+ cg = cos(g);
1257
+ sg = sin(g);
1258
+ l += -0.165009 * cg + 0.044176 * sg;
1259
+ l1 += 4.67 * cg + 201.55 * sg;
1260
+ g = STR*(a + 2.*D - MP);
1261
+ cg = cos(g);
1262
+ sg = sin(g);
1263
+ l += -0.133533 * cg + 0.041116 * sg;
1264
+ l1 += 6.95 * cg + 187.07 * sg;
1265
+ g = STR*(a - 2.*D + MP);
1266
+ cg = cos(g);
1267
+ sg = sin(g);
1268
+ l += -0.133430 * cg + 0.041079 * sg;
1269
+ l1 += 6.28 * cg + 169.08 * sg;
1270
+ g = STR*(3.*Ve - 4.*Ea);
1271
+ cg = cos(g);
1272
+ sg = sin(g);
1273
+ l += -0.175074 * cg + 0.003035 * sg;
1274
+ l1 += 49.17 * cg + 150.57 * sg;
1275
+ g = STR*(2.*(Ea + D - MP) - 3.*Ju + 213534.);
1276
+ l1 += 158.4 * sin(g);
1277
+ l1 += moonpol[0];
1278
+ a = 0.1 * T; /* set amplitude scale of 1.0 = 10^-4 arcsec */
1279
+ moonpol[1] *= a;
1280
+ moonpol[2] *= a;
1281
+ }
1282
+ #endif /* MOSH_MOON_200 */
1283
+
1284
+ static void moon2()
1285
+ {
1286
+ /* terms in T^0 */
1287
+ g = STR*(2*(Ea-Ju+D)-MP+648431.172);
1288
+ l += 1.14307 * sin(g);
1289
+ g = STR*(Ve-Ea+648035.568);
1290
+ l += 0.82155 * sin(g);
1291
+ g = STR*(3*(Ve-Ea)+2*D-MP+647933.184);
1292
+ l += 0.64371 * sin(g);
1293
+ g = STR*(Ea-Ju+4424.04);
1294
+ l += 0.63880 * sin(g);
1295
+ g = STR*(SWELP + MP - NF + 4.68);
1296
+ l += 0.49331 * sin(g);
1297
+ g = STR*(SWELP - MP - NF + 4.68);
1298
+ l += 0.4914 * sin(g);
1299
+ g = STR*(SWELP+NF+2.52);
1300
+ l += 0.36061 * sin(g);
1301
+ g = STR*(2.*Ve - 2.*Ea + 736.2);
1302
+ l += 0.30154 * sin(g);
1303
+ g = STR*(2.*Ea - 3.*Ju + 2.*D - 2.*MP + 36138.2);
1304
+ l += 0.28282 * sin(g);
1305
+ g = STR*(2.*Ea - 2.*Ju + 2.*D - 2.*MP + 311.0);
1306
+ l += 0.24516 * sin(g);
1307
+ g = STR*(Ea - Ju - 2.*D + MP + 6275.88);
1308
+ l += 0.21117 * sin(g);
1309
+ g = STR*(2.*(Ea - Ma) - 846.36);
1310
+ l += 0.19444 * sin(g);
1311
+ g = STR*(2.*(Ea - Ju) + 1569.96);
1312
+ l -= 0.18457 * sin(g);
1313
+ g = STR*(2.*(Ea - Ju) - MP - 55.8);
1314
+ l += 0.18256 * sin(g);
1315
+ g = STR*(Ea - Ju - 2.*D + 6490.08);
1316
+ l += 0.16499 * sin(g);
1317
+ g = STR*(Ea - 2.*Ju - 212378.4);
1318
+ l += 0.16427 * sin(g);
1319
+ g = STR*(2.*(Ve - Ea - D) + MP + 1122.48);
1320
+ l += 0.16088 * sin(g);
1321
+ g = STR*(Ve - Ea - MP + 32.04);
1322
+ l -= 0.15350 * sin(g);
1323
+ g = STR*(Ea - Ju - MP + 4488.88);
1324
+ l += 0.14346 * sin(g);
1325
+ g = STR*(2.*(Ve - Ea + D) - MP - 8.64);
1326
+ l += 0.13594 * sin(g);
1327
+ g = STR*(2.*(Ve - Ea - D) + 1319.76);
1328
+ l += 0.13432 * sin(g);
1329
+ g = STR*(Ve - Ea - 2.*D + MP - 56.16);
1330
+ l -= 0.13122 * sin(g);
1331
+ g = STR*(Ve - Ea + MP + 54.36);
1332
+ l -= 0.12722 * sin(g);
1333
+ g = STR*(3.*(Ve - Ea) - MP + 433.8);
1334
+ l += 0.12539 * sin(g);
1335
+ g = STR*(Ea - Ju + MP + 4002.12);
1336
+ l += 0.10994 * sin(g);
1337
+ g = STR*(20.*Ve - 21.*Ea - 2.*D + MP - 317511.72);
1338
+ l += 0.10652 * sin(g);
1339
+ g = STR*(26.*Ve - 29.*Ea - MP + 270002.52);
1340
+ l += 0.10490 * sin(g);
1341
+ g = STR*(3.*Ve - 4.*Ea + D - MP - 322765.56);
1342
+ l += 0.10386 * sin(g);
1343
+ g = STR*(SWELP+648002.556);
1344
+ B = 8.04508 * sin(g);
1345
+ g = STR*(Ea+D+996048.252);
1346
+ B += 1.51021 * sin(g);
1347
+ g = STR*(f - MP + NF + 95554.332);
1348
+ B += 0.63037 * sin(g);
1349
+ g = STR*(f - MP - NF + 95553.792);
1350
+ B += 0.63014 * sin(g);
1351
+ g = STR*(SWELP - MP + 2.9);
1352
+ B += 0.45587 * sin(g);
1353
+ g = STR*(SWELP + MP + 2.5);
1354
+ B += -0.41573 * sin(g);
1355
+ g = STR*(SWELP - 2.0*NF + 3.2);
1356
+ B += 0.32623 * sin(g);
1357
+ g = STR*(SWELP - 2.0*D + 2.5);
1358
+ B += 0.29855 * sin(g);
1359
+ }
1360
+
1361
+ static void moon3()
1362
+ {
1363
+ /* terms in T^0 */
1364
+ moonpol[0] = 0.0;
1365
+ chewm( LR, NLR, 4, 1, moonpol );
1366
+ chewm( MB, NMB, 4, 3, moonpol );
1367
+ l += (((l4 * T + l3) * T + l2) * T + l1) * T * 1.0e-5;
1368
+ moonpol[0] = SWELP + l + 1.0e-4 * moonpol[0];
1369
+ moonpol[1] = 1.0e-4 * moonpol[1] + B;
1370
+ moonpol[2] = 1.0e-4 * moonpol[2] + 385000.52899; /* kilometers */
1371
+ }
1372
+
1373
+ /* Compute final ecliptic polar coordinates
1374
+ */
1375
+ static void moon4()
1376
+ {
1377
+ moonpol[2] /= AUNIT / 1000;
1378
+ moonpol[0] = STR * mods3600( moonpol[0] );
1379
+ moonpol[1] = STR * moonpol[1];
1380
+ B = moonpol[1];
1381
+ }
1382
+
1383
+ /* mean lunar node
1384
+ * J julian day
1385
+ * pol return array for position and velocity
1386
+ * (polar coordinates of ecliptic of date)
1387
+ */
1388
+ int swi_mean_node(double J, double *pol, char *serr)
1389
+ {
1390
+ #if 0
1391
+ double a, b, c;
1392
+ #endif
1393
+ char s[AS_MAXCH];
1394
+ T = (J-J2000)/36525.0;
1395
+ T2 = T*T;
1396
+ T3 = T*T2;
1397
+ T4 = T2*T2;
1398
+ /* with elements from swi_moshmoon2(), which are fitted to jpl-ephemeris */
1399
+ if (J < MOSHNDEPH_START || J > MOSHNDEPH_END) {
1400
+ if (serr != NULL) {
1401
+ sprintf(s, "jd %f outside mean node range %.2f .. %.2f ",
1402
+ J, MOSHNDEPH_START, MOSHNDEPH_END);
1403
+ if (strlen(serr) + strlen(s) < AS_MAXCH)
1404
+ strcat(serr, s);
1405
+ }
1406
+ return ERR;
1407
+ }
1408
+ mean_elements();
1409
+ /* longitude */
1410
+ pol[0] = swi_mod2PI((SWELP - NF) * STR);
1411
+ /* latitude */
1412
+ pol[1] = 0.0;
1413
+ /* distance */
1414
+ pol[2] = MOON_MEAN_DIST / AUNIT; /* or should it be derived from mean
1415
+ * orbital ellipse? */
1416
+ #if 0
1417
+ a = pol[0];
1418
+ /* Chapront, according to Meeus, German, p. 339 */
1419
+ pol[0] = 125.0445550 - 1934.1361849 * T + 0.0020762 * T2 +
1420
+ T3 / 467410 - T4 / 60616000;
1421
+ pol[0] = swi_mod2PI(pol[0] * DEGTORAD);
1422
+ c = pol[0];
1423
+ printf ("mean node\n");
1424
+ printf ("moshier de404 - chapront %f\"\n", (a-c) * RADTODEG * 3600);
1425
+ #endif
1426
+ return OK;
1427
+ }
1428
+
1429
+ /* mean lunar apogee ('dark moon', 'lilith')
1430
+ * J julian day
1431
+ * pol return array for position
1432
+ * (polar coordinates of ecliptic of date)
1433
+ * serr error return string
1434
+ */
1435
+ int swi_mean_apog(double J, double *pol, char *serr)
1436
+ {
1437
+ #if 0
1438
+ int i;
1439
+ double a, b;
1440
+ double x[3];
1441
+ #endif
1442
+ double node;
1443
+ char s[AS_MAXCH];
1444
+ T = (J-J2000)/36525.0;
1445
+ T2 = T*T;
1446
+ T3 = T*T2;
1447
+ T4 = T2*T2;
1448
+ /* with elements from swi_moshmoon2(), which are fitted to jpl-ephemeris */
1449
+ if (J < MOSHNDEPH_START || J > MOSHNDEPH_END) {
1450
+ if (serr != NULL) {
1451
+ sprintf(s, "jd %f outside mean apogee range %.2f .. %.2f ",
1452
+ J, MOSHNDEPH_START, MOSHNDEPH_END);
1453
+ if (strlen(serr) + strlen(s) < AS_MAXCH)
1454
+ strcat(serr, s);
1455
+ }
1456
+ return(ERR);
1457
+ }
1458
+ mean_elements();
1459
+ pol[0] = swi_mod2PI((SWELP - MP) * STR + PI);
1460
+ #if 0
1461
+ a = pol[0];
1462
+ /* Chapront, according to Meeus, German, p. 339 */
1463
+ pol[0] = 83.3532430 + 4069.0137111 * T - 0.0103238 * T2
1464
+ - T3 / 80053 + T4 / 18999000;
1465
+ pol[0] = swi_mod2PI(pol[0] * DEGTORAD + PI);
1466
+ b = pol[0];
1467
+ printf ("mean apogee\n");
1468
+ printf ("moshier de404 - chapront %f\"\n", (a-b) * RADTODEG * 3600);
1469
+ #endif
1470
+ pol[1] = 0;
1471
+ pol[2] = MOON_MEAN_DIST * (1 + MOON_MEAN_ECC) / AUNIT; /* apogee */
1472
+ #if 0
1473
+ pol[2] = 2 * MOON_MEAN_ECC * MOON_MEAN_DIST / AUNIT; /* 2nd focus */
1474
+ #endif
1475
+ /* Lilith or Dark Moon is either the empty focal point of the mean
1476
+ * lunar ellipse or, for some people, its apogee ("aphelion").
1477
+ * This is 180 degrees from the perigee.
1478
+ *
1479
+ * Since the lunar orbit is not in the ecliptic, the apogee must be
1480
+ * projected onto the ecliptic.
1481
+ * Joelle de Gravelaine has in her book "Lilith der schwarze Mond"
1482
+ * (Astrodata, 1990) an ephemeris which gives noon (12.00) positions
1483
+ * but does not project them onto the ecliptic.
1484
+ * This results in a mistake of several arc minutes.
1485
+ *
1486
+ * There is also another problem. The other focal point doesn't
1487
+ * coincide with the geocenter but with the barycenter of the
1488
+ * earth-moon-system. The difference is about 4700 km. If one
1489
+ * took this into account, it would result in an oscillation
1490
+ * of the Black Moon. If defined as the apogee, this oscillation
1491
+ * would be about +/- 40 arcmin.
1492
+ * If defined as the second focus, the effect is very large:
1493
+ * +/- 6 deg!
1494
+ * We neglect this influence.
1495
+ */
1496
+ /* apogee is now projected onto ecliptic */
1497
+ node = (SWELP - NF) * STR;
1498
+ pol[0] = swi_mod2PI(pol[0] - node);
1499
+ swi_polcart(pol, pol);
1500
+ swi_coortrf(pol, pol, -MOON_MEAN_INCL * DEGTORAD);
1501
+ swi_cartpol(pol, pol);
1502
+ pol[0] = swi_mod2PI(pol[0] + node);
1503
+ #if 0
1504
+ /* speed */
1505
+ mean_elements(T-PLAN_SPEED_INTV, &SWELP, &MP, &NF, &M, &D);
1506
+ pol[3] = swi_mod2PI((SWELP - MP) * STR + PI);
1507
+ pol[4] = 0;
1508
+ pol[5] = MOON_MEAN_DIST * (1 + MOON_MEAN_ECC) / AUNIT; /* apogee */
1509
+ #if 0
1510
+ pol[2] = 2 * MOON_MEAN_ECC * MOON_MEAN_DIST / AUNIT; /* 2nd focus */
1511
+ #endif
1512
+ node = (SWELP - NF) * STR;
1513
+ pol[3] = swi_mod2PI(pol[3] - node);
1514
+ swi_polcart(pol+3, pol+3);
1515
+ swi_coortrf(pol+3, pol+3, -MOON_MEAN_INCL * DEGTORAD);
1516
+ swi_cartpol(pol+3, pol+3);
1517
+ pol[3] = swi_mod2PI(pol[3] + node);
1518
+ for (i = 0; i <= 2; i++)
1519
+ pol[3+i] = pol[i] - pol[3+i];
1520
+ pol[3] = swi_mod2PI(pol[3]);
1521
+ #endif
1522
+ return OK;
1523
+ }
1524
+
1525
+ /* Program to step through the perturbation table
1526
+ */
1527
+ static void chewm(short *pt, int nlines, int nangles, int typflg, double *ans )
1528
+ {
1529
+ int i, j, k, k1, m;
1530
+ double cu, su, cv, sv, ff;
1531
+ for( i=0; i<nlines; i++ ) {
1532
+ k1 = 0;
1533
+ sv = 0.0;
1534
+ cv = 0.0;
1535
+ for( m=0; m<nangles; m++ ) {
1536
+ j = *pt++; /* multiple angle factor */
1537
+ if( j ) {
1538
+ k = j;
1539
+ if( j < 0 ) k = -k; /* make angle factor > 0 */
1540
+ /* sin, cos (k*angle) from lookup table */
1541
+ su = ss[m][k-1];
1542
+ cu = cc[m][k-1];
1543
+ if( j < 0 ) su = -su; /* negative angle factor */
1544
+ if( k1 == 0 ) {
1545
+ /* Set sin, cos of first angle. */
1546
+ sv = su;
1547
+ cv = cu;
1548
+ k1 = 1;
1549
+ }
1550
+ else {
1551
+ /* Combine angles by trigonometry. */
1552
+ ff = su*cv + cu*sv;
1553
+ cv = cu*cv - su*sv;
1554
+ sv = ff;
1555
+ }
1556
+ }
1557
+ }
1558
+ /* Accumulate
1559
+ */
1560
+ switch( typflg ) {
1561
+ /* large longitude and radius */
1562
+ case 1:
1563
+ j = *pt++;
1564
+ k = *pt++;
1565
+ ans[0] += (10000.0 * j + k) * sv;
1566
+ j = *pt++;
1567
+ k = *pt++;
1568
+ if( k ) ans[2] += (10000.0 * j + k) * cv;
1569
+ break;
1570
+ /* longitude and radius */
1571
+ case 2:
1572
+ j = *pt++;
1573
+ k = *pt++;
1574
+ ans[0] += j * sv;
1575
+ ans[2] += k * cv;
1576
+ break;
1577
+ /* large latitude */
1578
+ case 3:
1579
+ j = *pt++;
1580
+ k = *pt++;
1581
+ ans[1] += ( 10000.0*j + k)*sv;
1582
+ break;
1583
+ /* latitude */
1584
+ case 4:
1585
+ j = *pt++;
1586
+ ans[1] += j * sv;
1587
+ break;
1588
+ }
1589
+ }
1590
+ }
1591
+
1592
+ /* Prepare lookup table of sin and cos ( i*Lj )
1593
+ * for required multiple angles
1594
+ */
1595
+ static void sscc(int k, double arg, int n )
1596
+ {
1597
+ double cu, su, cv, sv, s;
1598
+ int i;
1599
+ su = sin(arg);
1600
+ cu = cos(arg);
1601
+ ss[k][0] = su; /* sin(L) */
1602
+ cc[k][0] = cu; /* cos(L) */
1603
+ sv = 2.0*su*cu;
1604
+ cv = cu*cu - su*su;
1605
+ ss[k][1] = sv; /* sin(2L) */
1606
+ cc[k][1] = cv;
1607
+ for( i=2; i<n; i++ ) {
1608
+ s = su*cv + cu*sv;
1609
+ cv = cu*cv - su*sv;
1610
+ sv = s;
1611
+ ss[k][i] = sv; /* sin( i+1 L ) */
1612
+ cc[k][i] = cv;
1613
+ }
1614
+ }
1615
+
1616
+ /* converts from polar coordinates of ecliptic of date
1617
+ * to cartesian coordinates of equator 2000
1618
+ * tjd date
1619
+ * x array of position
1620
+ */
1621
+ static void ecldat_equ2000(double tjd, double *xpm) {
1622
+ /* cartesian */
1623
+ swi_polcart(xpm, xpm);
1624
+ /* equatorial */
1625
+ swi_coortrf2(xpm, xpm, -swed.oec.seps, swed.oec.ceps);
1626
+ /* j2000 */
1627
+ swi_precess(xpm, tjd, J_TO_J2000);/**/
1628
+ }
1629
+
1630
+ /* Reduce arc seconds modulo 360 degrees
1631
+ * answer in arc seconds
1632
+ */
1633
+ static double mods3600(double x)
1634
+ {
1635
+ double lx;
1636
+ lx = x;
1637
+ lx = lx - 1296000.0 * floor( lx/1296000.0 );
1638
+ return( lx );
1639
+ }
1640
+
1641
+ void swi_mean_lunar_elements(double tjd,
1642
+ double *node, double *dnode,
1643
+ double *peri, double *dperi)
1644
+ {
1645
+ T = (tjd - J2000) / 36525.0;
1646
+ T2 = T*T;
1647
+ mean_elements();
1648
+ *node = swe_degnorm((SWELP - NF) * STR * RADTODEG);
1649
+ *peri = swe_degnorm((SWELP - MP) * STR * RADTODEG);
1650
+ T -= 1.0 / 36525;
1651
+ mean_elements();
1652
+ *dnode = swe_degnorm(*node - (SWELP - NF) * STR * RADTODEG);
1653
+ *dnode -= 360;
1654
+ *dperi = swe_degnorm(*peri - (SWELP - MP) * STR * RADTODEG);
1655
+ }
1656
+
1657
+ static void mean_elements()
1658
+ {
1659
+ double fracT = fmod(T, 1);
1660
+ /* Mean anomaly of sun = l' (J. Laskar) */
1661
+ /*M = mods3600(129596581.038354 * T + 1287104.76154);*/
1662
+ M = mods3600(129600000.0 * fracT - 3418.961646 * T + 1287104.76154);
1663
+ M += ((((((((
1664
+ 1.62e-20 * T
1665
+ - 1.0390e-17 ) * T
1666
+ - 3.83508e-15 ) * T
1667
+ + 4.237343e-13 ) * T
1668
+ + 8.8555011e-11 ) * T
1669
+ - 4.77258489e-8 ) * T
1670
+ - 1.1297037031e-5 ) * T
1671
+ + 1.4732069041e-4 ) * T
1672
+ - 0.552891801772 ) * T2;
1673
+ #ifdef MOSH_MOON_200
1674
+ /* Mean distance of moon from its ascending node = F */
1675
+ NF = mods3600( 1739527263.0983 * T + 335779.55755 );
1676
+ /* Mean anomaly of moon = l */
1677
+ MP = mods3600( 1717915923.4728 * T + 485868.28096 );
1678
+ /* Mean elongation of moon = D */
1679
+ D = mods3600( 1602961601.4603 * T + 1072260.73512 );
1680
+ /* Mean longitude of moon */
1681
+ SWELP = mods3600( 1732564372.83264 * T + 785939.95571 );
1682
+ /* Higher degree secular terms found by least squares fit */
1683
+ NF += (((((z[5] *T+z[4] )*T + z[3] )*T + z[2] )*T + z[1] )*T + z[0] )*T2;
1684
+ MP += (((((z[11]*T+z[10])*T + z[9] )*T + z[8] )*T + z[7] )*T + z[6] )*T2;
1685
+ D += (((((z[17]*T+z[16])*T + z[15])*T + z[14])*T + z[13])*T + z[12])*T2;
1686
+ SWELP += (((((z[23]*T+z[22])*T + z[21])*T + z[20])*T + z[19])*T + z[18])*T2;
1687
+ #else
1688
+ /* Mean distance of moon from its ascending node = F */
1689
+ /*NF = mods3600((1739527263.0983 - 2.079419901760e-01) * T + 335779.55755);*/
1690
+ NF = mods3600(1739232000.0 * fracT + 295263.0983 * T - 2.079419901760e-01 * T + 335779.55755);
1691
+ /* Mean anomaly of moon = l */
1692
+ /*MP = mods3600((1717915923.4728 - 2.035946368532e-01) * T + 485868.28096);*/
1693
+ MP = mods3600(1717200000.0 * fracT + 715923.4728 * T - 2.035946368532e-01 * T + 485868.28096);
1694
+ /* Mean elongation of moon = D */
1695
+ /*D = mods3600((1602961601.4603 + 3.962893294503e-01) * T + 1072260.73512);*/
1696
+ D = mods3600(1601856000.0 * fracT + 1105601.4603 * T + 3.962893294503e-01 * T + 1072260.73512);
1697
+ /* Mean longitude of moon, referred to the mean ecliptic and equinox of date */
1698
+ /*SWELP = mods3600((1732564372.83264 - 6.784914260953e-01) * T + 785939.95571);*/
1699
+ SWELP = mods3600(1731456000.0 * fracT + 1108372.83264 * T - 6.784914260953e-01 * T + 785939.95571);
1700
+ /* Higher degree secular terms found by least squares fit */
1701
+ NF += ((z[2]*T + z[1])*T + z[0])*T2;
1702
+ MP += ((z[5]*T + z[4])*T + z[3])*T2;
1703
+ D += ((z[8]*T + z[7])*T + z[6])*T2;
1704
+ SWELP += ((z[11]*T + z[10])*T + z[9])*T2;
1705
+ #endif /* ! MOSH_MOON_200 */
1706
+ /* sensitivity of mean elements
1707
+ * delta argument = scale factor times delta amplitude (arcsec)
1708
+ * cos l 9.0019 = mean eccentricity
1709
+ * cos 2D 43.6
1710
+ * cos F 11.2 (latitude term)
1711
+ */
1712
+ }
1713
+
1714
+ void mean_elements_pl()
1715
+ {
1716
+ /* Mean longitudes of planets (Laskar, Bretagnon) */
1717
+ Ve = mods3600( 210664136.4335482 * T + 655127.283046 );
1718
+ Ve += ((((((((
1719
+ -9.36e-023 * T
1720
+ - 1.95e-20 ) * T
1721
+ + 6.097e-18 ) * T
1722
+ + 4.43201e-15 ) * T
1723
+ + 2.509418e-13 ) * T
1724
+ - 3.0622898e-10 ) * T
1725
+ - 2.26602516e-9 ) * T
1726
+ - 1.4244812531e-5 ) * T
1727
+ + 0.005871373088 ) * T2;
1728
+ Ea = mods3600( 129597742.26669231 * T + 361679.214649 );
1729
+ Ea += (((((((( -1.16e-22 * T
1730
+ + 2.976e-19 ) * T
1731
+ + 2.8460e-17 ) * T
1732
+ - 1.08402e-14 ) * T
1733
+ - 1.226182e-12 ) * T
1734
+ + 1.7228268e-10 ) * T
1735
+ + 1.515912254e-7 ) * T
1736
+ + 8.863982531e-6 ) * T
1737
+ - 2.0199859001e-2 ) * T2;
1738
+ Ma = mods3600( 68905077.59284 * T + 1279559.78866 );
1739
+ Ma += (-1.043e-5*T + 9.38012e-3)*T2;
1740
+ Ju = mods3600( 10925660.428608 * T + 123665.342120 );
1741
+ Ju += (1.543273e-5*T - 3.06037836351e-1)*T2;
1742
+ Sa = mods3600( 4399609.65932 * T + 180278.89694 );
1743
+ Sa += (( 4.475946e-8*T - 6.874806E-5 ) * T + 7.56161437443E-1)*T2;
1744
+ }
1745
+
1746
+ /* Calculate geometric coordinates of true interpolated Moon apsides
1747
+ */
1748
+ int swi_intp_apsides(double J, double *pol, int ipli)
1749
+ {
1750
+ double dd;
1751
+ double rsv[3];
1752
+ double sNF, sD, sLP, sMP, sM, sVe, sEa, sMa, sJu, sSa, fM, fVe, fEa, fMa, fJu, fSa, cMP, zMP, fNF, fD, fLP;
1753
+ double dMP, mLP, mNF, mD, mMP;
1754
+ int i, ii, iii, niter = 4; /* niter: silence compiler warning */
1755
+ ii=1;
1756
+ zMP=27.55454988;
1757
+ fNF = 27.212220817/zMP;/**/
1758
+ fD = 29.530588835/zMP;/**/
1759
+ fLP = 27.321582/zMP;/**/
1760
+ fM = 365.2596359/zMP;
1761
+ fVe = 224.7008001/zMP;
1762
+ fEa = 365.2563629/zMP;
1763
+ fMa = 686.9798519/zMP;
1764
+ fJu = 4332.589348/zMP;
1765
+ fSa = 10759.22722/zMP;
1766
+ T = (J-J2000)/36525.0;
1767
+ T2 = T*T;
1768
+ T4 = T2*T2;
1769
+ mean_elements();
1770
+ mean_elements_pl();
1771
+ sNF = NF;
1772
+ sD = D;
1773
+ sLP = SWELP;
1774
+ sMP = MP;
1775
+ sM = M ;
1776
+ sVe = Ve;
1777
+ sEa = Ea;
1778
+ sMa = Ma;
1779
+ sJu = Ju;
1780
+ sSa = Sa;
1781
+ sNF = mods3600(NF);
1782
+ sD = mods3600(D);
1783
+ sLP = mods3600(SWELP);
1784
+ sMP = mods3600(MP);
1785
+ if (ipli == SEI_INTP_PERG) {MP = 0.0; niter = 5;}
1786
+ if (ipli == SEI_INTP_APOG) {MP = 648000.0; niter = 4;}
1787
+ cMP = 0;
1788
+ dd = 18000.0;
1789
+ for (iii= 0; iii<=niter; iii++) {/**/
1790
+ dMP = sMP - MP;
1791
+ mLP = sLP - dMP;
1792
+ mNF = sNF - dMP;
1793
+ mD = sD - dMP;
1794
+ mMP = sMP - dMP;
1795
+ for (ii = 0; ii <=2; ii++) {/**/
1796
+ MP = mMP + (ii-1)*dd; /**/
1797
+ NF = mNF + (ii-1)*dd/fNF;
1798
+ D = mD + (ii-1)*dd/fD;
1799
+ SWELP = mLP + (ii-1)*dd/fLP;
1800
+ M = sM + (ii-1)*dd/fM ;
1801
+ Ve = sVe + (ii-1)*dd/fVe;
1802
+ Ea = sEa + (ii-1)*dd/fEa;
1803
+ Ma = sMa + (ii-1)*dd/fMa;
1804
+ Ju = sJu + (ii-1)*dd/fJu;
1805
+ Sa = sSa + (ii-1)*dd/fSa;
1806
+ moon1();
1807
+ moon2();
1808
+ moon3();
1809
+ moon4();
1810
+ if (ii==1) {
1811
+ for( i=0; i<3; i++ ) pol[i] = moonpol[i];
1812
+ }
1813
+ rsv[ii] = moonpol[2];
1814
+ }
1815
+ cMP = (1.5*rsv[0] - 2*rsv[1] + 0.5*rsv[2]) / (rsv[0] + rsv[2] - 2*rsv[1]);/**/
1816
+ cMP *= dd;
1817
+ cMP = cMP - dd;
1818
+ mMP += cMP;
1819
+ MP = mMP;
1820
+ dd /= 10;
1821
+ }
1822
+ return(0);
1823
+ }
1824
+