@swisseph/node 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,694 @@
1
+ /********************************************************************
2
+ sweephe4.c
3
+ access structures and functions for ephemeris file ep4_
4
+ a fast precomputed ephemeris
5
+ *********************************************************************/
6
+ /* Copyright (C) 1997 - 2021 Astrodienst AG, Switzerland. All rights reserved.
7
+
8
+ License conditions
9
+ ------------------
10
+
11
+ This file is part of Swiss Ephemeris.
12
+
13
+ Swiss Ephemeris is distributed with NO WARRANTY OF ANY KIND. No author
14
+ or distributor accepts any responsibility for the consequences of using it,
15
+ or for whether it serves any particular purpose or works at all, unless he
16
+ or she says so in writing.
17
+
18
+ Swiss Ephemeris is made available by its authors under a dual licensing
19
+ system. The software developer, who uses any part of Swiss Ephemeris
20
+ in his or her software, must choose between one of the two license models,
21
+ which are
22
+ a) GNU Affero General Public License (AGPL)
23
+ b) Swiss Ephemeris Professional License
24
+
25
+ The choice must be made before the software developer distributes software
26
+ containing parts of Swiss Ephemeris to others, and before any public
27
+ service using the developed software is activated.
28
+
29
+ If the developer choses the AGPL software license, he or she must fulfill
30
+ the conditions of that license, which includes the obligation to place his
31
+ or her whole software project under the AGPL or a compatible license.
32
+ See https://www.gnu.org/licenses/agpl-3.0.html
33
+
34
+ If the developer choses the Swiss Ephemeris Professional license,
35
+ he must follow the instructions as found in http://www.astro.com/swisseph/
36
+ and purchase the Swiss Ephemeris Professional Edition from Astrodienst
37
+ and sign the corresponding license contract.
38
+
39
+ The License grants you the right to use, copy, modify and redistribute
40
+ Swiss Ephemeris, but only under certain conditions described in the License.
41
+ Among other things, the License requires that the copyright notices and
42
+ this notice be preserved on all copies.
43
+
44
+ Authors of the Swiss Ephemeris: Dieter Koch and Alois Treindl
45
+
46
+ The authors of Swiss Ephemeris have no control or influence over any of
47
+ the derived works, i.e. over software or services created by other
48
+ programmers which use Swiss Ephemeris functions.
49
+
50
+ The names of the authors or of the copyright holder (Astrodienst) must not
51
+ be used for promoting any software, product or service which uses or contains
52
+ the Swiss Ephemeris. This copyright notice is the ONLY place where the
53
+ names of the authors can legally appear, except in cases where they have
54
+ given special permission in writing.
55
+
56
+ The trademarks 'Swiss Ephemeris' and 'Swiss Ephemeris inside' may be used
57
+ for promoting such software, products or services.
58
+ */
59
+
60
+
61
+ # include "swephexp.h"
62
+ # include "sweephe4.h"
63
+ # include <string.h>
64
+
65
+ # define INVALID_BASE 2000000000L
66
+ # define EPBS (2 * NDB) /* buffer size is 20 days */
67
+ # define EP_MIN_IX 2 /* load buffer when index below this */
68
+ # define EP_MAX_IX (EPBS - 4) /* load buffer when index above this */
69
+
70
+ FILE *ephfp = NULL;
71
+ const int qod[EP_NP] = {5,5,5,5,5,3,3,3,3,3,3,5,3,3,3};
72
+
73
+ static void inpolq_l(int n, int o, double p, centisec *x,
74
+ centisec *axu, centisec *adxu);
75
+ static int inpolq(int n, int o, double p, double *x,
76
+ double *axu, double *adxu);
77
+ static int ephe4_unpack(int jdl, int pflag, centisec lon[][EPBS], int i0,
78
+ char *errs);
79
+ static int ephe4_unpack_d(int jdl, int pflag, double lon[][EPBS], int i0,
80
+ char *errs);
81
+ static char *my_makepath(char *d, char *s);
82
+
83
+ # ifdef INTEL_BYTE_ORDER
84
+ /********************************************************************/
85
+ void shortreorder (UCHAR *p, int n)
86
+ /* p points to memory filled with 16-bit values; for
87
+ each of the values the seqeuence of the two bytes
88
+ has to be reversed, to translate HP-UX and VAX
89
+ ordering to MSDOS/Turboc ordering */
90
+ {
91
+ int i;
92
+ unsigned char c0;
93
+ for (i = 0; i < n; i += 2, p += 2) {
94
+ c0 = *p;
95
+ *p = *(p+1);
96
+ *(p + 1) = c0;
97
+ }
98
+ }
99
+ # endif
100
+
101
+
102
+ /****************************************************
103
+ read ephe file and return a pointer to normalized positions
104
+ for planets specified by pflag at julday jdl;
105
+ If the reading failes, NULL is returned and
106
+ an error text of max. 79 char in errtext, except when errtext = NULL.
107
+ If calc is used and succeeds, a message is put into errtext, otherwise
108
+ errtext is empty.
109
+ Attention: jd is an absolute Julian date
110
+ flag bits defined in sweephe4.h, onl
111
+ ****************************************************/
112
+ centisec *ephread(double jd, int plalist, int flag, char *errtext)
113
+ {
114
+ static int jdbase = INVALID_BASE;
115
+ static int lastplalist = 0;
116
+ static centisec lon[EP_NP][EPBS]; /* buffer for 20 days unpacked ephe */
117
+ static centisec out[2 * EP_NP]; /* buffer for return longitude
118
+ and return speed */
119
+ int p, pf;
120
+ int ix, jdlong, iflagret;
121
+ centisec clp;
122
+ double jfract;
123
+ double x[6];
124
+ if (errtext != NULL)
125
+ *errtext = '\0';
126
+ if (plalist == 0)
127
+ plalist = EP_ALL_BITS; /* default: all logitudes, no speeds */
128
+ /*
129
+ * we must determine when to reload the lon buffer: if the contents do
130
+ * not allow immediate interpolation or if the plalist selection has
131
+ * changed since the last call.
132
+ */
133
+ if ((plalist & lastplalist) != plalist) { /* new set is not contained in old */
134
+ jdbase = INVALID_BASE;
135
+ }
136
+ lastplalist = plalist;
137
+ jdlong = floor(jd - 0.5);
138
+ ix = jdlong - jdbase;
139
+ if (ix < EP_MIN_IX || ix >= EPBS) { /* must reload full buffer */
140
+ jdbase = ((jdlong - EP_MIN_IX) / NDB) * NDB; /* new base */
141
+ if (jdbase > jdlong - EP_MIN_IX) jdbase -= NDB; /* fix bug for neg. */
142
+ if (ephe4_unpack (jdbase, plalist, lon, 0, errtext) != OK)
143
+ goto err_exit;
144
+ if (ephe4_unpack (jdbase + NDB, plalist, lon, 0 + NDB, errtext) != OK)
145
+ goto err_exit;
146
+ ix = jdlong - jdbase;
147
+ } else if (ix > EP_MAX_IX) { /* must shift upper half down
148
+ and reload upper half of buffer */
149
+ jdbase += NDB; /* new base */
150
+ for (p = 0; p < EP_NP; p++)
151
+ memcpy (&lon[p][0], &lon[p][NDB], NDB * sizeof(centisec));
152
+ if (ephe4_unpack (jdbase + NDB, plalist, lon, 0 + NDB, errtext) != OK)
153
+ goto err_exit;
154
+ ix = jdlong - jdbase;
155
+ }
156
+ jfract = jd - 0.5 - jdlong;
157
+ /*
158
+ * we use the interpolator even for jfract = 0, because it delivers
159
+ * the speed term. The computation overhead is unimportant
160
+ * in any case.
161
+ */
162
+ for (p = 0, pf = 1; p < EP_NP; p++, pf = pf << 1)
163
+ if ((plalist & pf) != 0) {
164
+ inpolq_l((int) ix, qod[p], jfract, &(lon[p][0]), &(out[p]), &clp);
165
+ if (p <= PLACALC_CHIRON) { /* normalize all except ecl and nut */
166
+ if (out[p] < 0)
167
+ out[p] += DEG360;
168
+ else if (out[p] >= DEG360)
169
+ out[p] -= DEG360;
170
+ }
171
+ #ifdef DEBUG
172
+ fprintf(stderr,"ephread p=%d, lon=%.3lf\n", p, out[p] * CS2DEG);
173
+ #endif
174
+ if (flag & EP_BIT_SPEED)
175
+ out[p+EP_NP] = clp;
176
+ }
177
+ return out;
178
+ err_exit:
179
+ jdbase = INVALID_BASE;
180
+ lastplalist = 0;
181
+ if ((flag & EP_BIT_MUST_USE_EPHE) == 0) { /* try using calc */
182
+ int sweflag = 0;
183
+ char serr[AS_MAXCH];
184
+ if (flag & EP_BIT_SPEED)
185
+ sweflag = SEFLG_SPEED;
186
+ if (errtext != NULL)
187
+ sprintf(errtext,"ephread failed for jd=%f; used swe_calc().", jd);
188
+ for (p = 0, pf = 1; p < PLACALC_CALC_N; p++, pf = pf << 1) {
189
+ if ((plalist & pf) != 0) {
190
+ if ((iflagret = swe_calc(jd, ephe_plac2swe(p), sweflag, x, serr)) != ERR) {
191
+ out[p] = swe_d2l(x[0] * DEG);
192
+ if (flag & EP_BIT_SPEED)
193
+ out[p + EP_NP] = swe_d2l(x[3] * DEG);
194
+ if (out[p] < 0)
195
+ out[p] += DEG360;
196
+ else if (out[p] >= DEG360)
197
+ out[p] -= DEG360;
198
+ } else {
199
+ swe_close();
200
+ if (errtext != NULL)
201
+ strcat(errtext," calc failed too.");
202
+ return NULL;
203
+ }
204
+ }
205
+ }
206
+ if ((iflagret = swe_calc(jd, SE_ECL_NUT, 0, x, serr)) == ERR) {
207
+ swe_close();
208
+ sprintf(errtext, "error in swe_calc() %s\n", serr);
209
+ return NULL;
210
+ }
211
+ out[EP_ECL_INDEX] = swe_d2l(x[0] * DEG); /* true ecliptic */
212
+ out[EP_NUT_INDEX] = swe_d2l(x[2] * DEG); /* nutation */
213
+ out[EP_ECL_INDEX + EP_NP] = 0;
214
+ out[EP_NUT_INDEX + EP_NP] = 0;
215
+ return out;
216
+ }
217
+ return NULL;
218
+ } /* ephread */
219
+
220
+ // same in double
221
+ double *dephread2(double jd, int plalist, int flag, char *errtext)
222
+ {
223
+ static int jdbase = INVALID_BASE;
224
+ static int lastplalist = 0;
225
+ static double lon[EP_NP][EPBS]; // buffer for 20 days unpacked ephe
226
+ static double out[2 * EP_NP]; // buffer for return longitude and return speed
227
+ int p, pf;
228
+ int ix, jdlong, iflagret;
229
+ double lp;
230
+ double jfract;
231
+ double x[6];
232
+ if (errtext != NULL)
233
+ *errtext = '\0';
234
+ if (plalist == 0)
235
+ plalist = EP_ALL_BITS; /* default: all logitudes, no speeds */
236
+ /*
237
+ * we must determine when to reload the lon buffer: if the contents do
238
+ * not allow immediate interpolation or if the plalist selection has
239
+ * changed since the last call.
240
+ */
241
+ if ((plalist & lastplalist) != plalist) { /* new set is not contained in old */
242
+ jdbase = INVALID_BASE;
243
+ }
244
+ lastplalist = plalist;
245
+ jdlong = floor(jd - 0.5);
246
+ ix = jdlong - jdbase;
247
+ if (ix < EP_MIN_IX || ix >= EPBS) { /* must reload full buffer */
248
+ jdbase = ((jdlong - EP_MIN_IX) / NDB) * NDB; /* new base */
249
+ if (jdbase > jdlong - EP_MIN_IX) jdbase -= NDB; /* fix bug for neg. */
250
+ if (ephe4_unpack_d(jdbase, plalist, lon, 0, errtext) != OK)
251
+ goto err_exit;
252
+ if (ephe4_unpack_d(jdbase + NDB, plalist, lon, 0 + NDB, errtext) != OK)
253
+ goto err_exit;
254
+ ix = jdlong - jdbase;
255
+ } else if (ix > EP_MAX_IX) { /* must shift upper half down
256
+ and reload upper half of buffer */
257
+ jdbase += NDB; /* new base */
258
+ for (p = 0; p < EP_NP; p++)
259
+ memcpy(&lon[p][0], &lon[p][NDB], NDB * sizeof(double));
260
+ if (ephe4_unpack_d(jdbase + NDB, plalist, lon, 0 + NDB, errtext) != OK)
261
+ goto err_exit;
262
+ ix = jdlong - jdbase;
263
+ }
264
+ jfract = jd - 0.5 - jdlong;
265
+ /*
266
+ * we use the interpolator even for jfract = 0, because it delivers
267
+ * the speed term. The computation overhead is unimportant
268
+ * in any case.
269
+ */
270
+ for (p = 0, pf = 1; p < EP_NP; p++, pf = pf << 1)
271
+ if ((plalist & pf) != 0) {
272
+ inpolq((int) ix, qod[p], jfract, &(lon[p][0]), &(out[p]), &lp);
273
+ if (p <= PLACALC_CHIRON) { /* normalize all except ecl and nut */
274
+ if (out[p] < 0)
275
+ out[p] += 360.0;
276
+ else if (out[p] >= 360.0)
277
+ out[p] -= 360.0;
278
+ }
279
+ #ifdef DEBUG
280
+ fprintf(stderr,"ephread p=%d, lon=%.3lf\n", p, out[p]);
281
+ #endif
282
+ if (flag & EP_BIT_SPEED)
283
+ out[p+EP_NP] = lp;
284
+ }
285
+ return out;
286
+ err_exit:
287
+ jdbase = INVALID_BASE;
288
+ lastplalist = 0;
289
+ if ((flag & EP_BIT_MUST_USE_EPHE) == 0) { /* try using calc */
290
+ int sweflag = 0;
291
+ char serr[AS_MAXCH];
292
+ if (flag & EP_BIT_SPEED)
293
+ sweflag = SEFLG_SPEED;
294
+ if (errtext != NULL)
295
+ sprintf(errtext,"ephread failed for jd=%f; used swe_calc().", jd);
296
+ for (p = 0, pf = 1; p < PLACALC_CALC_N; p++, pf = pf << 1) {
297
+ if ((plalist & pf) != 0) {
298
+ if ((iflagret = swe_calc(jd, ephe_plac2swe(p), sweflag, x, serr)) != ERR) {
299
+ out[p] = x[0];
300
+ if (flag & EP_BIT_SPEED)
301
+ out[p + EP_NP] = x[3];
302
+ if (out[p] < 0)
303
+ out[p] += 360.0;
304
+ else if (out[p] >= 360.0)
305
+ out[p] -= 360.0;
306
+ } else {
307
+ swe_close();
308
+ if (errtext != NULL)
309
+ strcat(errtext," calc failed too.");
310
+ return NULL;
311
+ }
312
+ }
313
+ }
314
+ if ((iflagret = swe_calc(jd, SE_ECL_NUT, 0, x, serr)) == ERR) {
315
+ swe_close();
316
+ sprintf(errtext, "error in swe_calc() %s\n", serr);
317
+ return NULL;
318
+ }
319
+ out[EP_ECL_INDEX] = x[0]; /* true ecliptic */
320
+ out[EP_NUT_INDEX] = x[2]; /* nutation */
321
+ out[EP_ECL_INDEX + EP_NP] = 0;
322
+ out[EP_NUT_INDEX + EP_NP] = 0;
323
+ return out;
324
+ }
325
+ return NULL;
326
+ }
327
+
328
+ /****************************************************
329
+ unpack an ephe file block specified by jlong
330
+ and the planets specified by pflag into
331
+ the array lon[p][EPBS], starting at index i0.
332
+ jdl is (long) floor(full julian date);
333
+ If the reading failes, ERR is returned and
334
+ an error text of max. 79 char in errs, except when errs = NULL.
335
+ ****************************************************/
336
+ static int ephe4_unpack(int jdl, int plalist, centisec lon[][EPBS], int i0,char *errs)
337
+ {
338
+ int p, i, pf;
339
+ centisec l_ret, d_ret;
340
+ struct ep4 e;
341
+ if (eph4_posit (jdl, FALSE, errs) != OK)
342
+ return (ERR);
343
+ if (fread (&e, sizeof(struct ep4), 1, ephfp) != 1) {
344
+ if (errs != NULL)
345
+ sprintf (errs, "ephe4_unpack: fread for jd=%d failed", jdl);
346
+ return (ERR);
347
+ }
348
+ #ifdef INTEL_BYTE_ORDER
349
+ shortreorder((UCHAR *) &e, sizeof(struct ep4));
350
+ #endif
351
+ for (p = PLACALC_SUN, pf = 1; p <= PLACALC_CHIRON; p++, pf = pf << 1) {
352
+ if ((plalist & pf) == 0) continue;
353
+ l_ret = e.elo[p].p0m * 6000L + e.elo[p].p0s; /* csec */
354
+ d_ret = e.elo[p].pd1m * 6000L + e.elo[p].pd1s; /* csec */
355
+ lon[p][i0] = l_ret;
356
+ l_ret += d_ret;
357
+ if (l_ret < 0) {
358
+ lon[p][i0+1] = l_ret + DEG360;
359
+ } else if (l_ret >= DEG360) {
360
+ lon[p][i0+1] = l_ret - DEG360;
361
+ } else {
362
+ lon[p][i0+1] = l_ret;
363
+ }
364
+ for (i = 2; i < NDB; i++) {
365
+ if (p == PLACALC_MOON || p == PLACALC_MERCURY)
366
+ d_ret += e.elo[p].pd2[i-2] * 10L;
367
+ else
368
+ d_ret += e.elo[p].pd2[i-2];
369
+ l_ret += d_ret;
370
+ if (l_ret < 0) {
371
+ lon[p][i0+i] = l_ret + DEG360;
372
+ } else if (l_ret >= DEG360) {
373
+ lon[p][i0+i] = l_ret - DEG360;
374
+ } else {
375
+ lon[p][i0+i] = l_ret;
376
+ }
377
+ }
378
+ } /* for p */
379
+ if ( plalist & EP_ECL_BIT) { /* unpack ecl */
380
+ l_ret = e.ecl0m * 6000L + e.ecl0s;
381
+ lon[EP_ECL_INDEX][i0] = l_ret;
382
+ for (i = 1; i < NDB; i++)
383
+ lon[EP_ECL_INDEX][i0+i] = l_ret + e.ecld1[i-1];
384
+ }
385
+ if ( plalist & EP_NUT_BIT) { /* unpack nut */
386
+ for (i = 0; i < NDB; i++)
387
+ lon[EP_NUT_INDEX][i0+i] = e.nuts[i] ;
388
+ }
389
+ return OK;
390
+ } /* ephe4_unpack */
391
+
392
+ // same in double
393
+ static int ephe4_unpack_d(int jdl, int plalist, double lon[][EPBS], int i0,char *errs)
394
+ {
395
+ int p, i, pf;
396
+ double l_ret, d_ret;
397
+ struct ep4 e;
398
+ if (eph4_posit (jdl, FALSE, errs) != OK)
399
+ return (ERR);
400
+ if (fread (&e, sizeof(struct ep4), 1, ephfp) != 1) {
401
+ if (errs != NULL)
402
+ sprintf (errs, "ephe4_unpack: fread for jd=%d failed", jdl);
403
+ return (ERR);
404
+ }
405
+ #ifdef INTEL_BYTE_ORDER
406
+ shortreorder((UCHAR *) &e, sizeof(struct ep4));
407
+ #endif
408
+ for (p = PLACALC_SUN, pf = 1; p <= PLACALC_CHIRON; p++, pf = pf << 1) {
409
+ if ((plalist & pf) == 0) continue;
410
+ l_ret = (e.elo[p].p0m * 6000 + e.elo[p].p0s) * CS2DEG;
411
+ d_ret = (e.elo[p].pd1m * 6000 + e.elo[p].pd1s) * CS2DEG;
412
+ lon[p][i0] = l_ret;
413
+ l_ret += d_ret;
414
+ if (l_ret < 0) {
415
+ lon[p][i0+1] = l_ret + 360.0;
416
+ } else if (l_ret >= 360.0) {
417
+ lon[p][i0+1] = l_ret - 360.0;
418
+ } else {
419
+ lon[p][i0+1] = l_ret;
420
+ }
421
+ for (i = 2; i < NDB; i++) {
422
+ if (p == PLACALC_MOON || p == PLACALC_MERCURY)
423
+ d_ret += (e.elo[p].pd2[i-2] * 10 * CS2DEG);
424
+ else
425
+ d_ret += (e.elo[p].pd2[i-2] * CS2DEG);
426
+ l_ret += d_ret;
427
+ if (l_ret < 0) {
428
+ lon[p][i0+i] = l_ret + 360.0;
429
+ } else if (l_ret >= 360.0) {
430
+ lon[p][i0+i] = l_ret - 360.0;
431
+ } else {
432
+ lon[p][i0+i] = l_ret;
433
+ }
434
+ }
435
+ } /* for p */
436
+ if ( plalist & EP_ECL_BIT) { /* unpack ecl */
437
+ l_ret = (e.ecl0m * 6000L + e.ecl0s) * CS2DEG;
438
+ lon[EP_ECL_INDEX][i0] = l_ret;
439
+ for (i = 1; i < NDB; i++)
440
+ lon[EP_ECL_INDEX][i0+i] = l_ret + e.ecld1[i-1] * CS2DEG;
441
+ }
442
+ if ( plalist & EP_NUT_BIT) { /* unpack nut */
443
+ for (i = 0; i < NDB; i++)
444
+ lon[EP_NUT_INDEX][i0+i] = e.nuts[i] * CS2DEG ;
445
+ }
446
+ return OK;
447
+ }
448
+
449
+ /****************************************************
450
+ position ephe file at proper position for julian
451
+ date jd; if writeflag = TRUE (write mode), create file
452
+ if required. Return OK or ERR.
453
+ globals used: ephfp.
454
+ *****************************************************/
455
+ int eph4_posit (int jlong, AS_BOOL writeflag, char *errtext)
456
+ {
457
+ int filenr;
458
+ long posit;
459
+ static int open_filenr = -10000;
460
+ char fname[AS_MAXCH], s[80], *sp;
461
+ filenr = jlong / EP4_NDAYS;
462
+ if (jlong < 0 && filenr * EP4_NDAYS != jlong) filenr--;
463
+ posit = jlong - filenr * EP4_NDAYS;
464
+ posit = posit / NDB * sizeof(struct ep4);
465
+ if (open_filenr != filenr) {
466
+ if (ephfp != NULL) {
467
+ fclose(ephfp);
468
+ open_filenr = -10000;
469
+ }
470
+ if (filenr >= 0)
471
+ sprintf (s, "%s%s%d", EP4_PATH, EP4_FILE, filenr);
472
+ else
473
+ sprintf (s, "%s%sM%d", EP4_PATH, EP4_FILE, -filenr);
474
+ my_makepath(fname, s);
475
+ if (writeflag)
476
+ sp = BFILE_W_CREATE;
477
+ else
478
+ sp = BFILE_R_ACCESS;
479
+ ephfp = fopen (fname, sp);
480
+ if (ephfp == NULL) {
481
+ if (errtext != NULL) {
482
+ if (! writeflag) {
483
+ sprintf (errtext,"eph4_posit: file %s does not exist\n", fname);
484
+ } else {
485
+ sprintf (errtext,"eph4_posit: could not create file %s\n", fname);
486
+ }
487
+ }
488
+ return (ERR);
489
+ }
490
+ open_filenr = filenr;
491
+ }
492
+ if (fseek (ephfp, posit, 0) == 0 && ftell(ephfp) == posit) {
493
+ return (OK);
494
+ } else {
495
+ if (errtext != NULL)
496
+ sprintf (errtext,"eph4_posit: fseek(%ld) of file nr %d failed\n",
497
+ posit, open_filenr);
498
+ return (ERR);
499
+ }
500
+ } /* end eph4_posit */
501
+
502
+ /*****************************************************
503
+ quicker Everett interpolation, after Pottenger
504
+ version for long, 17.7.91 by Alois Treindl
505
+ *****************************************************/
506
+ static void inpolq_l(int n, int o, double p, centisec *x, centisec *axu, centisec *adxu)
507
+ /*
508
+ * interpolate between x[n] and x[n-1], at argument n+p
509
+ * o = order of interpolation, maximum 5
510
+ * p = argument in [0..1]
511
+ * x[] array of function values, x[n-2]..x[n+3] must exist
512
+ * axu pointer for storage of result
513
+ * adxu pointer for storage of dx/dt
514
+ */
515
+ {
516
+ static double q,q2,q3,q4,q5,
517
+ p2,p3,p4,p5,
518
+ u,u0,u1,u2;
519
+ static double lastp = 9999;
520
+ double rl, rlp;
521
+ centisec dm2,dm1,d0,dp1,dp2,
522
+ d2m1,d20,d2p1,d2p2,
523
+ d30,d3p1,d3p2,
524
+ d4p1,d4p2;
525
+ centisec offset = 0;
526
+ if (lastp != p) { /* recompute the interpolator factors */
527
+ q=1.0-p;
528
+ q2 = q*q;
529
+ q3 = (q+1.0)*q*(q-1.0)/6.0; /* q - 1 over 3; u5 */
530
+ p2 = p*p;
531
+ p3 = (p+1.0)*p*(p-1.0)/6.0; /* p - 1 over 3; u8 */
532
+ u = (3.0*p2-1.0)/6.0;
533
+ u0 = (3.0*q2-1.0)/6.0;
534
+ q4 = q2*q2; /* f5 */
535
+ p4 = p2*p2; /* f4 */
536
+ u1 = (5.0*p4-15.0*p2+4.0)/120.0; /* u1 */
537
+ u2 = (5.0*q4-15.0*q2+4.0)/120.0; /* u2 */
538
+ q5 = q3*(q+2.0)*(q-2.0)/20.0; /* q - 2 over 5; u6 */
539
+ p5 = (p+2.0)*p3*(p-2.0)/20.0; /* p - 2 over 5; u9 */
540
+ lastp = p;
541
+ }
542
+ dm1 = x[n] - x[n-1];
543
+ if (dm1 >= DEG180)
544
+ dm1 -= DEG360;
545
+ else if (dm1 < -DEG180)
546
+ dm1 += DEG360;
547
+ d0 = x[n+1] - x[n];
548
+ if (d0 >= DEG180) {
549
+ d0 -= DEG360;
550
+ offset = DEG360;
551
+ } else if (d0 < -DEG180) {
552
+ d0 += DEG360;
553
+ offset = -DEG360;
554
+ }
555
+ dp1 = x[n+2] - x[n+1];
556
+ if (dp1 >= DEG180)
557
+ dp1 -= DEG360;
558
+ else if (dp1 < -DEG180)
559
+ dp1 += DEG360;
560
+ d20 = d0 - dm1; /* f8 */
561
+ d2p1 = dp1 - d0; /* f9 */
562
+ /*
563
+ * Everett interpolation 3rd order
564
+ */
565
+ rl = q*(x[n] + offset) + q3*d20 + p*x[n+1] + p3*d2p1;
566
+ rlp = d0 + u*d2p1 - u0*d20;
567
+ if ( o > 3 ) { /* 5th order */
568
+ dm2 = x[n-1] - x[n-2];
569
+ if (dm2 >= DEG180)
570
+ dm2 -= DEG360;
571
+ else if (dm2 < -DEG180)
572
+ dm2 += DEG360;
573
+ dp2 = x[n+3] - x[n+2];
574
+ if (dp2 >= DEG180)
575
+ dp2 -= DEG360;
576
+ else if (dp2 < -DEG180)
577
+ dp2 += DEG360;
578
+ d2m1 = dm1 - dm2;
579
+ d2p2 = dp2 - dp1;
580
+ d30 = d20 - d2m1;
581
+ d3p1 = d2p1 - d20;
582
+ d3p2 = d2p2 - d2p1;
583
+ d4p1 = d3p1 - d30; /* f7 */
584
+ d4p2 = d3p2 - d3p1; /* f */
585
+ rl += p5*d4p2 + q5*d4p1;
586
+ rlp += u1*d4p2 - u2*d4p1;
587
+ }
588
+ *axu = swe_d2l (rl);
589
+ *adxu = swe_d2l (rlp);
590
+ } /* end inpolq_l() */
591
+
592
+ /*****************************************************
593
+ quicker Everett interpolation, after Pottenger
594
+ version for double 9 Jul 1988 by Alois Treindl
595
+ return OK, no error checking
596
+ Was used in Placalc to interpolate 80-day stored ephe for outer planets.
597
+ *****************************************************/
598
+ static int inpolq(int n, int o, double p, double *x, double *axu, double *adxu)
599
+ // n interpolate between x[n] and x[n-1], at argument n+p
600
+ // o order of interpolation, maximum 5
601
+ // p, argument , intervall [0..1]
602
+ // x[] array of function values, x[n-o]..x[n+o] must exist
603
+ // *axu pointer for storage of result
604
+ // *adxu pointer for storage of dx/dt
605
+ {
606
+ static double q,q2,q3,q4,q5,p2,p3,p4,p5, u,u0,u1,u2;
607
+ static double lastp = 9999.0;
608
+ double dm2,dm1,d0,dp1,dp2,
609
+ d2m1,d20,d2p1,d2p2,
610
+ d30,d3p1,d3p2,
611
+ d4p1,d4p2;
612
+ double offset = 0.0;
613
+ if (lastp != p) {
614
+ q=1.0-p;
615
+ q2 = q*q;
616
+ q3 = (q+1.0)*q*(q-1.0)/6.0; /* q - 1 over 3; u5 */
617
+ p2 = p*p;
618
+ p3 = (p+1.0)*p*(p-1.0)/6.0; /* p - 1 over 3; u8 */
619
+ u = (3.0*p2-1.0)/6.0;
620
+ u0 = (3.0*q2-1.0)/6.0;
621
+ q4 = q2*q2; /* f5 */
622
+ p4 = p2*p2; /* f4 */
623
+ u1 = (5.0*p4-15.0*p2+4.0)/120.0; /* u1 */
624
+ u2 = (5.0*q4-15.0*q2+4.0)/120.0; /* u2 */
625
+ q5 = q3*(q+2.0)*(q-2.0)/20.0; /* q - 2 over 5; u6 */
626
+ p5 = (p+2.0)*p3*(p-2.0)/20.0; /* p - 2 over 5; u9 */
627
+ lastp = p;
628
+ }
629
+ dm1 = x[n] - x[n-1];
630
+ if (dm1 > 180.0) dm1 -= 360.0;
631
+ if (dm1 < -180.0) dm1 += 360.0;
632
+ d0 = x[n+1] - x[n];
633
+ if (d0 > 180.0) {
634
+ d0 -= 360.0;
635
+ offset = 360.0;
636
+ }
637
+ if (d0 < -180.0) {
638
+ d0 += 360.0;
639
+ offset = -360.0;
640
+ }
641
+ dp1 = x[n+2] - x[n+1];
642
+ if (dp1 > 180.0) dp1 -= 360.0;
643
+ if (dp1 < -180.0) dp1 += 360.0;
644
+ d20 = d0 - dm1; /* f8 */
645
+ d2p1 = dp1 - d0; /* f9 */
646
+ /* Everett interpolation 3rd order */
647
+ *axu = q*(x[n] + offset) + q3*d20
648
+ + p*x[n+1] + p3*d2p1;
649
+ *adxu = d0 + u*d2p1 - u0*d20;
650
+ if ( o > 3 ) { /* 5th order */
651
+ dm2 = x[n-1] - x[n-2];
652
+ if (dm2 > 180.0) dm2 -= 360.0;
653
+ if (dm2 < -180.0) dm2 += 360.0;
654
+ dp2 = x[n+3] - x[n+2];
655
+ if (dp2 > 180.0) dp2 -= 360.0;
656
+ if (dp2 < -180.0) dp2 += 360.0;
657
+ d2m1 = dm1 - dm2;
658
+ d2p2 = dp2 - dp1;
659
+ d30 = d20 - d2m1;
660
+ d3p1 = d2p1 - d20;
661
+ d3p2 = d2p2 - d2p1;
662
+ d4p1 = d3p1 - d30; /* f7 */
663
+ d4p2 = d3p2 - d3p1; /* f */
664
+ *axu += p5*d4p2 + q5*d4p1;
665
+ *adxu += u1*d4p2 - u2*d4p1;
666
+ }
667
+ return (OK);
668
+ } /* end inpolq() */
669
+
670
+
671
+ static char *my_makepath(char *d, char *s)
672
+ {
673
+ char *getenv();
674
+ if (*s == *DIR_GLUE || *s == '/' || strchr (s, ':') != NULL) {
675
+ strcpy (d, s); /* s is absolute path name */
676
+ }
677
+ # if MSDOS
678
+ while ((p = strchr(d, '/')) != NULL) *p = '\\';
679
+ # endif
680
+ return (d);
681
+ }
682
+
683
+ int ephe_plac2swe(int p)
684
+ {
685
+ if (p >= PLACALC_SUN && p <= PLACALC_TRUE_NODE) return p;
686
+ if (p == PLACALC_CHIRON) return SE_CHIRON;
687
+ if (p == PLACALC_LILITH) return SE_MEAN_APOG;
688
+ if (p == PLACALC_CERES) return SE_CERES;
689
+ if (p == PLACALC_PALLAS) return SE_PALLAS;
690
+ if (p == PLACALC_JUNO) return SE_JUNO;
691
+ if (p == PLACALC_VESTA) return SE_VESTA;
692
+ if (p == PLACALC_EARTHHEL) return SE_EARTH;
693
+ return -1;
694
+ }