-
Notifications
You must be signed in to change notification settings - Fork 67
/
charts3.cpp
2011 lines (1817 loc) · 69.3 KB
/
charts3.cpp
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
/*
** Astrolog (Version 7.70) File: charts3.cpp
**
** IMPORTANT NOTICE: Astrolog and all chart display routines and anything
** not enumerated below used in this program are Copyright (C) 1991-2024 by
** Walter D. Pullen (Astara@msn.com, http://www.astrolog.org/astrolog.htm).
** Permission is granted to freely use, modify, and distribute these
** routines provided these credits and notices remain unmodified with any
** altered or distributed versions of the program.
**
** The main ephemeris databases and calculation routines are from the
** library SWISS EPHEMERIS and are programmed and copyright 1997-2008 by
** Astrodienst AG. Use of that source code is subject to license for Swiss
** Ephemeris Free Edition at https://www.astro.com/swisseph/swephinfo_e.htm.
** This copyright notice must not be changed or removed by any user of this
** program.
**
** Additional ephemeris databases and formulas are from the calculation
** routines in the program PLACALC and are programmed and Copyright (C)
** 1989,1991,1993 by Astrodienst AG and Alois Treindl (alois@astro.ch). The
** use of that source code is subject to regulations made by Astrodienst
** Zurich, and the code is not in the public domain. This copyright notice
** must not be changed or removed by any user of this program.
**
** The original planetary calculation routines used in this program have
** been copyrighted and the initial core of this program was mostly a
** conversion to C of the routines created by James Neely as listed in
** 'Manual of Computer Programming for Astrologers', by Michael Erlewine,
** available from Matrix Software.
**
** Atlas composed using data from https://www.geonames.org/ licensed under a
** Creative Commons Attribution 4.0 License. Time zone changes composed using
** public domain TZ database: https://data.iana.org/time-zones/tz-link.html
**
** The PostScript code within the core graphics routines are programmed
** and Copyright (C) 1992-1993 by Brian D. Willoughby (brianw@sounds.wa.com).
**
** More formally: This program is free software; you can redistribute it
** and/or modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of the
** License, or (at your option) any later version. This program is
** distributed in the hope that it will be useful and inspiring, but
** WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details, a copy of which is in the
** LICENSE.HTM file included with Astrolog, and at http://www.gnu.org
**
** Initial programming 8/28-30/1991.
** X Window graphics initially programmed 10/23-29/1991.
** PostScript graphics initially programmed 11/29-30/1992.
** Last code change made 4/22/2024.
*/
#include "astrolog.h"
/*
******************************************************************************
** Multiple Chart Scanning Routines.
******************************************************************************
*/
#ifdef GRAPH
#define RgzCalendar() gi.rgzCalendar
#else
#define RgzCalendar() NULL
#endif
// Display a list of transit events. Called from ChartInDaySearch().
void PrintInDays(InDayInfo *pid, int occurcount, int counttotal, flag fProg)
{
char sz[cchSzDef];
int fVoid, nVoid, nSkip = 0, i, j, k, s1, s2, s3;
CI ciCast = ciSave, ciEvent;
#ifdef EXPRESS
int nEclipse;
real rEclipse;
#endif
#ifdef GRAPH
int nEclipse2;
#endif
i = (RgzCalendar() == NULL ? -1 : occurcount);
loop {
i += (RgzCalendar() == NULL ? 1 : -1);
if (!FBetween(i, 0, occurcount-1))
break;
// Detect whether this aspect indicates the Moon going void of course, and
// if so how long the Moon is v/c before entering next sign. This requires
// the sign change event to be in the same list as the Moon aspect.
nVoid = -1;
fVoid = FAspectVoid(pid[i].source, pid[i].dest, pid[i].aspect);
#ifdef EXPRESS
if (RgzCalendar() != NULL &&
(i >= occurcount || pid[i].day != pid[i+1].day))
nSkip = 0;
// Adjust whether this aspect can be going v/c if AstroExpression says so.
if (!us.fExpOff && FSzSet(us.szExpVoid)) {
ExpSetN(iLetterV, 0);
ExpSetN(iLetterW, pid[i].source);
ExpSetN(iLetterX, pid[i].aspect);
ExpSetN(iLetterY, pid[i].dest);
ExpSetN(iLetterZ, fVoid);
ParseExpression(us.szExpVoid);
fVoid = NExpGet(iLetterZ);
}
#endif
if (fVoid) {
for (j = i+1; j < counttotal; j++) {
fVoid = FAspectVoid(pid[j].source, pid[j].dest, pid[j].aspect);
#ifdef EXPRESS
// Adjust whether aspect can be going v/c if AstroExpression says so.
if (!us.fExpOff && FSzSet(us.szExpVoid)) {
ExpSetN(iLetterV, 0);
ExpSetN(iLetterW, pid[j].source);
ExpSetN(iLetterX, pid[j].aspect);
ExpSetN(iLetterY, pid[j].dest);
ExpSetN(iLetterZ, fVoid);
ParseExpression(us.szExpVoid);
fVoid = NExpGet(iLetterZ);
}
#endif
if (fVoid)
break;
fVoid = (pid[j].aspect == aSig && pid[j].source == oMoo);
#ifdef EXPRESS
// Adjust whether event can be ending v/c if AstroExpression says so.
if (!us.fExpOff && FSzSet(us.szExpVoid)) {
ExpSetN(iLetterV, 1);
ExpSetN(iLetterW, pid[j].source);
ExpSetN(iLetterX, pid[j].aspect);
ExpSetN(iLetterY, pid[j].dest);
ExpSetN(iLetterZ, fVoid);
ParseExpression(us.szExpVoid);
fVoid = NExpGet(iLetterZ);
}
#endif
if (fVoid) {
nVoid = pid[j].day - pid[i].day;
if (nVoid < 0)
nVoid += DayInMonth(pid[i].mon, pid[i].yea);
nVoid *= 24*60*60;
nVoid += (int)((pid[j].time - pid[i].time) * 60.0);
break;
}
}
}
// Display the current transit event.
s1 = (int)pid[i].time/60;
s2 = (int)pid[i].time-s1*60;
s3 = us.fSeconds ? (int)(pid[i].time*60.0)-((s1*60+s2)*60) : -1;
SetCI(ciCast, pid[i].mon, pid[i].day, pid[i].yea,
pid[i].time / 60.0, Dst, Zon, Lon, Lat);
if ((!us.fExpOff && FSzSet(us.szExpDay)) || (us.fEclipse &&
!us.fParallel && (pid[i].aspect == aCon || pid[i].aspect == aOpp))) {
ciCore = ciCast;
CastChart(-1);
}
#ifdef EXPRESS
// May want to skip current event if AstroExpression says to do so.
if (!us.fExpOff && FSzSet(us.szExpDay)) {
nEclipse = NCheckEclipseAny(pid[i].source, pid[i].aspect, pid[i].dest,
&rEclipse);
ExpSetN(iLetterU, pid[i].source);
ExpSetN(iLetterV, pid[i].aspect);
ExpSetN(iLetterW, pid[i].dest);
ExpSetN(iLetterX, nVoid);
ExpSetN(iLetterY, nEclipse);
ExpSetR(iLetterZ, rEclipse);
if (!NParseExpression(us.szExpDay)) {
nSkip++;
continue;
}
}
#endif
ciSave = ciCast;
#ifdef GRAPH
// May want to draw current event within a graphic calendar box.
if (RgzCalendar() != NULL) {
for (j = i; j >= 0 && pid[j].day == pid[i].day; j--)
;
for (k = i; k < occurcount && pid[k].day == pid[i].day; k++)
;
nEclipse2 = NCheckEclipseAny(pid[i].source, pid[i].aspect, pid[i].dest,
NULL);
DrawCalendarAspect(&pid[i], i-j+nSkip, k-j, nVoid, nEclipse2);
continue;
}
#endif
if (us.fListAuto) {
// May want to add chart for current event to chart list.
ciEvent = ciSave;
*sz = chNull;
k = pid[i].aspect;
if (k > 0)
sprintf(sz, "%s %s %s", szObjDisp[pid[i].source],
SzAspectAbbrev(pid[i].aspect), szObjDisp[pid[i].dest]);
else if (k == aSig)
sprintf(sz, "%s enters %s", szObjDisp[pid[i].source],
szSignName[pid[i].dest]);
else if (k == aDir)
sprintf(sz, "%s S%c", szObjDisp[pid[i].source],
pid[i].dest ? chRet : 'D');
else if (k == aDeg)
sprintf(sz, "%s at %s", szObjDisp[pid[i].source], SzZodiac(
(real)pid[i].dest * (rDegMax / (real)(cSign * us.nSignDiv))));
else if (k == aAlt)
sprintf(sz, "%s LA%c", szObjDisp[pid[i].source],
pid[i].dest ? '+' : '-');
else if (k == aLen)
sprintf(sz, "%s %s", szObjDisp[pid[i].source],
pid[i].dest ? "Apo" : "Per");
else if (k == aNod)
sprintf(sz, "%s LA0 %s", szObjDisp[pid[i].source],
pid[i].dest ? "South" : "North");
else if (k == aDis)
sprintf(sz, "%s distance equal %s", szObjDisp[pid[i].source],
szObjDisp[pid[i].dest]);
else
Assert(fFalse);
ciEvent.nam = SzClone(sz);
ciEvent.loc = ciDefa.loc;
FAppendCIList(&ciEvent);
}
k = DayOfWeek(pid[i].mon, pid[i].day, pid[i].yea);
AnsiColor(kRainbowA[k + 1]);
sprintf(sz, "%.3s ", szDay[k]); PrintSz(sz);
AnsiColor(kDefault);
sprintf(sz, "%s %s ",
SzDate(pid[i].mon, pid[i].day, pid[i].yea, fFalse),
SzTime(s1, s2, s3)); PrintSz(sz);
PrintAspect(pid[i].source, pid[i].pos1, pid[i].ret1, pid[i].aspect,
pid[i].dest, pid[i].pos2, pid[i].ret2, fProg ? 'e' : 'd');
PrintInDayEvent(pid[i].source, pid[i].aspect, pid[i].dest, nVoid);
}
}
// Search through a day or longer period, and print out the times of exact
// aspects among planets during that day, as specified with the -d switch,
// as well as times when planets changes sign or direction. To do this, cast
// charts for the beginning and end of the day (or a part of a day) and do a
// linear equation check to see if anything happens during the interval.
void ChartInDaySearch(flag fProg)
{
InDayInfo id[MAXINDAY], idT, *pid = id;
int yea0, yea1, yea2, mon0, mon1, mon2, day0, day1, day2, counttotal = 0,
occurcount, maxinday = MAXINDAY, division, div, divSign,
i, j, k, l, s1, s2;
real divsiz, d1, d2, e1, e2, f1, f2, g;
flag fYear, fVoid, fPrint = fTrue;
CP cpA, cpB;
// If parameter 'fProg' is set, look for changes in a progressed chart.
#ifdef GRAPH
fPrint &= (RgzCalendar() == NULL);
#endif
fYear = us.fInDayMonth && us.fInDayYear;
fVoid = !FIgnore(oMoo) && !us.fIgnoreSign && us.fInDayMonth;
division = (fYear || fProg) ? (us.nDivision + 9) / 10 : us.nDivision;
divsiz = 24.0 / (real)division*60.0;
divSign = cSign * us.nSignDiv;
if (us.fListAuto)
is.cci = 0;
// If -dY in effect, then search through a range of years.
yea1 = yea2 = !fProg ? Yea : YeaT;
if (fYear && us.nEphemYears != 0) {
if (us.nEphemYears < 0)
yea1 += (us.nEphemYears + 1);
else
yea2 += (us.nEphemYears - 1);
}
for (yea0 = yea1; yea0 <= yea2; yea0++) {
// If -dy in effect, then search through the whole year, month by month.
if (fYear) {
mon1 = 1; mon2 = 12;
} else
mon1 = mon2 = !fProg ? Mon : MonT;
// Start searching the month or months in question for exciting events.
for (mon0 = mon1; mon0 <= mon2; mon0++) {
if (us.fInDayMonth) {
day1 = 1;
day2 = DayInMonth(mon0, yea0);
} else
day1 = day2 = !fProg ? Day : DayT;
// Start searching the day or days in question for exciting events.
for (day0 = day1; day0 <= day2; day0 = AddDay(mon0, day0, yea0, 1)) {
occurcount = 0;
maxinday = MAXINDAY - (int)(pid - id);
// Cast chart for beginning of day and store it for future use.
SetCI(ciCore, mon0, day0, yea0, 0.0, Dst, Zon, Lon, Lat);
us.fProgress = fProg;
if (fProg) {
is.JDp = MdytszToJulian(mon0, day0, yea0, 0.0, Dst, Zon);
ciCore = ciMain;
}
CastChart(-1);
cpB = cp0;
// Now divide the day into segments and search each segment in turn.
// More segments is slower, but has slightly better time accuracy.
for (div = 1; div <= division; div++) {
// Cast the chart for the ending time of the present segment. The
// beginning time chart is copied from the previous end time chart.
SetCI(ciCore, mon0, day0, yea0,
24.0*(real)div/(real)division, Dst, Zon, Lon, Lat);
if (fProg) {
is.JDp = MdytszToJulian(mon0, day0, yea0, TT, Dst, Zon);
ciCore = ciMain;
}
CastChart(-1);
cpA = cpB; cpB = cp0;
// Now search through the present segment for anything exciting.
for (i = 0; i <= is.nObj; i++)
if (!FIgnore(i) && (fProg || us.fGraphAll || FThing(i))) {
s1 = SFromZ(cpA.obj[i])-1;
s2 = SFromZ(cpB.obj[i])-1;
// Does the current planet change into the next or previous sign?
if (!us.fIgnoreSign && FAllow(i) && occurcount < maxinday) {
l = NAbs(s1-s2);
if (s1 != s2 && (l == 1 || l == cSign-1)) {
pid[occurcount].source = i;
pid[occurcount].aspect = aSig;
pid[occurcount].dest = s2+1;
pid[occurcount].time = MinDistance(cpA.obj[i],
(real)(cpA.dir[i] >= 0.0 ? s2 : s1) * 30.0) / MinDistance(
cpA.obj[i], cpB.obj[i])*divsiz + (real)(div-1)*divsiz;
pid[occurcount].pos1 = pid[occurcount].pos2 = ZFromS(s1+1);
pid[occurcount].ret1 = cpA.dir[i];
pid[occurcount].ret2 = cpB.dir[i];
pid[occurcount].mon = mon0;
pid[occurcount].day = day0;
pid[occurcount].yea = yea0;
occurcount++;
// Does the current planet change into next or previous degree?
} else if (us.nSignDiv > 1) {
j = (int)(cpA.obj[i] / (rDegMax / (real)divSign));
k = (int)(cpB.obj[i] / (rDegMax / (real)divSign));
l = NAbs(j-k);
if (j != k && (l == 1 || l == divSign-1)) {
l = k;
if (j == k+1 || j == k-(divSign-1))
l = j;
pid[occurcount].source = i;
pid[occurcount].aspect = aDeg;
pid[occurcount].dest = l;
pid[occurcount].time = MinDistance(cpA.obj[i],
(real)l * (rDegMax / (real)divSign)) / MinDistance(cpA.obj[i],
cpB.obj[i])*divsiz + (real)(div-1)*divsiz;
pid[occurcount].pos1 = pid[occurcount].pos2 = cpA.obj[i];
pid[occurcount].ret1 = pid[occurcount].ret2 =
(l == k) ? 1.0 : -1.0;
pid[occurcount].mon = mon0;
pid[occurcount].day = day0;
pid[occurcount].yea = yea0;
occurcount++;
}
}
}
// Does the current planet go retrograde or direct?
if (!us.fIgnoreDir && (cpA.dir[i] < 0.0) != (cpB.dir[i] < 0.0) &&
FAllow(i) && occurcount < maxinday) {
pid[occurcount].source = i;
pid[occurcount].aspect = aDir;
pid[occurcount].dest = cpB.dir[i] < 0.0;
pid[occurcount].time = RAbs(cpA.dir[i])/(RAbs(cpA.dir[i])+
RAbs(cpB.dir[i]))*divsiz + (real)(div-1)*divsiz;
pid[occurcount].pos1 = pid[occurcount].pos2 =
RAbs(cpA.dir[i])/(RAbs(cpA.dir[i])+RAbs(cpB.dir[i])) *
(cpB.obj[i]-cpA.obj[i]) + cpA.obj[i];
pid[occurcount].ret1 = pid[occurcount].ret2 = 0.0;
pid[occurcount].mon = mon0;
pid[occurcount].day = day0;
pid[occurcount].yea = yea0;
occurcount++;
}
// Does the current planet reach maximum or minimum latitude?
if (!us.fIgnoreDiralt && (cpA.diralt[i] < 0.0) != (cpB.diralt[i] < 0.0)
&& FAllow(i) && occurcount < maxinday) {
pid[occurcount].source = i;
pid[occurcount].aspect = aAlt;
pid[occurcount].dest = cpB.diralt[i] < 0.0;
pid[occurcount].time = RAbs(cpA.diralt[i])/(RAbs(cpA.diralt[i])+
RAbs(cpB.diralt[i]))*divsiz + (real)(div-1)*divsiz;
pid[occurcount].pos1 = pid[occurcount].pos2 =
RAbs(cpA.diralt[i])/(RAbs(cpA.diralt[i])+RAbs(cpB.diralt[i])) *
(cpB.alt[i]-cpA.alt[i]) + cpA.alt[i];
pid[occurcount].ret1 = cpA.dir[i]; pid[occurcount].ret2 = cpB.dir[i];
pid[occurcount].mon = mon0;
pid[occurcount].day = day0;
pid[occurcount].yea = yea0;
occurcount++;
}
// Does the current planet reach maximum or minimum distance?
if (!us.fIgnoreDirlen && (cpA.dirlen[i] < 0.0) != (cpB.dirlen[i] < 0.0)
&& FAllow(i) && occurcount < maxinday) {
pid[occurcount].source = i;
pid[occurcount].aspect = aLen;
pid[occurcount].dest = (cpB.dirlen[i] < 0.0);
pid[occurcount].time = RAbs(cpA.dirlen[i])/(RAbs(cpA.dirlen[i])+
RAbs(cpB.dirlen[i]))*divsiz + (real)(div-1)*divsiz;
pid[occurcount].pos1 = pid[occurcount].pos2 =
RAbs(cpA.dirlen[i])/(RAbs(cpA.dirlen[i])+RAbs(cpB.dirlen[i])) *
(cpB.obj[i]-cpA.obj[i]) + cpA.obj[i];
pid[occurcount].ret1 = cpA.dir[i]; pid[occurcount].ret2 = cpB.dir[i];
pid[occurcount].mon = mon0;
pid[occurcount].day = day0;
pid[occurcount].yea = yea0;
occurcount++;
}
// Does the current planet cross zero latitude?
if (!us.fIgnoreAlt0 && ((cpA.alt[i] < 0.0 && cpB.alt[i] >= 0.0) ||
(cpA.alt[i] >= 0.0 && cpB.alt[i] < 0.0)) &&
FAllow(i) && occurcount < maxinday) {
pid[occurcount].source = i;
pid[occurcount].aspect = aNod;
pid[occurcount].dest = (cpA.alt[i] >= 0.0);
pid[occurcount].time = cpA.alt[i]/(cpA.alt[i]-cpB.alt[i])*divsiz +
(real)(div-1)*divsiz;
pid[occurcount].pos1 = pid[occurcount].pos2 =
Mod(cpA.obj[i] + cpA.alt[i]/(cpA.alt[i]-cpB.alt[i]) *
MinDifference(cpA.obj[i], cpB.obj[i]));
pid[occurcount].ret1 = cpA.dir[i]; pid[occurcount].ret2 = cpB.dir[i];
pid[occurcount].mon = mon0;
pid[occurcount].day = day0;
pid[occurcount].yea = yea0;
occurcount++;
}
// Now search for anything making an aspect to the current planet.
for (j = i+1; j <= is.nObj; j++)
if (!FIgnore(j) && (fProg || us.fGraphAll || FThing(j))) {
if (!us.fParallel) {
for (k = 1; k <= us.nAsp; k++) if (FAcceptAspect(i, -k, j)) {
d1 = cpA.obj[i]; d2 = cpB.obj[i];
e1 = cpA.obj[j]; e2 = cpB.obj[j];
if (MinDistance(d1, d2) < MinDistance(e1, e2)) {
SwapR(&d1, &e1);
SwapR(&d2, &e2);
}
// Search each potential aspect in turn. First subtract the size
// of the aspect from the angular difference, so can then treat it
// like a conjunction.
if (MinDistance(e1, Mod(d1-rAspAngle[k])) <
MinDistance(e2, Mod(d2+rAspAngle[k]))) {
e1 = Mod(e1+rAspAngle[k]);
e2 = Mod(e2+rAspAngle[k]);
} else {
e1 = Mod(e1-rAspAngle[k]);
e2 = Mod(e2-rAspAngle[k]);
}
// Check to see if the aspect actually occurs during this segment,
// making sure to take into account if one or both planets are
// retrograde or if they cross the Aries point.
f1 = e1-d1;
if (RAbs(f1) > rDegHalf)
f1 -= RSgn(f1)*rDegMax;
f2 = e2-d2;
if (RAbs(f2) > rDegHalf)
f2 -= RSgn(f2)*rDegMax;
if (MinDistance(Midpoint(d1, d2), Midpoint(e1, e2)) < rDegQuad &&
RSgn(f1) != RSgn(f2) && occurcount < maxinday) {
pid[occurcount].source = i;
pid[occurcount].aspect = k;
pid[occurcount].dest = j;
pid[occurcount].mon = mon0;
pid[occurcount].day = day0;
pid[occurcount].yea = yea0;
// Horray! The aspect occurs sometime during the interval. Now
// just have to solve an equation in two variables to find out
// where their "lines" of motion cross, i.e. the aspect's time.
f1 = d2-d1;
if (RAbs(f1) > rDegHalf)
f1 -= RSgn(f1)*rDegMax;
f2 = e2-e1;
if (RAbs(f2) > rDegHalf)
f2 -= RSgn(f2)*rDegMax;
g = (RAbs(d1-e1) > rDegHalf ?
(d1-e1)-RSgn(d1-e1)*rDegMax : d1-e1)/(f2-f1);
pid[occurcount].time = g*divsiz + (real)(div-1)*divsiz;
pid[occurcount].pos1 = Mod(cpA.obj[i] +
RSgn(cpB.obj[i]-cpA.obj[i])*
(RAbs(cpB.obj[i]-cpA.obj[i]) > rDegHalf ? -1 : 1)*
RAbs(g)*MinDistance(cpA.obj[i], cpB.obj[i]));
pid[occurcount].pos2 = Mod(cpA.obj[j] +
RSgn(cpB.obj[j]-cpA.obj[j])*
(RAbs(cpB.obj[j]-cpA.obj[j]) > rDegHalf ? -1 : 1)*
RAbs(g)*MinDistance(cpA.obj[j], cpB.obj[j]));
pid[occurcount].ret1 = (cpA.dir[i] + cpB.dir[i]) / 2.0;
pid[occurcount].ret2 = (cpA.dir[j] + cpB.dir[j]) / 2.0;
occurcount++;
}
}
} else {
for (k = 1; k <= Min(us.nAsp, aOpp); k++)
if (FAcceptAspect(i, -k, j)) {
d1 = cpA.alt[i]; d2 = cpB.alt[i];
e1 = cpA.alt[j]; e2 = cpB.alt[j];
if (!us.fEquator2 && !us.fParallel2) {
// If have ecliptic latitude and want declination, convert.
g = cpA.obj[i]; EclToEqu(&g, &d1);
g = cpB.obj[i]; EclToEqu(&g, &d2);
g = cpA.obj[j]; EclToEqu(&g, &e1);
g = cpB.obj[j]; EclToEqu(&g, &e2);
} else if (us.fEquator2 && us.fParallel2) {
// If have equatorial declination and want latitude, convert.
g = cpA.obj[i]; EquToEcl(&g, &d1);
g = cpB.obj[i]; EquToEcl(&g, &d2);
g = cpA.obj[j]; EquToEcl(&g, &e1);
g = cpB.obj[j]; EquToEcl(&g, &e2);
}
// Search each potential aspect in turn. Negate the sign of the
// aspect if needed, so can then treat it like a parallel.
if (k == aOpp) {
neg(e1);
neg(e2);
}
// Check if the aspect actually occurs during this segment, making
// sure to take into account if one or both planets are retrograde.
f1 = e1-d1;
f2 = e2-d2;
if (RSgn(f1) != RSgn(f2) && occurcount < maxinday) {
pid[occurcount].source = i;
pid[occurcount].aspect = k;
pid[occurcount].dest = j;
pid[occurcount].mon = mon0;
pid[occurcount].day = day0;
pid[occurcount].yea = yea0;
// Horray! The aspect occurs sometime during the interval. Now
// just have to solve an equation in two variables to find out
// where their "lines" of motion cross, i.e. the aspect's time.
f1 = d2-d1;
f2 = e2-e1;
g = (d1-e1)/(f2-f1);
if (k == aOpp) {
neg(e1);
neg(e2);
}
pid[occurcount].time = g*divsiz + (real)(div-1)*divsiz;
pid[occurcount].pos1 = d1 + (d2 - d1)*g;
pid[occurcount].pos2 = e1 + (e2 - e1)*g;
pid[occurcount].ret1 = (cpA.diralt[i] + cpB.diralt[i]) / 2.0;
pid[occurcount].ret2 = (cpA.diralt[j] + cpB.diralt[j]) / 2.0;
occurcount++;
}
}
} // us.fParallel
// Check for planet pairs equidistant from each other.
if (!us.fIgnoreDisequ) {
d1 = cpA.dist[i]; d2 = cpB.dist[i];
e1 = cpA.dist[j]; e2 = cpB.dist[j];
f1 = e1-d1; f2 = e2-d2;
if (RSgn(f1) != RSgn(f2) && occurcount < maxinday) {
pid[occurcount].source = i;
pid[occurcount].aspect = aDis;
pid[occurcount].dest = j;
pid[occurcount].mon = mon0;
pid[occurcount].day = day0;
pid[occurcount].yea = yea0;
f1 = d2-d1; f2 = e2-e1;
g = (d1-e1)/(f2-f1);
pid[occurcount].time = g*divsiz + (real)(div-1)*divsiz;
pid[occurcount].pos1 = Mod(cpA.obj[i] +
RSgn(cpB.obj[i]-cpA.obj[i])*
(RAbs(cpB.obj[i]-cpA.obj[i]) > rDegHalf ? -1 : 1)*
RAbs(g)*MinDistance(cpA.obj[i], cpB.obj[i]));
pid[occurcount].pos2 = Mod(cpA.obj[j] +
RSgn(cpB.obj[j]-cpA.obj[j])*
(RAbs(cpB.obj[j]-cpA.obj[j]) > rDegHalf ? -1 : 1)*
RAbs(g)*MinDistance(cpA.obj[j], cpB.obj[j]));
pid[occurcount].ret1 = (cpA.dir[i] + cpB.dir[i]) / 2.0;
pid[occurcount].ret2 = (cpA.dir[j] + cpB.dir[j]) / 2.0;
occurcount++;
}
}
}
} // i
} // div
// After all the aspects and evemts in the day have been located, sort
// them by time at which they occur, so can print them in order.
for (i = 1; i < occurcount; i++) {
j = i-1;
while (j >= 0 && pid[j].time > pid[j+1].time) {
idT = pid[j]; pid[j] = pid[j+1]; pid[j+1] = idT;
j--;
}
}
// Finally, loop through and display each aspect and when it occurs.
if (!fVoid || (day0 >= day2 && mon0 >= mon2 && yea0 >= yea2)) {
// If no v/c aspects, or reached end of period, output all at once.
if (fVoid) {
occurcount += (int)(pid - id);
pid = id;
}
PrintInDays(id, occurcount, occurcount, fProg);
} else {
// Output a chunk of events, knowing there's more to come.
pid += occurcount;
j = MAXINDAY >> 2;
if (pid - id > j << 1) {
#ifdef GRAPH
if (RgzCalendar() != NULL && id[j].day != id[0].day) {
// Don't split day when drawing within calendar boxes.
while (j > 0 && id[j].day == id[j-1].day)
j--;
}
#endif
PrintInDays(id, j, pid - id, fProg);
for (i = 0; i < pid - id - j; i++)
id[i] = id[i + j];
pid -= j;
}
}
if (occurcount >= maxinday && fPrint)
PrintSz("Too many transit events found.\n");
counttotal += occurcount;
} // day0
} // mon0
} // yea0
if (counttotal == 0 && fPrint)
PrintSz("No transit events found.\n");
// Recompute original chart placements as have overwritten them.
ciCore = ciMain;
CastChart(1);
}
// Search through a month, year, or years, and print out the times of exact
// transits where planets in the time frame make aspect to the planets in
// some other chart, as specified with the -t switch. To do this, cast charts
// for the start and end of each month, or within a month, and do an equation
// check for aspects to the other base chart during the interval.
void ChartTransitSearch(flag fProg)
{
TransInfo ti[MAXINDAY], tiT, *pti;
char sz[cchSzDef];
int M1, M2, Y1, Y2, counttotal = 0, occurcount, division, div, nAsp, fNoCusp,
nSkip = 0, i, j, k, s1, s2, s3, s4, s1prev = 0;
real divsiz, daysiz, d, e1, e2, f1, f2, mc = is.MC, ob = is.OB;
flag fPrint = fTrue;
CP cpA, cpB, cpN = cp0;
CI ciSav, ciCast = ciSave, ciEvent;
// Save away natal chart and initialize things.
#ifdef GRAPH
InDayInfo idT;
fPrint &= (RgzCalendar() == NULL);
#endif
ciSav = ciTran;
if (fProg)
fNoCusp = fFalse;
else {
fNoCusp = fTrue;
for (i = cuspLo; i <= cuspHi; i++)
fNoCusp &= ignore2[i];
}
division = us.nDivision;
if (!fProg && !fNoCusp)
division = Max(division, 96);
nAsp = is.fReturn ? aCon : us.nAsp;
if (us.fParallel)
nAsp = Min(nAsp, aOpp);
if (us.fListAuto)
is.cci = 0;
Y1 = Y2 = YeaT;
M1 = M2 = MonT;
if (us.fInDayYear) {
M1 = 1; M2 = 12;
if (us.nEphemYears != 0) {
if (us.nEphemYears < 0)
Y1 += (us.nEphemYears + 1);
else
Y2 += (us.nEphemYears - 1);
}
}
// Start searching the year or years in question for any transits.
for (YeaT = Y1; YeaT <= Y2; YeaT++)
// Start searching the month or months in question for any transits.
for (MonT = M1; MonT <= M2; MonT++) {
occurcount = 0; pti = ti;
daysiz = (real)(us.fInDayMonth ? DayInMonth(MonT, YeaT) : 1)*24.0*60.0;
divsiz = daysiz / (real)division;
// Cast chart for beginning of month and store it for future use.
SetCI(ciCore, MonT, us.fInDayMonth ? 1 : DayT, YeaT, 0.0, DstT, ZonT,
LonT, LatT);
if (us.fProgress = fProg) {
is.JDp = MdytszToJulian(MM, DD, YY, TT, SS, ZZ);
ciCore = ciMain;
}
for (i = 0; i <= is.nObj; i++)
SwapN(ignore[i], ignore2[i]);
CastChart(-1);
for (i = 0; i <= is.nObj; i++)
SwapN(ignore[i], ignore2[i]);
cpB = cp0;
// Divide month into segments and then search each segment in turn.
for (div = 1; div <= division; div++) {
if (fPrint) {
occurcount = 0; pti = ti;
}
// Cast the chart for the ending time of the present segment, and copy
// the start time chart from the previous end time chart.
d = (us.fInDayMonth ? 1.0 : (real)DayT) +
(daysiz/24.0/60.0)*(real)div/(real)division;
SetCI(ciCore, MonT, (int)d, YeaT, RFract(d)*24.0,
DstT, ZonT, LonT, LatT);
if (fProg) {
is.JDp = MdytszToJulian(MM, DD, YY, TT, SS, ZZ);
ciCore = ciMain;
}
for (i = 0; i <= oNorm; i++)
SwapN(ignore[i], ignore2[i]);
CastChart(-1);
for (i = 0; i <= oNorm; i++)
SwapN(ignore[i], ignore2[i]);
cpA = cpB; cpB = cp0;
// Now search through the present segment for any transits. Note that
// stars can be transited, but they can't make transits themselves.
for (i = 0; i <= is.nObj; i++) {
// Check if 3D house change occurs during time segment.
if (us.fHouse3D && !us.fIgnoreSign && !FIgnore2(i)) {
is.MC = mc; is.OB = ob;
e1 = cpA.obj[i]; f1 = RHousePlaceIn3D(e1, cpA.alt[i]);
e2 = cpB.obj[i]; f2 = RHousePlaceIn3D(e2, cpB.alt[i]);
s1 = SFromZ(f1)-1; s2 = SFromZ(f2)-1;
k = NAbs(s1-s2);
if (s1 != s2 && (k == 1 || k == cSign-1) && !FIgnore(cuspLo+s2) &&
occurcount < MAXINDAY) {
pti->source = i;
pti->aspect = aHou;
pti->dest = s2+1;
pti->time = MinDistance(f1,
(real)(cpA.dir[i] >= 0.0 ? s2 : s1) * 30.0) /
MinDistance(f1, f2)*divsiz + (real)(div-1)*divsiz;
pti->posT = cpA.obj[i];
pti->posN = cpN.obj[i];
pti->retT = (cpA.dir[i] + cpB.dir[i]) / 2.0;
occurcount++, pti++;
}
}
if (FIgnore(i))
continue;
for (j = 0; j <= oNorm; j++) {
if ((is.fReturn ? i != j : FIgnore2(j)) || (fNoCusp && !FThing(j)))
continue;
// Between each pair of planets, check if they make any aspects.
if (!us.fParallel) {
for (k = 1; k <= nAsp; k++) if (FAcceptAspect(i, k, j)) {
d = cpN.obj[i]; e1 = cpA.obj[j]; e2 = cpB.obj[j];
if (MinDistance(e1, Mod(d-rAspAngle[k])) <
MinDistance(e2, Mod(d+rAspAngle[k]))) {
e1 = Mod(e1+rAspAngle[k]);
e2 = Mod(e2+rAspAngle[k]);
} else {
e1 = Mod(e1-rAspAngle[k]);
e2 = Mod(e2-rAspAngle[k]);
}
// Check to see if the present aspect actually occurs during the
// segment, making sure we check any Aries point crossings.
f1 = e1-d;
if (RAbs(f1) > rDegHalf)
f1 -= RSgn(f1)*rDegMax;
f2 = e2-d;
if (RAbs(f2) > rDegHalf)
f2 -= RSgn(f2)*rDegMax;
if (MinDistance(d, Midpoint(e1, e2)) < rDegQuad &&
RSgn(f1) != RSgn(f2) && occurcount < MAXINDAY) {
// Ok, have found a transit! Now determine the time and save
// this transit in our list to be printed.
pti->source = j;
pti->aspect = k;
pti->dest = i;
pti->time = RAbs(f1)/(RAbs(f1)+RAbs(f2))*divsiz +
(real)(div-1)*divsiz;
pti->posT = Mod(MinDistance(cpA.obj[j], Mod(d-rAspAngle[k])) <
MinDistance(cpB.obj[j], Mod(d+rAspAngle[k])) ?
d-rAspAngle[k] : d+rAspAngle[k]);
pti->posN = cpN.obj[i];
pti->retT = (cpA.dir[j] + cpB.dir[j]) / 2.0;
occurcount++, pti++;
}
}
} else {
for (k = 1; k <= nAsp; k++) if (FAcceptAspect(i, k, j)) {
d = cpN.alt[i]; e1 = cpA.alt[j]; e2 = cpB.alt[j];
if (!us.fEquator2 && !us.fParallel2) {
// If have ecliptic latitude and want declination, convert.
f1 = cpN.obj[i]; EclToEqu(&f1, &d);
f1 = cpA.obj[j]; EclToEqu(&f1, &e1);
f2 = cpB.obj[j]; EclToEqu(&f2, &e2);
} else if (us.fEquator2 && us.fParallel2) {
// If have equatorial declination and want latitude, convert.
f1 = cpN.obj[i]; EquToEcl(&f1, &d);
f1 = cpA.obj[j]; EquToEcl(&f1, &e1);
f2 = cpB.obj[j]; EquToEcl(&f2, &e2);
}
if (k == aOpp) {
neg(e1);
neg(e2);
}
// Check if parallel aspect occurs during time segment.
f1 = e1-d;
f2 = e2-d;
if (RSgn(f1) != RSgn(f2) && occurcount < MAXINDAY) {
// Ok, found a parallel transit. Now determine the time and save
// this transit in the list to be printed.
if (k == aOpp) {
neg(e1);
neg(e2);
}
pti->source = j;
pti->aspect = k;
pti->dest = i;
pti->time = RAbs(f1)/(RAbs(f1)+RAbs(f2))*divsiz +
(real)(div-1)*divsiz;
pti->posT = e1 + (e2 - e1)*RAbs(f1)/(RAbs(f1)+RAbs(f2));
pti->posN = d;
pti->retT = (cpA.diralt[j] + cpB.diralt[j]) / 2.0;
occurcount++, pti++;
}
}
} // us.fParallel
// Check for planet pairs equidistant from each other.
if (!us.fIgnoreDisequ) {
d = cpN.dist[i]; e1 = cpA.dist[j]; e2 = cpB.dist[j];
if (((d > e1 && d < e2) || (d > e2 && d < e1)) &&
occurcount < MAXINDAY) {
f1 = d-e1; f2 = e2-d;
pti->source = j;
pti->aspect = aDis;
pti->dest = i;
pti->time = RAbs(f1)/(RAbs(f1)+RAbs(f2))*divsiz +
(real)(div-1)*divsiz;
pti->posT = Mod(cpA.obj[j] + RAbs(f1)/(RAbs(f1)+RAbs(f2)) *
MinDifference(cpA.obj[j], cpB.obj[j]));
pti->posN = cpN.obj[i];
pti->retT = (cpA.dir[j] + cpB.dir[j]) / 2.0;
occurcount++, pti++;
}
}
} // j
} // i
#ifdef GRAPH
// May want to draw current transit event within a graphic calendar box.
if (RgzCalendar() != NULL && div < division)
continue;
#endif
// After all transits located, sort them by time at which they occur.
for (i = 1; i < occurcount; i++) {
j = i-1;
while (j >= 0 && ti[j].time > ti[j+1].time) {
tiT = ti[j]; ti[j] = ti[j+1]; ti[j+1] = tiT;
j--;
}
}
// Now loop through list and display all the transits.
i = (RgzCalendar() == NULL ? -1 : occurcount);
loop {
i += (RgzCalendar() == NULL ? 1 : -1);
if (!FBetween(i, 0, occurcount-1))
break;
pti = &ti[i];
j = (int)(pti->time * 60.0);
if (us.fInDayMonth) {
s1 = j / (24*60*60);
j = j - s1 * (24*60*60);
} else
s1 = DayT-1;
s2 = j / (60*60);
k = j - s2 * (60*60);
s3 = k / 60;
s4 = us.fSeconds ? k - s3*60 : -1;
SetCI(ciCast, MonT, s1+1, YeaT, (real)j / (60.0*60.0),
DstT, ZonT, LonT, LatT);
#ifdef EXPRESS
if (RgzCalendar() != NULL && (i >= occurcount || s1 != s1prev))
nSkip = 0;
s1prev = s1;
// May want to skip this transit if AstroExpression says to do so.
if (!us.fExpOff && FSzSet(us.szExpTra)) {
ciCore = ciCast;
CastChart(-1);
ExpSetN(iLetterX, pti->source);
ExpSetN(iLetterY, pti->aspect);
ExpSetN(iLetterZ, pti->dest);
if (!NParseExpression(us.szExpTra)) {
nSkip++;
continue;
}
}
#endif
ciSave = ciCast;
#ifdef GRAPH
// May want to draw current transit within a graphic calendar box.
if (RgzCalendar() != NULL) {
for (j = i; j >= 0 && (int)ti[j].time/(24*60)+1 == ciSave.day; j--)
;
for (k = i; k < occurcount &&
(int)ti[k].time/(24*60)+1 == ciSave.day; k++)
;
idT.source = pti->source; idT.aspect = pti->aspect;
idT.dest = pti->dest; idT.ret1 = pti->retT;
idT.mon = -1; idT.day = ciSave.day; idT.time = pti->time;