-
Notifications
You must be signed in to change notification settings - Fork 110
/
sweasp.c
1884 lines (1841 loc) · 61.8 KB
/
sweasp.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SWISSEPH
Authors: Dieter Koch and Alois Treindl, Astrodienst Zurich
swetest -ec3 -p789 -lasp -b1.1.-580 -s30 -n200000 -lsco -ln2
**************************************************************/
/* Copyright (C) 1997 - 2021 Astrodienst AG, Switzerland. All rights reserved.
License conditions
------------------
This file is part of Swiss Ephemeris.
Swiss Ephemeris is distributed with NO WARRANTY OF ANY KIND. No author
or distributor accepts any responsibility for the consequences of using it,
or for whether it serves any particular purpose or works at all, unless he
or she says so in writing.
Swiss Ephemeris is made available by its authors under a dual licensing
system. The software developer, who uses any part of Swiss Ephemeris
in his or her software, must choose between one of the two license models,
which are
a) GNU Affero General Public License (AGPL)
b) Swiss Ephemeris Professional License
The choice must be made before the software developer distributes software
containing parts of Swiss Ephemeris to others, and before any public
service using the developed software is activated.
If the developer choses the AGPL software license, he or she must fulfill
the conditions of that license, which includes the obligation to place his
or her whole software project under the AGPL or a compatible license.
See https://www.gnu.org/licenses/agpl-3.0.html
If the developer choses the Swiss Ephemeris Professional license,
he must follow the instructions as found in http://www.astro.com/swisseph/
and purchase the Swiss Ephemeris Professional Edition from Astrodienst
and sign the corresponding license contract.
The License grants you the right to use, copy, modify and redistribute
Swiss Ephemeris, but only under certain conditions described in the License.
Among other things, the License requires that the copyright notices and
this notice be preserved on all copies.
Authors of the Swiss Ephemeris: Dieter Koch and Alois Treindl
The authors of Swiss Ephemeris have no control or influence over any of
the derived works, i.e. over software or services created by other
programmers which use Swiss Ephemeris functions.
The names of the authors or of the copyright holder (Astrodienst) must not
be used for promoting any software, product or service which uses or contains
the Swiss Ephemeris. This copyright notice is the ONLY place where the
names of the authors can legally appear, except in cases where they have
given special permission in writing.
The trademarks 'Swiss Ephemeris' and 'Swiss Ephemeris inside' may be used
for promoting such software, products or services.
*/
/* attention: Microsoft Compiler does not accept strings > 2048 char */
static char *infocmd0 = "\n\
Swetest computes a complete set of geocentric planetary positions,\n\
for a given date or a sequence of dates.\n\
Input can either be a date or an absolute julian day number.\n\
0:00 (midnight).\n\
With the proper options, swetest can be used to output a printed\n\
ephemeris and transfer the data into other programs like spreadsheets\n\
for graphical display.\n\
\n";
static char *infocmd1 = "\n\
Command line options:\n\
-pSEQ planet sequence to be computed.\n\
See the letter coding below.\n\
-nN output data for N consecutive days; if no -n option\n\
is given, the default is 1. If the option -n without a\n\
number is given, the default is 20.\n\
-sN timestep N days, default 1. This option is only meaningful\n\
when combined with option -n.\n\
-edirPATH change the directory of the ephemeris files \n\
-dX differential ephemeris: print differential ephemeris between\n\
body X and each body in list given by -p\n\
example: -p2 -d0 -fJl -n366 -b1.1.1992 prints the longitude\n\
distance between SUN (planet 0) and MERCURY (planet 2)\n\
for a full year starting at 1 Jan 1992.\n\
-hel compute heliocentric positions\n\
-bary compute barycentric positions (bar. sun instead of node) \n\
-head don\'t print the header before the planet data. This option\n\
is useful when you want to paste the output into a\n\
spreadsheet for displaying graphical ephemeris.\n\
+head header before every step (with -s..) \n\
-bDATE use this begin date instead of asking; use -b1.1.1992 if\n\
the begin date string contains blanks; use format -bj2400000.5\n\
to express the date as absolute Julian day number.\n\
Note: the date format is day month year (European style).\n\
-gPPP use PPP as gap between output columns; default is a single\n\
blank. -g followed by white space sets the\n\
gap to the TAB character; which is useful for data entry\n\
into spreadsheets.\n\
-iXX force iflag to value XX\n\
-fSEQ use SEQ as format sequence for the output columns;\n\
default is PLBRuS.\n";
static char *infocmd2 = "\
-ut input date is universal time\n\
-eswe swiss ephemeris\n\
-ejpl jpl ephemeris (DE406), or with ephemeris file name\n\
-ejplDE200.cdrom \n\
-emos moshier ephemeris\n\
-true true positions\n\
-noaberr no aberration\n\
-nodefl no gravitational light deflection\n\
-j2000 no precession (i.e. J2000 positions)\n\
-nonut no nutation \n\
-speed high precision speed \n\
-speed3 'low' precision speed from 3 positions \n\
do not use this option. -speed parameter is faster and preciser \n\
-testaa96 test example in AA 96, B37,\n\
i.e. venus, j2450442.5, DE200.\n\
attention: use precession IAU1976\n\
and nutation 1980 (s. swephlib.h)\n\
-testaa95\n\
-roundsec round to seconds\n\
-roundmin round to minutes\n\
\n\
-?, -h display whole info\n\
-hcmd display commands\n\
-hplan display planet numbers\n\
-hform display format characters\n\
-hdate display input date format\n";
static char *infoplan = "\n\
Planet selection letters:\n\
d (default) main factors 0123456789mtABC\n\
p main factors as above, plus main asteroids DEFGHI\n\
h ficticious factors J..X\n\
a all factors\n\
(the letters above can only appear as a single letter)\n\n\
0 Sun (character zero)\n\
1 Moon (character 1)\n\
2 Mercury\n\
....\n\
9 Pluto\n\
m mean lunar node\n\
t true lunar node\n\
e obliquity of ecliptic\n\
n nutation\n\
A lunar apogee mean (Lilith, Black Moon) \n\
B lunar apogee osculating \n\
w lunar apogee interpolated\n\
x lunar perigee interpolated\n\
C Earth \n\
D Chiron\n\
E Pholus\n\
F Ceres \n\
G Pallas \n\
H Juno \n\
I Vesta \n\
J Cupido \n\
K Hades \n\
L Zeus \n\
M Kronos \n\
N Apollon \n\
O Admetos \n\
P Vulkanus \n\
Q Poseidon \n\
R Isis (Sevin) \n\
S Nibiru (Sitchin) \n\
T Harrington \n\
U Leverrier's Neptune\n\
V Adams' Neptune\n\
W Lowell's Pluto\n\
X Pickering's Pluto\n\n\
f fixed star, with name or number given in -xf option\n\
s minor planet, with MPC number given in -xs\n\
\n";
static char *infoform = "\n\
Output format SEQ letters:\n\
In the standard setting five columns of coordinates are printed with\n\
the default format PLBRuS. You can change the default by providing an\n\
option like -fCCCC where CCCC is your sequence of columns.\n\
The coding of the sequence is like this:\n\
y year\n\
Y year.fraction_of_year\n\
p planet index\n\
P planet name\n\
J absolute juldate\n\
T date formatted like 23.02.1992 \n\
t date formatted like 920223 for 1992 february 23\n\
L longitude in degree ddd mm'ss\"\n\
l longitude decimal\n\
Z longitude ddsignmm'ss\"\n\
S speed in longitude in degree ddd:mm:ss per day\n\
SS speed for all values specified in fmt\n\
s speed longitude decimal (degrees/day)\n\
ss speed for all values specified in fmt\n\
B latitude degree\n\
b latitude decimal\n\
R distance decimal in AU\n\
r distance decimal in AU, Moon in seconds parallax\n\
relative distance (1000=nearest, 0=furthest)\n\
A Rectascension in hh:mm:ss\n\
a rectascension hours decimal\n\
D Declination degree\n\
d declination decimal\n\
X x-, y-, and z-coordinates ecliptical\n\
x x-, y-, and z-coordinates equatorial\n\
U unit vector ecliptical\n\
u unit vector equatorial\n\
Q l, b, r, dl, db, dr, a, d, da, dd\n";
static char *infodate = "\n\
Date entry:\n\
In the interactive mode, when you are asked for a start date,\n\
you can enter data in one of the following formats:\n\
\n\
1.2.1991 three integers separated by a nondigit character for\n\
day month year. Dates are interpreted as Gregorian\n\
after 4.10.1582 and as Julian Calender before.\n\
Time is always set to midnight.\n\
If the three letters jul are appended to the date,\n\
the Julian calendar is used even after 1582.\n\
If the four letters greg are appended to the date,\n\
the Gregorian calendar is used even before 1582.\n\
\n\
j2400123.67 the letter j followed by a real number, for\n\
the absolute Julian daynumber of the start date.\n\
Fraction .5 indicates midnight, fraction .0\n\
indicates noon, other times of the day can be\n\
chosen accordingly.\n\
\n\
<RETURN> repeat the last entry\n\
\n\
. stop the program\n\
\n\
+20 advance the date by 20 days\n\
\n\
-10 go back in time 10 days\n";
/**************************************************************/
//#include "sweodef.h"
#include "swephexp.h"
#include "swephlib.h"
#include <string.h>
#if MSDOS
# include <direct.h>
# include <dos.h>
# ifdef _MSC_VER
# include <sys\types.h>
# endif
# include <sys\stat.h>
#else
# include <sys/stat.h>
#endif
#ifdef _WINDOWS
#include <windows.h>
#endif
//#include "sweph.h"
//#include "swephlib.h"
#define J2000 2451545.0 /* 2000 January 1.5 */
#define square_sum(x) (x[0]*x[0]+x[1]*x[1]+x[2]*x[2])
#define SEFLG_EPHMASK (SEFLG_JPLEPH|SEFLG_SWIEPH|SEFLG_MOSEPH)
#define BIT_ROUND_SEC 1
#define BIT_ROUND_MIN 2
#define BIT_ZODIAC 4
#define PLSEL_D "0123456789mtABC"
#define PLSEL_P "0123456789mtABCDEFGHI"
#define PLSEL_H "JKLMNOPQRSTUV"
#define PLSEL_A "0123456789mtABCDEFGHIJKLMNOPQRSTUV"
#define LIST_CONJ 1
#define LIST_POLYG 2
#define LIST_ASP 4
static int listflag = (LIST_CONJ|LIST_ASP);
static int nlist = 0;
static double maxorb = 4;
static char slist[AS_MAXCH];
static char sretdir[AS_MAXCH];
int iflag = 0;
AS_BOOL do_nod = FALSE, do_nos = FALSE, do_aph = FALSE, do_per = FALSE;
int do_true_node = 0;
#ifdef _WINDOWS
static FILE *fp = NULL;
#endif
static char se_pname[AS_MAXCH];
static char *zod_nam[] = {"ar", "ta", "ge", "cn", "le", "vi",
"li", "sc", "sa", "cp", "aq", "pi"};
extern int swe_plan_pheno(double tjd, int ipl, int iflag, double *attr, char *serr);
static char star[AS_MAXCH] = "algol";
static char sastno[AS_MAXCH] = "433";
static char *dms(double x, long iflag);
static int do_calc(double tjd, int ipl, long iflag, double *x, char *serr);
static long do_fixstar(char *star, double tjd, long iflag, double *x, char *serr);
static void do_printf(char *info);
static double difdeg2n (double p1, double p2);
static int find_ephemeris_path(long iflag, char *argv0);
static int letter_to_ipl(int letter);
static int search_file(char *path, long iflag);
void polcart(double *l, double *x);
static int pos_compare(double *a1, double *a2);
static int find_maximum(double y00, double y11, double y2, double dx,
double *dxret, double *yret);
static int find_zero(double y00, double y11, double y2, double dx,
double *dxret, double *dxret2);
static double find_max(double tjd, double tstep, char *plsel,
double harm, int recursive,
double *xxs);
static char *hms(double x, long iflag);
#define NPLX 30
#ifdef _WINDOWS
int WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
#else
int main(int argc, char *argv[])
#endif
{
#ifdef _WINDOWS
int argc = 1;
char *argv[30];
struct _wopeninfo wo;
char scmd[AS_MAXCH];
#endif
char spnam[AS_MAXCH], spnam2[AS_MAXCH], saves[AS_MAXCH];
char serr[AS_MAXCH], serr_save[AS_MAXCH], serr_warn[AS_MAXCH], sout[AS_MAXCH];
char *sp, *spsave, *sp2, *psp;
char *spno;
char *fmt = "PLBRS";
char *gap = " ";
char *plsel = PLSEL_D;
#if HPUNIX
char hostname[80];
#endif
int i, j, n, iflag_f = -1, isp;
int listflg2 = 0;
int jmon, jday, jyear;
int line_count, line_limit = 32000;
double jut = 0.0, y_frac;
int ipl, ipldiff = SE_SUN;
long nstep = 1, istep;
double x[6], x2[6], xequ[6], xcart[6], xcartq[6];
static double xxx[NPLX], xsv[NPLX], xs2[NPLX];
/* static to init with 0 */
double ar, sinp;
char ephepath[AS_MAXCH];
char fname[AS_MAXCH];
char sdate[AS_MAXCH];
char *begindate = NULL;
long iflag2; /* external flag: helio, geo... */
long iflgret;
int icomb, ncomb, plslen;
int whicheph = SEFLG_SWIEPH;
short universal_time = FALSE;
short with_header = TRUE;
short with_header_always = FALSE;
int gregflag;
AS_BOOL plan_phenomena = FALSE;
AS_BOOL do_eval_const = FALSE;
AS_BOOL do_print_max = FALSE;
AS_BOOL do_all_comb = FALSE;
short diff_mode = FALSE;
long round_flag = 0;
double tjd = 2415020.5, t_ut;
double t, te, t2, tstep = 1, thour = 0;
double delt;
serr[0] = serr_save[0] = serr_warn[0] = saves[0] = slist[0] = '\0';
#ifdef _WINDOWS
wo._version = _QWINVER;
wo._title = "Dlltest";
wo._wbufsize = _WINBUFDEF;
fp = _fwopen(&wo, NULL, "w+");
do_printf("Enter options: ");
rewind(fp);
fgets(scmd, AS_MAXCH, fp);
rewind(fp);
argv[0] = "swetest";
sp = strchr(scmd, '\n');
if (sp != NULL)
*sp = '\0';
sp = scmd;
/* cut command string */
while (sp != NULL && *sp != '\0') {
while (*sp == ' ')
sp++;
if (*sp == '\0')
break;
if (*sp == '-' || *sp == '+') {
argv[argc] = sp;
argc++;
} else if (*sp == 'j' || (*sp >= '0' && *sp <= '9')) {
strcpy(s, "-b"); /* date is allowed without '-b' */
strcat(s, sp);
strcpy(sp, s);
argv[argc] = sp;
argc++;
} else
goto end_main;
sp = strchr(sp, ' ');
if (sp != NULL) {
*sp = '\0';
sp++;
}
}
iflag = whicheph | SEFLG_SPEED;
#endif
strcpy(ephepath, SE_EPHE_PATH);
strcpy(fname, SE_FNAME_DE406);
for (i = 1; i < argc; i++) {
if (strlen(argv[i]) >= AS_MAXCH) argv[i][AS_MAXCH-1] = '\0';
if (strncmp(argv[i], "-ut", 3) == 0) {
universal_time = TRUE;
if (strlen(argv[i]) > 3) {
thour = atof(argv[i] + 3) + 1E-10;
/* h.mmss -> decimal */
t = (thour - (int) thour) * 100;
j = (int) t;
t = (t - (int) t) * 100;
thour = (int) thour + j / 60.0 + t / 3600.0;
}
} else if (strncmp(argv[i], "-head", 5) == 0) {
with_header = FALSE;
} else if (strncmp(argv[i], "+head", 5) == 0) {
with_header_always = TRUE;
} else if (strcmp(argv[i], "-j2000") == 0) {
iflag |= SEFLG_J2000;
} else if (strncmp(argv[i], "-sidto", 6) == 0) {
iflag |= SEFLG_SIDEREAL;
swe_set_sid_mode(atol(argv[i] + 6) + SE_SIDBIT_ECL_T0, 0, 0);
} else if (strncmp(argv[i], "-sidsy", 6) == 0) {
iflag |= SEFLG_SIDEREAL;
swe_set_sid_mode(atol(argv[i] + 6) + SE_SIDBIT_SSY_PLANE, 0, 0);
} else if (strncmp(argv[i], "-sid", 4) == 0) {
iflag |= SEFLG_SIDEREAL;
swe_set_sid_mode(atol(argv[i] + 4), 0, 0);
} else if (strcmp(argv[i], "-lcon") == 0) {
listflg2 |= LIST_CONJ;
} else if (strcmp(argv[i], "-lpol") == 0) {
listflg2 |= LIST_POLYG;
} else if (strcmp(argv[i], "-lasp") == 0) {
listflg2 |= LIST_ASP;
} else if (strncmp(argv[i], "-ln", 3) == 0) {
nlist = atoi(argv[i]+3);
} else if (strncmp(argv[i], "-ls", 3) == 0) {
strcpy(slist, argv[i]+3);
} else if (strncmp(argv[i], "-orb", 4) == 0) {
maxorb = atof(argv[i]+4);
} else if (strncmp(argv[i], "-ec", 3) == 0) {
do_eval_const = TRUE;
if (*(argv[i] + 3) != '\0')
do_print_max = TRUE;
if (*(argv[i] + 3) == '3')
do_all_comb = TRUE;
} else if (strncmp(argv[i], "-j", 2) == 0) {
begindate = argv[i] + 1;
} else if (strncmp(argv[i], "-ejpl", 5) == 0) {
whicheph = SEFLG_JPLEPH;
strcpy(ephepath, SE_EPHE_PATH);
if (*(argv[i]+5) != '\0') {
strcpy(fname, argv[i]+5);
}
} else if (strcmp(argv[i], "-eswe") == 0) {
whicheph = SEFLG_SWIEPH;
strcpy(ephepath, SE_EPHE_PATH);
} else if (strcmp(argv[i], "-emos") == 0) {
whicheph = SEFLG_MOSEPH;
} else if (strcmp(argv[i], "-hel") == 0) {
iflag |= SEFLG_HELCTR;
} else if (strcmp(argv[i], "-bary") == 0) {
iflag |= SEFLG_BARYCTR;
} else if (strcmp(argv[i], "-topo") == 0) {
iflag |= SEFLG_TOPOCTR;
} else if (strcmp(argv[i], "-true") == 0) {
iflag |= SEFLG_TRUEPOS;
} else if (strcmp(argv[i], "-noaberr") == 0) {
iflag |= SEFLG_NOABERR;
} else if (strcmp(argv[i], "-nodefl") == 0) {
iflag |= SEFLG_NOGDEFL;
} else if (strcmp(argv[i], "-nonut") == 0) {
iflag |= SEFLG_NONUT;
} else if (strcmp(argv[i], "-speed3") == 0) {
iflag |= SEFLG_SPEED3;
} else if (strcmp(argv[i], "-speed") == 0) {
iflag |= SEFLG_SPEED;
} else if (strncmp(argv[i], "-phen", 5) == 0) {
plan_phenomena = TRUE;
} else if (strncmp(argv[i], "-testaa", 7) == 0) {
whicheph = SEFLG_JPLEPH;
strcpy(ephepath, SE_EPHE_PATH);
strcpy(fname, SE_FNAME_DE200);
if (strcmp(argv[i]+7, "95") == 0)
begindate = "j2449975.5";
if (strcmp(argv[i]+7, "96") == 0)
begindate = "j2450442.5";
if (strcmp(argv[i]+7, "97") == 0)
begindate = "j2450482.5";
fmt = "PADRu";
universal_time = FALSE;
plsel="3";
} else if (strncmp(argv[i], "-nod", 4) == 0) {
if (strchr(argv[i], 's') != NULL)
do_nos = TRUE;
else
do_nod = TRUE;
if (strchr(argv[i], 'm') != NULL)
do_true_node = SE_NODBIT_MEAN;
if (strchr(argv[i], 't') != NULL)
do_true_node = SE_NODBIT_OSCU;
if (strchr(argv[i], 'b') != NULL)
do_true_node |= SE_NODBIT_OSCU_BAR;
if (strchr(argv[i], 'f') != NULL)
do_true_node |= SE_NODBIT_FOPOINT;
} else if (strncmp(argv[i], "-aph", 4) == 0) {
do_aph = TRUE;
if (strchr(argv[i], 'm') != NULL)
do_true_node = SE_NODBIT_MEAN;
if (strchr(argv[i], 't') != NULL)
do_true_node = SE_NODBIT_OSCU;
if (strchr(argv[i], 'b') != NULL)
do_true_node |= SE_NODBIT_OSCU_BAR;
if (strchr(argv[i], 'f') != NULL)
do_true_node |= SE_NODBIT_FOPOINT;
} else if (strncmp(argv[i], "-per", 4) == 0) {
do_per = TRUE;
if (strchr(argv[i], 'm') != NULL)
do_true_node = SE_NODBIT_MEAN;
if (strchr(argv[i], 't') != NULL)
do_true_node = SE_NODBIT_OSCU;
if (strchr(argv[i], 'b') != NULL)
do_true_node |= SE_NODBIT_OSCU_BAR;
if (strchr(argv[i], 'f') != NULL)
do_true_node |= SE_NODBIT_FOPOINT;
} else if (strncmp(argv[i], "-p", 2) == 0) {
spno = argv[i]+2;
switch (*spno) {
case 'd':
case '\0':
case ' ': plsel = PLSEL_D; break;
case 'p': plsel = PLSEL_P; break;
case 'h': plsel = PLSEL_H; break;
case 'a': plsel = PLSEL_A; break;
default: plsel = spno;
}
} else if (strncmp(argv[i], "-xs", 3) == 0) {
/* number of asteroid */
strcpy(sastno, argv[i] + 3);
} else if (strncmp(argv[i], "-xf", 3) == 0) {
/* name or number of fixed star */
strcpy(star, argv[i] + 3);
} else if (strncmp(argv[i], "-x", 2) == 0) {
/* name or number of fixed star */
strcpy(star, argv[i] + 2);
} else if (strncmp(argv[i], "-n", 2) == 0) {
nstep = atoi(argv[i]+2);
} else if (strncmp(argv[i], "-i", 2) == 0) {
iflag_f = atoi(argv[i]+2);
} else if (strncmp(argv[i], "-s", 2) == 0) {
tstep = atof(argv[i]+2);
} else if (strncmp(argv[i], "-b", 2) == 0) {
begindate = argv[i] + 2;
} else if (strncmp(argv[i], "-f", 2) == 0) {
fmt = argv[i] + 2;
} else if (strncmp(argv[i], "-g", 2) == 0) {
gap = argv[i] + 2;
if (*gap == '\0') gap = "\t";
} else if (strncmp(argv[i], "-d", 2) == 0) {
diff_mode = TRUE;
sp = argv[i]+2;
ipldiff = letter_to_ipl((int) *sp);
if (ipldiff <0) ipldiff = SE_SUN;
swe_get_planet_name(ipldiff, spnam2);
} else if (strcmp(argv[i], "-roundsec") == 0) {
round_flag |= BIT_ROUND_SEC;
} else if (strcmp(argv[i], "-roundmin") == 0) {
round_flag |= BIT_ROUND_MIN;
} else if (strncmp(argv[i], "-h", 2) == 0
|| strncmp(argv[i], "-?", 2) == 0) {
sp = argv[i]+2;
if (*sp == 'c' || *sp == '\0') {
do_printf(infocmd0);
do_printf(infocmd1);
do_printf(infocmd2);
}
if (*sp == 'p' || *sp == '\0')
do_printf(infoplan);
if (*sp == 'f' || *sp == '\0')
do_printf(infoform);
if (*sp == 'd' || *sp == '\0')
do_printf(infodate);
goto end_main;
} else {
if (strlen(argv[i]) >= AS_MAXCH - 30) argv[i][AS_MAXCH -30] = '\0';
sprintf(sout, "illegal option %s\n", argv[i]);
do_printf(sout);
exit(1);
}
}
if (listflg2 > 0)
listflag = listflg2;
plslen = strlen(plsel);
if (do_all_comb)
ncomb = (1 << plslen) - 1;
swe_set_topo(8.55, 47.35, 400);
#if HPUNIX
gethostname (hostname, 80);
if (strstr(hostname, "as10") != NULL)
line_limit = 1000;
#endif
if (with_header) {
for (i = 0; i < argc; i++) {
do_printf(argv[i]);
do_printf(" ");
}
}
iflag = (iflag & ~SEFLG_EPHMASK) | whicheph;
if (strpbrk(fmt, "SsQ") != NULL)
iflag |= SEFLG_SPEED;
#if 1
swe_set_ephe_path(ephepath);
/* swe_set_ephe_path("d:\\sweph\\ephe\\");*/
#else
if (find_ephemeris_path(iflag, argv[0]) == ERR) {
iflag = (iflag & ~SEFLG_EPHMASK) | SEFLG_MOSEPH;
whicheph = SEFLG_MOSEPH;
}
#endif
if (whicheph & SEFLG_JPLEPH)
swe_set_jpl_file(fname);
while (TRUE) {
serr[0] = serr_save[0] = serr_warn[0] = '\0';
if (begindate == NULL) {
do_printf("\nDate ?");
sdate[0] = '\0';
#ifdef _WINDOWS
rewind(fp);
fgets(sdate, AS_MAXCH, fp);
rewind(fp);
#else
gets(sdate);
#endif
} else {
strcpy(sdate, begindate);
begindate = "."; /* to exit afterwards */
}
if (strcmp(sdate, "-bary") == 0) {
iflag = iflag & ~SEFLG_HELCTR;
iflag |= SEFLG_BARYCTR;
*sdate = '\0';
} else if (strcmp(sdate, "-hel") == 0) {
iflag = iflag & ~SEFLG_BARYCTR;
iflag |= SEFLG_HELCTR;
*sdate = '\0';
} else if (strcmp(sdate, "-geo") == 0) {
iflag = iflag & ~SEFLG_BARYCTR;
iflag = iflag & ~SEFLG_HELCTR;
*sdate = '\0';
} else if (strcmp(sdate, "-ejpl") == 0) {
iflag &= ~SEFLG_EPHMASK;
iflag |= SEFLG_JPLEPH;
*sdate = '\0';
} else if (strcmp(sdate, "-eswe") == 0) {
iflag &= ~SEFLG_EPHMASK;
iflag |= SEFLG_SWIEPH;
*sdate = '\0';
} else if (strcmp(sdate, "-emos") == 0) {
iflag &= ~SEFLG_EPHMASK;
iflag |= SEFLG_MOSEPH;
*sdate = '\0';
} else if (strncmp(sdate, "-xs",3) == 0) {
/* number of asteroid */
strcpy(sastno, sdate + 3);
*sdate = '\0';
}
sp = sdate;
spsave = sp;
if (*sp == '.') {
goto end_main;
} else if (*sp == '\0') {
strcpy (sdate, saves);
} else {
strcpy (saves, sdate);
}
if (*sp == 'j') { /* it's a day number */
if ((sp2 = strchr(sp, ',')) != NULL)
*sp2 = '.';
sscanf(sp+1,"%lf", &tjd);
if (tjd < 2299160.5) {
gregflag = SE_JUL_CAL;
} else {
gregflag = SE_GREG_CAL;
}
if (strstr(sp, "jul") != NULL) {
gregflag = SE_JUL_CAL;
} else if (strstr(sp, "greg") != NULL) {
gregflag = SE_GREG_CAL;
}
swe_revjul(tjd, gregflag, &jyear, &jmon, &jday, &jut);
} else if (*sp == '+') {
n = atoi(sp);
if (n == 0) n = 1;
tjd += n;
swe_revjul(tjd, gregflag, &jyear, &jmon, &jday, &jut);
} else if (*sp == '-') {
n = atoi(sp);
if (n == 0) n = -1;
tjd += n;
swe_revjul(tjd, gregflag, &jyear, &jmon, &jday, &jut);
} else {
if (sscanf (sp, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);
if ((long) jyear * 10000L + (long) jmon * 100L + (long) jday < 15821015L) {
gregflag = SE_JUL_CAL;
} else {
gregflag = SE_GREG_CAL;
}
if (strstr(sp, "jul") != NULL) {
gregflag = SE_JUL_CAL;
} else if (strstr(sp, "greg") != NULL) {
gregflag = SE_GREG_CAL;
}
jut = 0;
tjd = swe_julday(jyear,jmon,jday,jut,gregflag);
tjd += thour / 24;
}
line_count = 0;
for (t = tjd, istep = 1; istep <= nstep; t += tstep, istep++) {
if (t < 2299160.5) {
gregflag = SE_JUL_CAL;
} else {
gregflag = SE_GREG_CAL;
}
if (strstr(spsave, "jul") != NULL) {
gregflag = SE_JUL_CAL;
} else if (strstr(spsave, "greg") != NULL) {
gregflag = SE_GREG_CAL;
}
swe_revjul(t, gregflag, &jyear, &jmon, &jday, &jut);
if (with_header) {
sprintf(sout, "\ndate (dmy) %d.%d.%d", jday, jmon, jyear);
do_printf(sout);
if (gregflag) {
do_printf(" greg.");
} else {
do_printf(" jul.");
}
t2 = t + 0.5;
t2 = (t2 - (long int) t2) * 24;
sprintf(sout, " % 2d:", (int) t2);
do_printf(sout);
t2 = (t2 - (long int) t2) * 60 + 0.5;
sprintf(sout, "%02d", (int) t2);
do_printf(sout);
if (universal_time) {
do_printf(" UT");
} else {
do_printf(" ET");
}
}
delt = swe_deltat(t);
if (universal_time) {
if (with_header) {
sprintf(sout, "\nUT: %f", t);
do_printf(sout);
}
if (with_header) {
sprintf(sout, " delta t: %f sec", delt * 86400.0);
do_printf(sout);
}
te = t + delt;
t_ut = t;
} else {
te = t;
t_ut = te - delt;
}
{
double x[6];
x[1] = x[2] = x[0] = 1;
swi_precess(x, te, iflag, 1);
}
if (with_header && (iflag & SEFLG_SIDEREAL)) {
double daya = swe_get_ayanamsa(te);
char s[AS_MAXCH];
sprintf(s, " ayan = %s", dms(daya, 0));
do_printf(s);
}
if (with_header)
do_printf("\n");
for (psp = plsel, isp = 0; *psp != '\0'; psp++, isp++) {
ipl = letter_to_ipl((int) *psp);
if (with_header && !with_header_always)
with_header = FALSE;
if (*psp == 'f') {
ipl = SE_FIXSTAR;
} else if (*psp == 's') {
ipl = atoi(sastno) + 10000;
}
if (plan_phenomena) {
double attr[20];
if (with_header && psp == plsel)
do_printf("planet\tphase_ang\tphase\t\telong\t\tdiam\t\tmag\n");
if (swe_pheno(te, ipl, iflag, attr, serr) == ERR) {
do_printf(serr);
exit(0);
}
if (strchr(fmt, 'P') != NULL)
swe_get_planet_name(ipl, se_pname);
se_pname[7] = 0;
sprintf(sout, "%s\t%f\t%f\t%f\t%f\t%f\n", se_pname,
attr[0], attr[1], attr[2], attr[3], attr[4]);
do_printf(sout);
continue;
}
if (iflag & SEFLG_HELCTR) {
if (ipl == SE_SUN
|| ipl == SE_MEAN_NODE || ipl == SE_TRUE_NODE
|| ipl == SE_MEAN_APOG || ipl == SE_OSCU_APOG)
continue;
} else if (iflag & SEFLG_BARYCTR) {
if (ipl == SE_MEAN_NODE || ipl == SE_TRUE_NODE
|| ipl == SE_MEAN_APOG || ipl == SE_OSCU_APOG)
continue;
} else { /* geocentric */
if (do_nod || do_nos || do_per || do_aph) {
if (ipl == SE_MEAN_NODE || ipl == SE_TRUE_NODE
|| ipl == SE_MEAN_APOG || ipl == SE_OSCU_APOG)
continue;
} else if (ipl == SE_EARTH)
continue;
}
/* ecliptic position */
if (iflag_f >=0)
iflag = iflag_f;
if (ipl == SE_FIXSTAR) {
iflgret = do_fixstar(star, te, iflag, x, serr);
strcpy(se_pname, star);
} else {
iflgret = do_calc(te, ipl, iflag, x, serr);
if (iflgret != ERR)
swe_get_planet_name(ipl, se_pname);
}
if (1) {
double xx[6], xnorm[6], m;
static double xsum[6];
switch(ipl) {
/* case SE_SUN: m = 1; break;
case SE_MERCURY: m = 6023600; break;
case SE_VENUS: m = 408523.5; break;
case SE_EARTH: m = 328900.5; break;
case SE_MARS: m = 3098710.0; break;
case SE_JUPITER: m = 1047.35;break;
case SE_SATURN: m = 3498.0; break;
case SE_URANUS: m = 22960.0; break;
case SE_NEPTUNE: m = 19314.0; break;
case SE_PLUTO: m = 130000000.0; break;
case SE_CERES: m = 2127659574.0; break;
case SE_PALLAS: m = 10000000000.0; break;
case SE_VESTA: m = 7692307692.0; break; */
case SE_SUN: m = 2.9591220828559109E-04; break;
case SE_MERCURY: m = 4.9125474514508119E-11; break;
case SE_VENUS: m = 7.2434524861627027E-10; break;
case SE_EARTH: m = 8.9970113467124988E-10; break;
case SE_MARS: m = 9.5495351057792581E-11; break;
case SE_JUPITER: m = 2.8253459095242264E-07; break;
case SE_SATURN: m = 8.4597151856806587E-08; break;
case SE_URANUS: m = 1.2920249167819694E-08; break;
case SE_NEPTUNE: m = 1.5243589007842763E-08; break;
case SE_PLUTO: m = 2.1886997654259697E-12; break;
//case SE_CERES: m = 1.3907873789422780E-13; break;
//case SE_PALLAS: m = 2.9591220828559110E-14; break;
//case SE_VESTA: m = 3.8468587077126837E-14; break;
default: m = 0;
}
if (m > 0) m = 1 / m;
for (i = 0; i < 6; i++) {
xx[i] = x[i];
if (i != 2 && i != 5)
xx[i] *= DEGTORAD;
}
swi_polcart_sp(xx, xx);
swi_cross_prod(xx, xx+3, xnorm);
for (i = 0; i < 3; i++) {
if (ipl == SE_MOON)
break;
if (ipl == SE_SUN)
xsum[i] = 0;
xsum[i] += xnorm[i] / m;
}
if (1 && ipl == SE_EARTH) {
swi_cartpol(xsum, xsum);
/*printf("spol: %f %f\n", xsum[0] * RADTODEG, xsum[1] * RADTODEG);*/
}
}
if (*psp == 'o') {/* ecliptic is wanted, remove nutation */
x[2] = x[3] = 0;
strcpy(se_pname, "Ecl. Obl.");
}
if (*psp == 'n') {/* nutation is wanted, remove ecliptic */
x[0] = x[2];
x[1] = x[3];
x[2] = x[3] = 0;
strcpy(se_pname, "Nutation");
}
if (iflgret < 0) {
if (strcmp(serr, serr_save) != 0
&& (ipl == SE_SUN || ipl == SE_MOON
|| ipl == SE_MEAN_NODE || ipl == SE_TRUE_NODE
|| ipl == SE_CHIRON || ipl == SE_CUPIDO
|| ipl >= SE_AST_OFFSET || ipl == SE_FIXSTAR)) {
sprintf(sout, "error: %s\n", serr);
do_printf(sout);
}
strcpy(serr_save, serr);
} else if (*serr != '\0' && *serr_warn == '\0') {
strcpy(serr_warn, serr);
}
if (diff_mode) {
double x3[6], x4[6];
iflgret = do_calc(te, ipldiff, iflag, x2, serr);
if (iflgret < 0) {
sprintf(sout, "error: %s\n", serr);
do_printf(sout);
}
for (i = 0; i < 6; i++) {
x3[i] = x[i];
x4[i] = x2[i];
x[i] -= x2[i];
}
if ((iflag & SEFLG_RADIANS) == 0)
x[0] = difdeg2n(x[0], 0.0);
x3[0] *= DEGTORAD;
x3[1] *= DEGTORAD;
x4[0] *= DEGTORAD;
x4[1] *= DEGTORAD;
polcart(x3, x3);
polcart(x4, x4);
for (i = 0; i < 6; i++)
x3[i] -= x4[i];
x[2] = sqrt(square_sum(x3));
}
/* equator position */
if (strpbrk(fmt, "aADdQ") != NULL) {
iflag2 = iflag | SEFLG_EQUATORIAL;
if (ipl == SE_FIXSTAR) {
iflgret = do_fixstar(star, te, iflag2, xequ, serr);
} else {
iflgret = do_calc(te, ipl, iflag2, xequ, serr);
}
if (diff_mode) {
iflgret = do_calc(te, ipldiff, iflag2, x2, serr);
for (i = 0; i < 6; i++)
xequ[i] -= x2[i];
if ((iflag & SEFLG_RADIANS) == 0)
xequ[0] = difdeg2n(xequ[0], 0.0);
}
}
/* ecliptic cartesian position */
if (strpbrk(fmt, "XU") != NULL) {
iflag2 = iflag | SEFLG_XYZ;
if (ipl == SE_FIXSTAR) {
iflgret = do_fixstar(star, te, iflag2, xcart, serr);
} else {
iflgret = do_calc(te, ipl, iflag2, xcart, serr);
}
if (diff_mode) {
iflgret = do_calc(te, ipldiff, iflag2, x2, serr);
for (i = 0; i < 6; i++)
xcart[i] -= x2[i];
}
}
/* equator cartesian position */
if (strpbrk(fmt, "xu") != NULL) {
iflag2 = iflag | SEFLG_XYZ | SEFLG_EQUATORIAL;
if (ipl == SE_FIXSTAR) {
iflgret = do_fixstar(star, te, iflag2, xcartq, serr);
} else {
iflgret = do_calc(te, ipl, iflag2, xcartq, serr);
}
if (diff_mode) {
iflgret = do_calc(te, ipldiff, iflag2, x2, serr);
for (i = 0; i < 6; i++)
xcartq[i] -= x2[i];
}
}
if (do_eval_const) {
xs2[isp] = xsv[isp];
xsv[isp] = xxx[isp];
xxx[isp] = x[0];
continue;
}
strcpy(spnam, se_pname);
/*
* The string fmt contains a sequence of format specifiers;
* each character in fmt creates a column, the columns are
* sparated by the gap string.
*/