-
Notifications
You must be signed in to change notification settings - Fork 67
/
general.cpp
2808 lines (2350 loc) · 74.9 KB
/
general.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: general.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 ([email protected], 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 ([email protected]). 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 ([email protected]).
**
** 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"
/*
******************************************************************************
** General Procedures.
******************************************************************************
*/
// Swap two floating point values.
void SwapR(real *d1, real *d2)
{
real temp;
temp = *d1; *d1 = *d2; *d2 = temp;
}
// Return the length of a string (not counting the null terminator).
int CchSz(CONST char *sz)
{
CONST char *pch = sz;
while (*pch)
pch++;
return (int)(pch - sz);
}
// Return the length of a string (not counting the null terminator). Like
// CchSz() but treat UTF8 byte sequences as a single character when necessary.
int CwchSz(CONST char *sz)
{
CONST char *pch;
int cwch, dwch;
if (us.nCharset < ccUTF8)
return CchSz(sz);
cwch = 0;
for (pch = sz; *pch; pch += dwch, cwch++)
dwch = UTF8ToWch((uchar *)pch, NULL);
return cwch;
}
// Compare two strings case sensitively. Return 0 if equal, negative number if
// first less than second, and positive number if first greater than second.
int NCompareSz(CONST char *sz1, CONST char *sz2)
{
if (sz1 == NULL || sz2 == NULL)
return (sz1 == sz2);
while (*sz1 && *sz1 == *sz2)
sz1++, sz2++;
return (int)*sz1 - *sz2;
}
// Compare two strings case insensitively. Return 0 if equal, negative number
// if first less than second, and positive if first greater than second.
int NCompareSzI(CONST char *sz1, CONST char *sz2)
{
if (sz1 == NULL || sz2 == NULL)
return (sz1 == sz2);
while (*sz1 && ChCap(*sz1) == ChCap(*sz2))
sz1++, sz2++;
return (int)ChCap(*sz1) - ChCap(*sz2);
}
// Return whether two ranges of characters are equal. Either string ending
// prematurely with a zero terminator makes the strings not equal.
flag FEqRgch(CONST char *rgch1, CONST char *rgch2, int cch, flag fInsensitive)
{
int ich;
if (!fInsensitive) {
for (ich = 0; ich < cch; ich++) {
if (rgch1[ich] == chNull || rgch1[ich] != rgch2[ich])
return fFalse;
}
} else {
for (ich = 0; ich < cch; ich++) {
if (rgch1[ich] == chNull || ChCap(rgch1[ich]) != ChCap(rgch2[ich]))
return fFalse;
}
}
return fTrue;
}
// Return whether the first string matches the second, case insensitively.
// The first string may be truncated, but the first three chars must match.
flag FMatchSz(CONST char *sz1, CONST char *sz2)
{
CONST char *szStart = sz1;
while (*sz1 && ChCap(*sz1) == ChCap(*sz2))
sz1++, sz2++;
return *sz1 == chNull && (*sz2 == chNull || sz1 - szStart >= 3);
}
// Return whether the first string matches any string in the second, case
// sensitively. The second string is subdivided by comma or semicolon
// characters. Return offset into string, and optionally the index into list.
CONST char *SzInList(CONST char *sz1, CONST char *sz2, int *pisz)
{
CONST char *szStart = sz1;
int isz = 0;
loop {
// Compate string to current string in string list.
for (sz1 = szStart; *sz1 && *sz1 == *sz2; sz1++, sz2++)
;
if (*sz2 == chNull || (*sz2 == chSep || *sz2 == chSep2)) {
if (*sz1 == chNull) {
// Match if reached end of string and of current string in list.
if (pisz != NULL)
*pisz = isz;
return sz2 + (*sz2 == chSep || *sz2 == chSep2);
}
} else {
// Skip ahead to start of next string in string list.
while (*sz2 && !(*sz2 == chSep || *sz2 == chSep2))
sz2++;
}
if (*sz2 == chSep || *sz2 == chSep2)
sz2++;
else
break; // If no separator, then end of string list reached.
isz++;
}
if (pisz != NULL)
*pisz = -1;
return NULL;
}
// Set a given number of bytes to zero given a starting pointer.
void ClearB(pbyte pb, int cb)
{
while (cb-- > 0)
*pb++ = 0;
}
// Copy a given number of bytes from one location to another.
void CopyRgb(CONST byte *pbSrc, byte *pbDst, int cb)
{
while (cb-- > 0)
*pbDst++ = *pbSrc++;
}
// Copy a range of characters and zero terminate it. If there are too many
// characters to fit in the destination buffer, the string is truncated.
void CopyRgchToSz(CONST char *pch, int cch, char *sz, int cchMax)
{
cch = Min(cch, cchMax-1);
CopyRgb((pbyte)pch, (pbyte)sz, cch);
sz[cch] = chNull;
}
// Determine the sign of a number: -1 if value negative, +1 if value positive,
// and 0 if it's zero.
real RSgn(real r)
{
return r == 0.0 ? 0.0 : RSgn2(r);
}
// Given an x and y coordinate, return the angle formed by a line from the
// origin to this coordinate. This is just converting from rectangular to
// polar coordinates, however this doesn't involve the radius here.
real RAngle(real x, real y)
{
real a;
if (x != 0.0) {
if (y != 0.0)
a = RAtn(y/x);
else
a = x < 0.0 ? rPi : 0.0;
} else
a = y < 0.0 ? -rPiHalf : rPiHalf;
if (a < 0.0)
a += rPi;
if (y < 0.0)
a += rPi;
return a;
}
// Like RAngle() but return the angle between two 3D vectors instead.
real VAngle(CONST PT3R *v1, CONST PT3R *v2)
{
real angle, len1, len2;
len1 = PtLen((*v1));
len2 = PtLen((*v2));
if (len1 != 0.0 && len2 != 0.0) {
angle = PtDot((*v1), (*v2))/len1/len2;
if (angle == 0.0)
return rPiHalf;
else if (angle <= -1.0)
return rPi;
angle = RAtn(RSqr(1.0 - Sq(angle)) / angle);
if (angle >= 0.0)
return angle;
else
return angle + rPi;
} else
return rPiHalf;
}
// Modulus function for floating point values, in which we bring the given
// parameter to within the range of 0 to 360.
real Mod(real d)
{
if (d >= rDegMax) // In most cases, value is only slightly
d -= rDegMax; // out of range, so can test for it and
else if (d < 0.0) // avoid the more complicated arithmetic.
d += rDegMax;
if (d >= 0 && d < rDegMax)
return d;
return (d - RFloor(d/rDegMax)*rDegMax);
}
// Integer division, like the "/" operator but always rounds result down.
long Dvd(long x, long y)
{
long z;
if (y == 0)
return x;
z = x / y;
if (((x >= 0) == (y >= 0)) || x-z*y == 0)
return z;
return z - 1;
}
// Lookup a string within a table (case insensitively) returning the index
// that goes with the matched string, or -1 if the string is not found.
int SzLookup(CONST StrLook *rgStrLook, CONST char *sz)
{
CONST char *pch1, *pch2;
int irg;
for (irg = 0; rgStrLook[irg].isz >= 0; irg++) {
for (pch1 = sz, pch2 = rgStrLook[irg].sz;
*pch1 && ChCap(*pch1) == ChCap(*pch2); pch1++, pch2++)
;
if (*pch1 == chNull && (*pch2 == chNull || pch1 - sz >= 3))
return rgStrLook[irg].isz;
}
return -1;
}
// Return whether a zero terminated string is a substring of another string,
// case insensitively.
flag FEqSzSubI(CONST char *sz1, CONST char *sz2)
{
while (*sz1 && ChCap(*sz1) == ChCap(*sz2))
sz1++, sz2++;
return *sz1 == chNull;
}
// Set a string to a floating point value, with at most 'n' significant
// fractional digits, and dropping trailing '0' characters.
void FormatR(char *sz, real r, int n)
{
char szT[cchSzDef], *pch;
int x = n/100, y = NAbs(n%100);
// If n > 100, use 100's place as minimum field length for entire number.
if (x != 0)
sprintf(szT, "%%%d.%df", NAbs(x) + y + 1, y);
else
sprintf(szT, "%%.%df", NAbs(n));
sprintf(sz, szT, r);
for (pch = sz; *pch; pch++)
;
while (pch > sz && *(--pch) == '0') // Drop off any trailing 0 digits.
;
// Positive n means ensure at least one fractional digit.
pch[n > 0 ? 1 + (*pch == '.') : (*pch != '.')] = chNull;
}
// Blend two RGB colors along the specified proportion between them. Returned
// color ranges from the first color (ratio = 0) to the second (ratio = 1).
KV KvBlend(KV kv1, KV kv2, real rRatio)
{
return Rgb((int)((real)(RgbR(kv2) - RgbR(kv1)) * rRatio) + RgbR(kv1),
(int)((real)(RgbG(kv2) - RgbG(kv1)) * rRatio) + RgbG(kv1),
(int)((real)(RgbB(kv2) - RgbB(kv1)) * rRatio) + RgbB(kv1));
}
#define rHueMax rDegMax
#define rHueHalf rDegHalf
#define rHue13 120.0
#define rHue23 240.0
#define rHue16 60.0
// Return a RGB color of the rainbow given a number 0-360, in which 0 is red,
// 120 is green, and 240 is blue.
KV KvHue(real deg)
{
int nR, nG, nB;
real rDiff;
while (deg >= rHueMax)
deg -= rHueMax;
while (deg < 0.0)
deg += rHueMax;
rDiff = RAbs(deg - rHueHalf);
if (rDiff > rHue13)
nR = 255;
else if (rDiff < rHue16)
nR = 0;
else
nR = NMultDiv((int)(rDiff - rHue16), 255, rHue16);
rDiff = RAbs(deg - rHue13);
if (rDiff < rHue16)
nG = 255;
else if (rDiff > rHue13)
nG = 0;
else
nG = NMultDiv((int)(rHue13 - rDiff), 255, rHue16);
rDiff = RAbs(deg - rHue23);
if (rDiff < rHue16)
nB = 255;
else if (rDiff > rHue13)
nB = 0;
else
nB = NMultDiv((int)(rHue13 - rDiff), 255, rHue16);
return Rgb(nR, nG, nB);
}
CONST int rgnHue2[cSign+1] =
{0, 15, 30, 45, 60, 75, 120, 180, 210, 240, 270, 315, 360};
// Return a RGB color of the rainbow given a number 0-360, in which 0 is red,
// 120 is yellow, and 240 is blue. This aligns with paint based RYB primary
// colors, instead of light based RGB colors as in KvHue().
KV KvHue2(real deg)
{
int sig;
while (deg >= rHueMax)
deg -= rHueMax;
while (deg < 0.0)
deg += rHueMax;
sig = SFromZ(deg)-1;
deg = (real)rgnHue2[sig] +
(deg - (real)(sig*30)) / 30.0 * (real)(rgnHue2[sig+1] - rgnHue2[sig]);
return KvHue(deg);
}
/*
******************************************************************************
** General Astrology Procedures.
******************************************************************************
*/
// A similar modulus function: Convert an integer to value from 1-12.
int Mod12(int i)
{
while (i > cSign)
i -= cSign;
while (i < 1)
i += cSign;
return i;
}
// Convert an inputed fractional degrees/minutes value to a true decimal
// degree quantity. For example, the user enters the decimal value "10.30"
// to mean 10 degrees and 30 minutes; this will return 10.5, i.e. 10 degrees
// and 30 minutes expressed as a floating point degree value.
real DecToDeg(real d)
{
return RSgn(d)*(RFloor(RAbs(d))+RFract(RAbs(d))*100.0/60.0);
}
// This is the inverse of the above function. Given a true decimal value for
// a zodiac degree, adjust it so the degrees are in the integer part and the
// minute expressed as hundredths, e.g. 10.5 degrees -> 10.30
real DegToDec(real d)
{
return RSgn(d)*(RFloor(RAbs(d))+RFract(RAbs(d))*60.0/100.0);
}
// Return the shortest distance between two degrees in the zodiac. This is
// normally their difference, but we have to check if near the Aries point.
real MinDistance(real deg1, real deg2)
{
real r;
r = RAbs(deg1-deg2);
return r <= rDegHalf ? r : rDegMax - r;
}
// This is just like the above routine, except the min distance value returned
// will either be positive or negative based on whether the second value is
// ahead or behind the first one in a circular zodiac.
real MinDifference(real deg1, real deg2)
{
real r;
r = deg2 - deg1;
if (RAbs(r) < rDegHalf)
return r;
return r >= 0 ? r - rDegMax : r + rDegMax;
}
// Return the degree of the midpoint between two zodiac positions, making sure
// we return the true midpoint closest to the positions in question.
real Midpoint(real deg1, real deg2)
{
real mid;
mid = (deg1+deg2)/2.0;
return MinDistance(deg1, mid) < rDegQuad ? mid : Mod(mid+rDegHalf);
}
// Return the minimum great circle distance between two sets of spherical
// coordinates. This is like MinDistance() but takes latitude into account.
real SphDistance(real lon1, real lat1, real lon2, real lat2)
{
real dLon, r;
dLon = RAbs(lon1 - lon2);
r = RAcosD(RSinD(lat1)*RSinD(lat2) + RCosD(lat1)*RCosD(lat2)*RCosD(dLon));
return r;
}
// Given two pairs of coordinates on a sphere, return coordinates at some
// proportion (0.0-1.0) along the great circle path between them.
void SphRatio(real lon1, real lat1, real lon2, real lat2, real rRatio,
real *lon, real *lat)
{
real x1, y1, z1, x2, y2, z2, x, y, z, len, ang, adj, ang2;
SphToRec(1.0, lon1, lat1, &x1, &y1, &z1);
SphToRec(1.0, lon2, lat2, &x2, &y2, &z2);
if (rRatio != 0.5) {
// Bisecting an arc is easy, however other proportions require extra math.
len = RLength3(x2 - x1, y2 - y1, z2 - z1) / 2.0;
ang = RAsinD(len);
adj = 1.0 / RTanD(ang);
rRatio = (rRatio - 0.5) / 0.5;
ang2 = rRatio * ang;
rRatio = adj * RTanD(ang2);
rRatio = (rRatio / 2.0) + 0.5;
}
x = x1 + (x2 - x1) * rRatio;
y = y1 + (y2 - y1) * rRatio;
z = z1 + (z2 - z1) * rRatio;
RecToSph3(x, y, z, lon, lat);
}
// Given a planet and sign, determine whether: The planet rules the sign or
// is in detriment in the sign, the planet exalts in sign or is in fall /
// debilitated in sign, the planet esoterically and hierarchically and ray
// rules or is in detriment in the sign, and return an appropriate string.
char *Dignify(int obj, int sign)
{
static char szDignify[7];
int sign2 = Mod12(sign+6), ray, ich;
sprintf(szDignify, "-_____");
if (obj > oNorm)
goto LExit;
// Check standard rulerships.
if (!ignore7[rrStd]) {
if (ruler1[obj] == sign || ruler2[obj] == sign)
szDignify[rrStd+1] = 'R';
else if (ruler1[obj] == sign2 || ruler2[obj] == sign2)
szDignify[rrStd+1] = 'd';
}
if (!ignore7[rrExa]) {
if (exalt[obj] == sign)
szDignify[rrExa+1] = 'X';
else if (exalt[obj] == sign2)
szDignify[rrExa+1] = 'f';
}
// Check esoteric rulerships.
if (!ignore7[rrEso]) {
if (rgObjEso1[obj] == sign || rgObjEso2[obj] == sign)
szDignify[rrEso+1] = 'S';
else if (rgObjEso1[obj] == sign2 || rgObjEso2[obj] == sign2)
szDignify[rrEso+1] = 's';
}
if (!ignore7[rrHie]) {
if (rgObjHie1[obj] == sign || rgObjHie2[obj] == sign)
szDignify[rrHie+1] = 'H';
else if (rgObjHie1[obj] == sign2 || rgObjHie2[obj] == sign2)
szDignify[rrHie+1] = 'h';
}
if (!ignore7[rrRay]) {
ray = rgObjRay[obj];
if (ray > 0) {
if (rgSignRay2[sign][ray] > 0)
szDignify[rrRay+1] = 'Y';
else if (rgSignRay2[sign2][ray] > 0)
szDignify[rrRay+1] = 'z';
}
}
LExit:
// Put "most significant" rulership state present in the first character.
// Order: Standard rulership, exaltation, esoteric, Hierarchical, Ray.
for (ich = 1; ich <= rrMax; ich += (ich == 1 ? 3 :
(ich == 4 ? -2 : (ich == 3 ? 2 : 1)))) {
if (szDignify[ich] != '_') {
szDignify[0] = szDignify[ich];
break;
}
}
return szDignify;
}
// Process the list of each sign's rays, creating a grid based on it
// indicating whether each ray applies to a sign, and its proportion.
void EnsureRay()
{
int i, j, c, n;
for (i = 1; i <= cSign; i++) {
for (j = 1; j <= cRay; j++)
rgSignRay2[i][j] = 0;
c = 0;
n = rgSignRay[i];
while (n) {
j = n % 10;
n /= 10;
if (!FBetween(j, 1, cRay))
continue;
rgSignRay2[i][j] = 1;
c++;
}
for (j = 1; j <= cRay; j++)
rgSignRay2[i][j] *= 420 / c;
}
}
// Initialize table of star brightnesses. Usually only called once before
// first star accessed, but may be redone if computation method changes.
void EnsureStarBright()
{
int i;
real rMode;
rMode = FCmSwissStar() ? 1.0 : 0.0;
if (rStarBrightDef[0] != rMode) {
rStarBrightDef[0] = rMode;
// Matrix formulas have star brightnesses in a simple table.
for (i = 1; i <= cStar; i++) {
#ifdef MATRIX
rStarBrightDef[i] = rStarBrightMatrix[i];
#else
rStarBrightDef[i] = 1.0;
#endif
rStarBright[i] = rStarBrightDef[i];
// No distance data, so assume each star is 100 LY away.
rStarBrightDistDef[i] = cp0.dist[oNorm+i] = 100.0 * rLYToAU;
}
#ifdef SWISS
// Swiss Ephemeris reads star brightnesses from an external file.
if (FCmSwissStar())
SwissComputeStars(0.0, fTrue);
#endif
}
}
// Determine the number of days in a particular month. The year is needed too,
// because have to check for leap years in the case of February.
int DayInMonth(int month, int year)
{
int d;
if (month == mSep || month == mApr || month == mJun || month == mNov)
d = 30;
else if (month != mFeb)
d = 31;
else {
d = 28;
if (year % 4 == 0 &&
(year % 100 != 0 || year % 400 == 0 || year <= yeaJ2G))
d++;
}
return d;
}
// Return the actual number of days in a particular month. Normally, this is
// the same as the above routine which determines the index of the last day of
// the month, but the values can differ when changing between calendar systems
// (Julian to Gregorian) in which a month can skip over days.
int DaysInMonth(int month, int year)
{
int d;
d = DayInMonth(month, year);
if (ciGreg.yea == yeaJ2G && ciGreg.mon == monJ2G && ciGreg.day == dayJ2G2 &&
year == yeaJ2G && month == monJ2G)
d -= (dayJ2G2 - dayJ2G1 - 1);
return d;
}
// Return the day of the week (Sunday is 0) of the specified given date.
int DayOfWeek(int month, int day, int year)
{
int d;
d = (MdyToJulian(month, day, year) + 1) % 7;
return d < 0 ? d+7 : d;
}
// Given a day, and the month and year it falls in, add a number of days to
// it and return the new day index. As month changes are not checked for here,
// this is mostly just adding the offset to the day, however need to check for
// calendar changes for when days in a month may be skipped.
int AddDay(int month, int day, int year, int delta)
{
int d;
d = day + delta;
if (ciGreg.yea == yeaJ2G && ciGreg.mon == monJ2G && ciGreg.day == dayJ2G2 &&
year == yeaJ2G && month == monJ2G) { // Check for Julian to
if (d > dayJ2G1 && d < dayJ2G2) // Gregorian crossover.
d += NSgn(delta)*(dayJ2G2-dayJ2G1-1);
}
return d;
}
// Add a certain amount of time to the hour/day/month/year quantity that
// defines a particular chart. This is used by the chart animation feature.
// This can add or subtract anywhere from 1 to 9 seconds, minutes, hours,
// days, months, years, decades, centuries, or millenia in any one call.
// This is mainly just addition to the appropriate quantity, but have to
// check for overflows, e.g. Dec 30 + 3 days = Jan 2 of next year.
void AddTime(CI *pci, int mode, int toadd)
{
int d, h;
real m;
if (!FBetween(mode, 1, 9))
mode = 4;
h = (int)RFloor(pci->tim);
m = RFract(pci->tim)*60.0;
if (m < 60.0 && m + 1.0/rLarge >= 60.0) // Avoid roundoff error.
m = 60.0;
if (mode == 1)
m += 1.0/60.0*(real)toadd; // Add seconds.
else if (mode == 2)
m += (real)toadd; // Add minutes.
// Add hours, either naturally or if minute value overflowed.
if (m >= 60.0 || m < 0.0 || mode == 3) {
if (m >= 60.0) {
m -= 60.0; toadd = NSgn2(toadd);
} else if (m < 0.0) {
m += 60.0; toadd = -NSgn2(-toadd);
}
h += toadd;
}
// Add days, either naturally or if hour value overflowed.
if (h >= 24 || h < 0 || mode == 4) {
if (h >= 24) {
h -= 24; toadd = NSgn2(toadd);
} else if (h < 0) {
h += 24; toadd = -NSgn2(-toadd);
}
pci->day = AddDay(pci->mon, pci->day, pci->yea, toadd);
}
// Add months, either naturally or if day value overflowed.
d = DayInMonth(pci->mon, pci->yea);
if (pci->day > d || pci->day < 1 || mode == 5) {
if (pci->day > d) {
pci->day -= d; toadd = NSgn2(toadd);
} else if (pci->day < 1) {
pci->day += DayInMonth(Mod12(pci->mon - 1), pci->yea);
toadd = -NSgn2(-toadd);
}
pci->mon += toadd;
}
// Add years, either naturally or if month value overflowed.
if (pci->mon > 12 || pci->mon < 1 || mode == 6) {
if (pci->mon > 12) {
pci->mon -= 12; toadd = NSgn2(toadd);
} else if (pci->mon < 1) {
pci->mon += 12; toadd = NSgn2(toadd);
}
pci->yea += toadd;
}
if (mode == 7)
pci->yea += 10 * toadd; // Add decades.
else if (mode == 8)
pci->yea += 100 * toadd; // Add centuries.
else if (mode == 9)
pci->yea += 1000 * toadd; // Add millenia.
pci->tim = (real)h + m/60.0; // Recalibrate hour time.
}
// Given a set of chart information, return the offset of its time in hours
// before UTC. This is normally (time zone - daylight offset), however check
// for special case time zones and Daylight autodetection.
real GetOffsetCI(CONST CI *pci)
{
real zon = pci->zon, dst = pci->dst;
if (zon == zonLMT)
zon = pci->lon / 15.0;
else if (zon == zonLAT)
zon = pci->lon / 15.0 - SwissLatLmt(is.JD);
if (dst == dstAuto)
dst = (real)is.fDst;
return zon - dst;
}
// Given an aspect and two objects making that aspect with each other, return
// the maximum orb allowed for such an aspect. Normally this only depends on
// the aspect itself, but some objects require narrow orbs, and some allow
// wider orbs, so check for these cases.
real GetOrb(int obj1, int obj2, int asp)
{
real orb, r;
orb = rAspOrb[asp];
r = rObjOrb[Min(obj1, oNorm1)];
orb = Min(orb, r);
r = rObjOrb[Min(obj2, oNorm1)];
orb = Min(orb, r);
orb += rObjAdd[Min(obj1, oNorm1)];
orb += rObjAdd[Min(obj2, oNorm1)];
return orb;
}
// Return an aspect's name, checking whether parallel aspects are on.
CONST char *SzAspect(int asp)
{
if (us.fParallel && asp <= aOpp)
asp += cAspect;
return szAspectDisp[asp];
}
// Return the three letter abbreviation for an aspect.
CONST char *SzAspectAbbrev(int asp)
{
if (us.fParallel && asp <= aOpp)
asp += cAspect;
return szAspectAbbrevDisp[asp];
}
// Restriction settings have changed in an arbitrary fashion (such as by
// running an unknown command line). Set the various "is category enabled"
// flags based on whether any of their objects are unrestricted.
void RedoRestrictions()
{
int i;
flag f;
for (f = fFalse, i = cuspLo; i <= cuspHi; i++)
if (!ignore[i] || !ignore2[i]) {
f = fTrue;
break;
}
us.fCusp = f;
for (f = fFalse, i = uranLo; i <= uranHi; i++)
if (!ignore[i] || !ignore2[i]) {
f = fTrue;
break;
}
us.fUranian = f;
for (f = fFalse, i = dwarfLo; i <= dwarfHi; i++)
if (!ignore[i] || !ignore2[i]) {
f = fTrue;
break;
}
us.fDwarf = f;
for (f = fFalse, i = moonsLo; i <= moonsHi; i++)
if (!ignore[i] || !ignore2[i]) {
f = fTrue;
break;
}
us.fMoons = f;
for (f = fFalse, i = cobLo; i <= cobHi; i++)
if (!ignore[i] || !ignore2[i]) {
f = fTrue;
break;
}
us.fCOB = f;
for (f = fFalse, i = starLo; i <= starHi; i++)
if (!ignore[i] || !ignore2[i]) {
f = fTrue;
break;
}
us.fStar = f;
AdjustRestrictions();
}
// Set the central planet (e.g. geocentric or heliocentric).
void SetCentric(int obj)
{
if (!us.fIgnoreAuto && ignore[us.objCenter] && !ignore[obj]) {
// If -YRh switch in effect, might auto(un)restrict central object.
inv(ignore[us.objCenter]);
inv(ignore[obj]);
}
us.objCenter = obj;
}
// Return the planet or other object that an object orbits, if any.
int ObjOrbit(int obj)
{
if (FGeo(obj))
return oEar;
if (FBetween(obj, oMer, cPlanet) || obj == oEar)
return oSun;
if (FCust(obj)) {
#ifdef SWISS
// Check if this object has been redefined to be related to Earth's Moon.
if (rgTypSwiss[obj - custLo] == 2 && FGeo(rgObjSwiss[obj - custLo]))
return oEar;
// Check if this object has been redefined to be a planetary moon.
if (rgTypSwiss[obj - custLo] == 3 && rgObjSwiss[obj - custLo] % 100 < 99)
return rgObjSwiss[obj - custLo] / 100 + 1;
// Check if this is a JPL Horizons object for a planetary moon.
if (rgTypSwiss[obj - custLo] == 4) {
if (rgObjSwiss[obj - custLo] % 100 < 99 &&
FBetween(rgObjSwiss[obj - custLo], 401, 998))
return rgObjSwiss[obj - custLo] / 100 + 1;
// Check if this is a JPL Horizons object for a Dwarf planet moon.
if (rgObjSwiss[obj - custLo] == 120136199) // Dysnomia
return oEri;
if (rgObjSwiss[obj - custLo] == 120136108) // Hi'iaka
return oHau;
if (rgObjSwiss[obj - custLo] == 220136108) // Namaka
return oHau;
if (rgObjSwiss[obj - custLo] == 120050000) // Weywot
return oQua;
if (rgObjSwiss[obj - custLo] == 120090482) // Vanth
return oOrc;
if (rgObjSwiss[obj - custLo] == 120120347) // Actaea
return oOrc; // Hack: Since Salacia not present by default
}
#endif
return oSun;
}
return -1;
}
// Map a planetary moon ephemeris number to an Astrolog object index.
int ObjMoons(int i)
{
int pla, moo, obj;