-
Notifications
You must be signed in to change notification settings - Fork 0
/
swehouse.c
3047 lines (3003 loc) · 105 KB
/
swehouse.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
/*******************************************************
module swehouse.c
house and (simple) aspect calculation
************************************************************/
/* Copyright (C) 1997 - 2008 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 public license version 2 or later
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 GNU GPL 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 GNU GPL or a compatible license.
See http://www.gnu.org/licenses/old-licenses/gpl-2.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.
*/
//#include "sweodef.h"
#include "swephexp.h"
#include "sweph.h"
#include "swephlib.h"
#include "swehouse.h"
#include <string.h>
#define MILLIARCSEC (1.0 / 3600000.0)
#define SOLAR_YEAR 365.24219893
#define ARMCS ((SOLAR_YEAR+1) / SOLAR_YEAR * 360)
static double Asc1(double, double, double, double);
static double AscDash(double, double, double, double);
static double Asc2(double, double, double, double);
static int CalcH(double th, double fi, double ekl, char hsy, struct houses *hsp);
static int sidereal_houses_ecl_t0(double tjde,
double armc,
double eps,
double *nutlo,
double lat,
int hsys,
double *cusp,
double *ascmc,
double *cusp_speed,
double *ascmc_speed,
char *serr);
static int sidereal_houses_trad(double tjde,
int32 iflag,
double armc,
double eps,
double nutl,
double lat,
int hsys,
double *cusp,
double *ascmc,
double *cusp_speed,
double *ascmc_speed,
char *serr);
static int sidereal_houses_ssypl(double tjde,
double armc,
double eps,
double *nutlo,
double lat,
int hsys,
double *cusp,
double *ascmc,
double *cusp_speed,
double *ascmc_speed,
char *serr);
static int sunshine_solution_makransky(double ramc, double lat, double ecl, struct houses *hsp);
static int sunshine_solution_treindl(double ramc, double lat, double ecl, struct houses *hsp);
#if 0
static void test_Asc1();
#endif
/* housasp.c
* cusps are returned in double cusp[13],
* or cusp[37] with house system 'G'.
* cusp[1...12] houses 1 - 12
* additional points are returned in ascmc[10].
* ascmc[0] = ascendant
* ascmc[1] = mc
* ascmc[2] = armc
* ascmc[3] = vertex
* ascmc[4] = equasc * "equatorial ascendant" *
* ascmc[5] = coasc1 * "co-ascendant" (W. Koch) *
* ascmc[6] = coasc2 * "co-ascendant" (M. Munkasey) *
* ascmc[7] = polasc * "polar ascendant" (M. Munkasey) *
*/
int CALL_CONV swe_houses(double tjd_ut,
double geolat,
double geolon,
int hsys,
double *cusp,
double *ascmc)
{
int i, retc = 0;
double armc, eps, nutlo[2];
double tjde = tjd_ut + swe_deltat_ex(tjd_ut, -1, NULL);
eps = swi_epsiln(tjde, 0) * RADTODEG;
swi_nutation(tjde, 0, nutlo);
for (i = 0; i < 2; i++)
nutlo[i] *= RADTODEG;
armc = swe_degnorm(swe_sidtime0(tjd_ut, eps + nutlo[1], nutlo[0]) * 15 + geolon);
if (toupper(hsys) == 'I') { // compute sun declination for sunshine houses
int flags = SEFLG_SPEED| SEFLG_EQUATORIAL;
double xp[6];
int result = swe_calc_ut(tjd_ut, SE_SUN, flags, xp, NULL);
if (result < 0) {
// in case of failure, Porphyry houses
result = swe_houses_armc_ex2(armc, geolat, eps + nutlo[1], 'O', cusp, ascmc, NULL, NULL, NULL);
return ERR;
}
ascmc[9] = xp[1]; // declination in ascmc[9];
}
#ifdef TRACE
swi_open_trace(NULL);
if (swi_trace_count <= TRACE_COUNT_MAX) {
if (swi_fp_trace_c != NULL) {
fputs("\n/*SWE_HOUSES*/\n", swi_fp_trace_c);
fprintf(swi_fp_trace_c, "#if 0\n");
fprintf(swi_fp_trace_c, " tjd = %.9f;", tjd_ut);
fprintf(swi_fp_trace_c, " geolon = %.9f;", geolon);
fprintf(swi_fp_trace_c, " geolat = %.9f;", geolat);
fprintf(swi_fp_trace_c, " hsys = %d;\n", hsys);
fprintf(swi_fp_trace_c, " retc = swe_houses(tjd, geolat, geolon, hsys, cusp, ascmc);\n");
fprintf(swi_fp_trace_c, " /* swe_houses calls swe_houses_armc as follows: */\n");
fprintf(swi_fp_trace_c, "#endif\n");
fflush(swi_fp_trace_c);
}
}
#endif
retc = swe_houses_armc_ex2(armc, geolat, eps + nutlo[1], hsys, cusp, ascmc, NULL, NULL, NULL);
return retc;
}
// For explanation see function swe_houses_ex2() below.
int CALL_CONV swe_houses_ex(double tjd_ut,
int32 iflag,
double geolat,
double geolon,
int hsys,
double *cusp,
double *ascmc)
{
return swe_houses_ex2(tjd_ut, iflag, geolat, geolon, hsys, cusp, ascmc, NULL, NULL, NULL);
}
/*
* Function returns OK or ERR.
* cusps are returned in double cusp[13],
* or cusp[37] with house system 'G'.
* cusp[1...12] houses 1 - 12
* ascmc[0...10] additional points:
* ascmc[0] = ascendant
* ascmc[1] = mc
* ascmc[2] = armc
* ascmc[3] = vertex
* ascmc[4] = equasc * "equatorial ascendant" *
* ascmc[5] = coasc1 * "co-ascendant" (W. Koch) *
* ascmc[6] = coasc2 * "co-ascendant" (M. Munkasey) *
* ascmc[7] = polasc * "polar ascendant" (M. Munkasey) *
* cusp_speed[1...12] speeds (daily motions) of the cusps.
* ascmc_speed[0...10] speeds (daily motions) of the additional points.
* serr error message or warning
*/
int CALL_CONV swe_houses_ex2(double tjd_ut,
int32 iflag,
double geolat,
double geolon,
int hsys,
double *cusp,
double *ascmc,
double *cusp_speed,
double *ascmc_speed,
char *serr)
{
int i, retc = 0;
double armc, eps_mean, nutlo[2];
double tjde = tjd_ut + swe_deltat_ex(tjd_ut, iflag, NULL);
struct sid_data *sip = &swed.sidd;
double xp[6];
int retc_makr = 0;
int ito;
if (toupper(hsys) == 'G')
ito = 36;
else
ito = 12;
if ((iflag & SEFLG_SIDEREAL) && !swed.ayana_is_set)
swe_set_sid_mode(SE_SIDM_FAGAN_BRADLEY, 0, 0);
eps_mean = swi_epsiln(tjde, 0) * RADTODEG;
swi_nutation(tjde, 0, nutlo);
for (i = 0; i < 2; i++)
nutlo[i] *= RADTODEG;
if (iflag & SEFLG_NONUT) {
for (i = 0; i < 2; i++)
nutlo[i] = 0;
}
#ifdef TRACE
swi_open_trace(NULL);
if (swi_trace_count <= TRACE_COUNT_MAX) {
if (swi_fp_trace_c != NULL) {
fputs("\n/*SWE_HOUSES_EX*/\n", swi_fp_trace_c);
fprintf(swi_fp_trace_c, "#if 0\n");
fprintf(swi_fp_trace_c, " tjd = %.9f;", tjd_ut);
fprintf(swi_fp_trace_c, " iflag = %d;\n", iflag);
fprintf(swi_fp_trace_c, " geolon = %.9f;", geolon);
fprintf(swi_fp_trace_c, " geolat = %.9f;", geolat);
fprintf(swi_fp_trace_c, " hsys = %d;\n", hsys);
fprintf(swi_fp_trace_c, " retc = swe_houses_ex(tjd, iflag, geolat, geolon, hsys, cusp, ascmc);\n");
fprintf(swi_fp_trace_c, " /* swe_houses calls swe_houses_armc as follows: */\n");
fprintf(swi_fp_trace_c, "#endif\n");
fflush(swi_fp_trace_c);
}
}
#endif
/*houses_to_sidereal(tjde, geolat, hsys, eps, cusp, ascmc, iflag);*/
armc = swe_degnorm(swe_sidtime0(tjd_ut, eps_mean + nutlo[1], nutlo[0]) * 15 + geolon);
//fprintf(stderr, "armc=%f, iflag=%d\n", armc, iflag);
if (toupper(hsys) == 'I') { // compute sun declination for sunshine houses
int flags = SEFLG_SPEED| SEFLG_EQUATORIAL;
retc_makr = swe_calc_ut(tjd_ut, SE_SUN, flags, xp, NULL);
if (retc_makr < 0) {
// in case of failure, provide Porphyry houses
hsys = (int) 'O';
}
ascmc[9] = xp[1]; // declination in ascmc[9];
}
if (iflag & SEFLG_SIDEREAL) {
if (sip->sid_mode & SE_SIDBIT_ECL_T0)
retc = sidereal_houses_ecl_t0(tjde, armc, eps_mean + nutlo[1], nutlo, geolat, hsys, cusp, ascmc, cusp_speed, ascmc_speed, serr);
else if (sip->sid_mode & SE_SIDBIT_SSY_PLANE)
retc = sidereal_houses_ssypl(tjde, armc, eps_mean + nutlo[1], nutlo, geolat, hsys, cusp, ascmc, cusp_speed, ascmc_speed, serr);
else
retc = sidereal_houses_trad(tjde, iflag, armc, eps_mean + nutlo[1], nutlo[0], geolat, hsys, cusp, ascmc, cusp_speed, ascmc_speed, serr);
} else {
retc = swe_houses_armc_ex2(armc, geolat, eps_mean + nutlo[1], hsys, cusp, ascmc, cusp_speed, ascmc_speed, serr);
if (toupper(hsys) == 'I')
ascmc[9] = xp[1]; // declination in ascmc[9];
}
if (iflag & SEFLG_RADIANS) {
for (i = 1; i <= ito; i++)
cusp[i] *= DEGTORAD;
for (i = 0; i < SE_NASCMC; i++)
ascmc[i] *= DEGTORAD;
}
if (retc_makr < 0)
return retc_makr;
return retc;
}
/*
* houses to sidereal
* ------------------
* there are two methods:
* a) the traditional one
* houses are computed tropically, then nutation and the ayanamsa
* are subtracted.
* b) the projection on the ecliptic of t0
* The house computation is then as follows:
*
* Be t the birth date and t0 the epoch at which ayanamsa = 0.
* 1. Compute the angle between the mean ecliptic at t0 and
* the true equator at t.
* The intersection point of these two circles we call the
* "auxiliary vernal point", and the angle between them the
* "auxiliary obliquity".
* 2. Compute the distance of the auxiliary vernal point from the
* vernal point at t. (this is a section on the equator)
* 3. subtract this value from the armc of t = aux. armc.
* 4. Compute the axes and houses for this aux. armc and aux. obliquity.
* 5. Compute the distance between the auxiliary vernal point and the
* vernal point at t0 (this is the ayanamsa at t, measured on the
* ecliptic of t0)
* 6. subtract this distance from all house cusps.
* 7. subtract ayanamsa_t0 from all house cusps.
*/
static int sidereal_houses_ecl_t0(double tjde,
double armc,
double eps,
double *nutlo,
double lat,
int hsys,
double *cusp,
double *ascmc,
double *cusp_speed,
double *ascmc_speed,
char *serr)
{
int i, j, retc = OK;
double x[6], xvpx[6], x2[6], epst0, xnorm[6];
double rxy, rxyz, c2, epsx, sgn, fac, dvpx, dvpxe;
double armcx;
struct sid_data *sip = &swed.sidd;
int ito;
if (toupper(hsys) == 'G')
ito = 36;
else
ito = 12;
/* epsilon at t0 */
epst0 = swi_epsiln(sip->t0, 0);
/* cartesian coordinates of an imaginary moving body on the
* the mean ecliptic of t0; we take the vernal point: */
x[0] = x[4] = 1;
x[1] = x[2] = x[3] = x[5] = 0;
/* to equator */
swi_coortrf(x, x, -epst0);
swi_coortrf(x+3, x+3, -epst0);
/* to tjd_et */
swi_precess(x, sip->t0, 0, J_TO_J2000);
swi_precess(x, tjde, 0, J2000_TO_J);
swi_precess(x+3, sip->t0, 0, J_TO_J2000);
swi_precess(x+3, tjde, 0, J2000_TO_J);
/* to true equator of tjd_et */
swi_coortrf(x, x, (eps - nutlo[1]) * DEGTORAD);
swi_coortrf(x+3, x+3, (eps - nutlo[1]) * DEGTORAD);
swi_cartpol_sp(x, x);
x[0] += nutlo[0] * DEGTORAD;
swi_polcart_sp(x, x);
swi_coortrf(x, x, -eps * DEGTORAD);
swi_coortrf(x+3, x+3, -eps * DEGTORAD);
/* now, we have the moving point precessed to tjd_et.
* next, we compute the auxiliary epsilon: */
swi_cross_prod(x, x+3, xnorm);
rxy = xnorm[0] * xnorm[0] + xnorm[1] * xnorm[1];
c2 = (rxy + xnorm[2] * xnorm[2]);
rxyz = sqrt(c2);
rxy = sqrt(rxy);
epsx = asin(rxy / rxyz) * RADTODEG; /* 1a */
/* auxiliary vernal point */
if (fabs(x[5]) < 1e-15)
x[5] = 1e-15;
fac = x[2] / x[5];
sgn = x[5] / fabs(x[5]);
for (j = 0; j <= 2; j++)
xvpx[j] = (x[j] - fac * x[j+3]) * sgn; /* 1b */
/* distance of the auxiliary vernal point from
* the zero point at tjd_et (a section on the equator): */
swi_cartpol(xvpx, x2);
dvpx = x2[0] * RADTODEG; /* 2 */
/* auxiliary armc */
armcx = swe_degnorm(armc - dvpx); /* 3 */
/* compute axes and houses: */
retc = swe_houses_armc_ex2(armcx, lat, epsx, hsys, cusp, ascmc, cusp_speed, ascmc_speed, serr); /* 4 */
/* distance between auxiliary vernal point and
* vernal point of t0 (a section on the sidereal plane) */
dvpxe = acos(swi_dot_prod_unit(x, xvpx)) * RADTODEG; /* 5 */
if (tjde < sip->t0)
dvpxe = -dvpxe;
for (i = 1; i <= ito; i++) /* 6, 7 */
cusp[i] = swe_degnorm(cusp[i] - dvpxe - sip->ayan_t0);
for (i = 0; i <= SE_NASCMC; i++) {
if (i == 2) /* armc */
continue;
ascmc[i] = swe_degnorm(ascmc[i] - dvpxe - sip->ayan_t0);
}
if (hsys == 'N') { /* 1 = 0° Aries */
for (i = 1; i <= ito; i++) {
cusp[i] = (i - 1) * 30;
}
}
return retc;
}
/*
* Be t the birth date and t0 the epoch at which ayanamsa = 0.
* 1. Compute the angle between the solar system rotation plane and
* the true equator at t.
* The intersection point of these two circles we call the
* "auxiliary vernal point", and the angle between them the
* "auxiliary obliquity".
* 2. Compute the distance of the auxiliary vernal point from the
* zero point at t. (this is a section on the equator)
* 3. subtract this value from the armc of t = aux. armc.
* 4. Compute the axes and houses for this aux. armc and aux. obliquity.
* 5. Compute the distance between the auxiliary vernal point at t
* and the zero point of the solar system plane J2000
* (a section measured on the solar system plane)
* 6. subtract this distance from all house cusps.
* 7. compute the ayanamsa of J2000 on the solar system plane,
* referred to t0
* 8. subtract ayanamsa_t0 from all house cusps.
* 9. subtract ayanamsa_2000 from all house cusps.
*/
static int sidereal_houses_ssypl(double tjde,
double armc,
double eps,
double *nutlo,
double lat,
int hsys,
double *cusp,
double *ascmc,
double *cusp_speed,
double *ascmc_speed,
char *serr)
{
int i, j, retc = OK;
double x[6], x0[6], xvpx[6], x2[6], xnorm[6];
double rxy, rxyz, c2, epsx, eps2000, sgn, fac, dvpx, dvpxe, x00;
double armcx;
struct sid_data *sip = &swed.sidd;
int ito;
if (toupper(hsys) == 'G')
ito = 36;
else
ito = 12;
eps2000 = swi_epsiln(J2000, 0);
/* cartesian coordinates of the zero point on the
* the solar system rotation plane */
x[0] = x[4] = 1;
x[1] = x[2] = x[3] = x[5] = 0;
/* to ecliptic 2000 */
swi_coortrf(x, x, -SSY_PLANE_INCL);
swi_coortrf(x+3, x+3, -SSY_PLANE_INCL);
swi_cartpol_sp(x, x);
x[0] += SSY_PLANE_NODE_E2000;
swi_polcart_sp(x, x);
/* to equator 2000 */
swi_coortrf(x, x, -eps2000);
swi_coortrf(x+3, x+3, -eps2000);
/* to mean equator of t */
swi_precess(x, tjde, 0, J2000_TO_J);
swi_precess(x+3, tjde, 0, J2000_TO_J);
/* to true equator of t */
swi_coortrf(x, x, (eps - nutlo[1]) * DEGTORAD);
swi_coortrf(x+3, x+3, (eps - nutlo[1]) * DEGTORAD);
swi_cartpol_sp(x, x);
x[0] += nutlo[0] * DEGTORAD;
swi_polcart_sp(x, x);
swi_coortrf(x, x, -eps * DEGTORAD);
swi_coortrf(x+3, x+3, -eps * DEGTORAD);
/* now, we have the moving point precessed to tjd_et.
* next, we compute the auxiliary epsilon: */
swi_cross_prod(x, x+3, xnorm);
rxy = xnorm[0] * xnorm[0] + xnorm[1] * xnorm[1];
c2 = (rxy + xnorm[2] * xnorm[2]);
rxyz = sqrt(c2);
rxy = sqrt(rxy);
epsx = asin(rxy / rxyz) * RADTODEG; /* 1a */
/* auxiliary vernal point */
if (fabs(x[5]) < 1e-15)
x[5] = 1e-15;
fac = x[2] / x[5];
sgn = x[5] / fabs(x[5]);
for (j = 0; j <= 2; j++)
xvpx[j] = (x[j] - fac * x[j+3]) * sgn; /* 1b */
/* distance of the auxiliary vernal point from
* mean vernal point at tjd_et (a section on the equator): */
swi_cartpol(xvpx, x2);
dvpx = x2[0] * RADTODEG; /* 2 */
/* auxiliary armc */
armcx = swe_degnorm(armc - dvpx); /* 3 */
/* compute axes and houses: */
retc = swe_houses_armc_ex2(armcx, lat, epsx, hsys, cusp, ascmc, cusp_speed, ascmc_speed, serr); /* 4 */
/* distance between the auxiliary vernal point at t and
* the sidereal zero point of 2000 at t
* (a section on the sidereal plane).
*/
dvpxe = acos(swi_dot_prod_unit(x, xvpx)) * RADTODEG; /* 5 */
/* (always positive for dates after 5400 bc) */
dvpxe -= SSY_PLANE_NODE * RADTODEG;
/* ayanamsa between t0 and J2000, measured on solar system plane: */
/* position of zero point of t0 */
x0[0] = 1;
x0[1] = x0[2] = 0;
/* zero point of t0 in J2000 system */
if (sip->t0 != J2000)
swi_precess(x0, sip->t0, 0, J_TO_J2000);
/* zero point to ecliptic 2000 */
swi_coortrf(x0, x0, eps2000);
/* to solar system plane */
swi_cartpol(x0, x0);
x0[0] -= SSY_PLANE_NODE_E2000;
swi_polcart(x0, x0);
swi_coortrf(x0, x0, SSY_PLANE_INCL);
swi_cartpol(x0, x0);
x0[0] += SSY_PLANE_NODE;
x00 = x0[0] * RADTODEG; /* 7 */
for (i = 1; i <= ito; i++) /* 6, 8, 9 */
cusp[i] = swe_degnorm(cusp[i] - dvpxe - sip->ayan_t0 - x00);
for (i = 0; i <= SE_NASCMC; i++) {
if (i == 2) /* armc */
continue;
ascmc[i] = swe_degnorm(ascmc[i] - dvpxe - sip->ayan_t0 - x00);
}
if (hsys == 'N') { /* 1 = 0° Aries */
for (i = 1; i <= ito; i++) {
cusp[i] = (i - 1) * 30;
}
}
return retc;
}
/* common simplified procedure */
static int sidereal_houses_trad(double tjde,
int32 iflag,
double armc,
double eps,
double nutl,
double lat,
int hsys,
double *cusp,
double *ascmc,
double *cusp_speed,
double *ascmc_speed,
char *serr)
{
int i, retc = OK;
double ay;
int ito;
int ihs = toupper(hsys);
int ihs2 = ihs;
// ay = swe_get_ayanamsa(tjde);
//fprintf(stderr, "ay=%f\n", ay);
retc = swe_get_ayanamsa_ex(tjde, iflag, &ay, NULL);
//fprintf(stderr, "ay=%f\n", ay);
//fprintf(stderr, "nutl=%f\n", nutl);
if (ihs == 'G')
ito = 36;
else
ito = 12;
if (ihs == 'W') /* whole sign houses: treat as 'E' and fix later */
ihs2 = 'E';
//fprintf(stderr, "armc=%f\n", armc);
//if (hsys == 'P') fprintf(stderr, "ay=%f, t=%f %c", ay, tjde, (char) hsys);
retc = swe_houses_armc_ex2(armc, lat, eps, ihs2, cusp, ascmc, cusp_speed, ascmc_speed, serr);
//if (hsys == 'P') fprintf(stderr, " h1=%f", cusp[1]);
for (i = 1; i <= ito; i++) {
//cusp[i] = swe_degnorm(cusp[i] - ay - nutl);
cusp[i] = swe_degnorm(cusp[i] - ay);
if (ihs == 'W') /* whole sign houses */
cusp[i] -= fmod(cusp[i], 30);
}
if (ihs == 'N') { /* 1 = 0° Aries */
for (i = 1; i <= ito; i++) {
cusp[i] = (i - 1) * 30;
}
}
for (i = 0; i < SE_NASCMC; i++) {
if (i == 2) /* armc */
continue;
//ascmc[i] = swe_degnorm(ascmc[i] - ay - nutl);
ascmc[i] = swe_degnorm(ascmc[i] - ay);
}
//if (hsys == 'P') fprintf(stderr, " => %f\n", cusp[1]);
return retc;
}
// For explanation see function swe_houses_armc_ex2() below.
int CALL_CONV swe_houses_armc(
double armc,
double geolat,
double eps,
int hsys,
double *cusp,
double *ascmc)
{
return swe_houses_armc_ex2(armc, geolat, eps, hsys, cusp, ascmc, NULL, NULL, NULL);
}
/*
* Function returns OK or ERR.
* this function is required for very special computations
* where no date is given for house calculation,
* e.g. for composite charts or progressive charts.
* cusps are returned in double cusp[13],
* or cusp[37] with house system 'G'.
* cusp[1...12] houses 1 - 12
* ascmc[0...10] additional points:
* ascmc[0] = ascendant
* ascmc[1] = mc
* ascmc[2] = armc
* ascmc[3] = vertex
* ascmc[4] = equasc * "equatorial ascendant" *
* ascmc[5] = coasc1 * "co-ascendant" (W. Koch) *
* ascmc[6] = coasc2 * "co-ascendant" (M. Munkasey) *
* ascmc[7] = polasc * "polar ascendant" (M. Munkasey) *
* cusp_speed[1...12] speeds (daily motions) of the cusps.
* ascmc_speed[0...10] speeds (daily motions) of the additional points.
* serr error message or warning
*/
int CALL_CONV swe_houses_armc_ex2(
double armc,
double geolat,
double eps,
int hsys,
double *cusp,
double *ascmc,
double *cusp_speed,
double *ascmc_speed,
char *serr)
{
struct houses h, hm1, hp1;
int i, retc = 0, rm1, rp1;
int ito;
static double saved_sundec = 99;
if (toupper(hsys) == 'G')
ito = 36;
else
ito = 12;
armc = swe_degnorm(armc);
h.do_speed = FALSE;
h.do_hspeed = FALSE;
if (ascmc_speed != NULL || cusp_speed != NULL)
h.do_speed = TRUE; // is needed if cusp_speed wanted
if (cusp_speed != NULL)
h.do_hspeed = TRUE;
if (toupper(hsys) == 'I') { // declination for sunshine houses
if (ascmc[9] == 99) {
h.sundec = 0;
if (saved_sundec != 99) h.sundec = saved_sundec;
} else {
h.sundec = ascmc[9];
saved_sundec = h.sundec;
}
}
retc = CalcH(armc, geolat, eps, (char)hsys, &h);
cusp[0] = 0;
// on failure, we only have 12 Porphyry cusps
if (retc < 0) {
ito = 12;
if (serr != NULL) strcpy(serr, h.serr);
}
for (i = 1; i <= ito; i++) {
cusp[i] = h.cusp[i];
if (h.do_hspeed) cusp_speed[i] = h.cusp_speed[i];
}
ascmc[0] = h.ac; /* Asc */
ascmc[1] = h.mc; /* Mid */
ascmc[2] = armc;
ascmc[3] = h.vertex;
ascmc[4] = h.equasc;
ascmc[5] = h.coasc1; /* "co-ascendant" (W. Koch) */
ascmc[6] = h.coasc2; /* "co-ascendant" (M. Munkasey) */
ascmc[7] = h.polasc; /* "polar ascendant" (M. Munkasey) */
for (i = SE_NASCMC; i < 10; i++)
ascmc[i] = 0;
if (toupper(hsys) == 'I') // declination for sunshine houses
ascmc[9] = h.sundec ;
if (h.do_speed && ascmc_speed != NULL) {
ascmc_speed[0] = h.ac_speed; /* Asc */
ascmc_speed[1] = h.mc_speed; /* Mid */
ascmc_speed[2] = h.armc_speed;
ascmc_speed[3] = h.vertex_speed;
ascmc_speed[4] = h.equasc_speed;
ascmc_speed[5] = h.coasc1_speed; /* "co-ascendant" (W. Koch) */
ascmc_speed[6] = h.coasc2_speed; /* "co-ascendant" (M. Munkasey) */
ascmc_speed[7] = h.polasc_speed; /* "polar ascendant" (M. Munkasey) */
for (i = SE_NASCMC; i < 10; i++)
ascmc_speed[i] = 0;
}
if (h.do_interpol) { // must compute cusp_speed via interpolation
double dt = 1.0 / 86400;
double darmc = dt * ARMCS;
hm1.do_speed = FALSE;
hm1.do_hspeed = FALSE;
hp1.do_speed = FALSE;
hp1.do_hspeed = FALSE;
if (toupper(hsys) == 'I') {
hm1.sundec = h.sundec;
hp1.sundec = h.sundec;
}
rm1 = CalcH(armc - darmc, geolat, eps, (char)hsys, &hm1);
rp1 = CalcH(armc + darmc, geolat, eps, (char)hsys, &hp1);
if (rp1 >= 0 && rm1 >=0) {
if (fabs(swe_difdeg2n(hp1.ac, h.ac)) > 90) {
hp1 = h; // use only upper interval
dt = dt / 2;
} else if (fabs(swe_difdeg2n(hm1.ac, h.ac)) > 90) {
hm1 = h; // use only lower interval
dt = dt / 2;
}
for (i = 1; i <= 12; i++) {
double dx = swe_difdeg2n(hp1.cusp[i], hm1.cusp[i]);
cusp_speed[i] = dx / 2 / dt ;
}
}
}
#ifdef TRACE
swi_open_trace(NULL);
if (swi_trace_count <= TRACE_COUNT_MAX) {
if (swi_fp_trace_c != NULL) {
fputs("\n/*SWE_HOUSES_ARMC_EX2*/\n", swi_fp_trace_c);
fprintf(swi_fp_trace_c, " armc = %.9f;", armc);
fprintf(swi_fp_trace_c, " geolat = %.9f;", geolat);
fprintf(swi_fp_trace_c, " eps = %.9f;", eps);
fprintf(swi_fp_trace_c, " hsys = %d;\n", hsys);
fprintf(swi_fp_trace_c, " retc = swe_houses_armc_ex2(armc, geolat, eps, hsys, cusp, ascmc, cusp_speed, ascmc_speed, serr);\n");
fputs(" printf(\"swe_houses_armc_ex2: %f\\t%f\\t%f\\t%c\\t\\n\", ", swi_fp_trace_c);
fputs(" armc, geolat, eps, hsys);\n", swi_fp_trace_c);
fputs(" printf(\"retc = %d\\n\", retc);\n", swi_fp_trace_c);
fputs(" printf(\"cusp:\\n\");\n", swi_fp_trace_c);
fputs(" for (i = 1; i <= 12; i++)\n", swi_fp_trace_c);
fputs(" printf(\" %d\\t%f\\n\", i, cusp[i]);\n", swi_fp_trace_c);
fputs(" printf(\"ascmc:\\n\");\n", swi_fp_trace_c);
fputs(" for (i = 0; i < 10; i++)\n", swi_fp_trace_c);
fputs(" printf(\" %d\\t%f\\n\", i, ascmc[i]);\n", swi_fp_trace_c);
fputs(" printf(\"cusp_speed:\\n\");\n", swi_fp_trace_c);
fputs(" for (i = 1; i <= 12; i++)\n", swi_fp_trace_c);
fputs(" printf(\" %d\\t%f\\n\", i, cusp_speed[i]);\n", swi_fp_trace_c);
fputs(" printf(\"ascmc_speed:\\n\");\n", swi_fp_trace_c);
fputs(" for (i = 0; i < 10; i++)\n", swi_fp_trace_c);
fputs(" printf(\" %d\\t%f\\n\", i, ascmc_speed[i]);\n", swi_fp_trace_c);
fflush(swi_fp_trace_c);
}
if (swi_fp_trace_out != NULL) {
fprintf(swi_fp_trace_out, "swe_houses_armc_ex2: %f\t%f\t%f\t%c\t\n", armc, geolat, eps, hsys);
fprintf(swi_fp_trace_out, "retc = %d\n", retc);
fputs("cusp:\n", swi_fp_trace_out);
for (i = 1; i <= 12; i++)
fprintf(swi_fp_trace_out, " %d\t%f\n", i, cusp[i]);
fputs("ascmc:\n", swi_fp_trace_out);
for (i = 0; i < 10; i++)
fprintf(swi_fp_trace_out, " %d\t%f\n", i, ascmc[i]);
fflush(swi_fp_trace_out);
}
}
#endif
#if 0
/* for test of swe_house_pos().
* 1st house will be 0, second 30, etc. */
for (i = 1; i <=12; i++) {
double x[6];
x[0] = cusp[i]; x[1] = 0; x[2] = 1;
cusp[i] = (swe_house_pos(armc, geolat, eps, hsys, x, NULL) - 1) * 30;
}
#endif
return retc;
}
/* for APC houses */
/* n number of house
* ph geographic latitude
* e ecliptic obliquity
* az armc
*/
static double apc_sector(int n, double ph, double e, double az)
{
int k, is_below_hor = 0;
double kv, a, dasc, dret;
/* kv: ascensional difference of the ascendant */
/* dasc: declination of the ascendant */
if (fabs(ph * RADTODEG) > 90 - VERY_SMALL) {
kv = 0;
dasc = 0;
} else {
kv = atan(tan(ph) * tan(e) * cos(az)/(1 + tan(ph) * tan(e) * sin(az)));
if (fabs(ph * RADTODEG) < VERY_SMALL) {
dasc = (90 - VERY_SMALL) * DEGTORAD;
if (ph < 0)
dasc = -dasc;
} else {
dasc = atan(sin(kv) / tan(ph));
}
}
/* note, at polar circles, when the mc sinks below the horizon,
* kv and dasc change sign in the above formulae.
* this is what we need, because the ascendand jumps by 180 deg */
/* printf("%f, %f\n", kv*RADTODEG, dasc*RADTODEG); */
if (n < 8) {
is_below_hor = 1; /* 1 and 7 are included here */
k = n - 1;
} else {
k = n - 13;
}
/* az + PI/2 + kv = armc + 90 + asc. diff. = right ascension of ascendant
* PI/2 +- kv = semi-diurnal or seminocturnal arc of ascendant
* a = right ascension of house cusp on apc circle (ascendant-parallel
* circle), with declination dasc */
if (is_below_hor) {
a = kv + az + PI/2 + k * (PI/2 - kv) / 3;
} else {
a = kv + az + PI/2 + k * (PI/2 + kv) / 3;
}
a = swe_radnorm(a);
dret = atan2(tan(dasc) * tan(ph) * sin(az) + sin(a),
cos(e) * (tan(dasc) * tan(ph) * cos(az) + cos(a)) + sin(e) * tan(ph) * sin(az - a));
dret = swe_degnorm(dret * RADTODEG);
return dret;
}
char *CALL_CONV swe_house_name(int hsys)
{
int h = hsys;
if (h != 'i') h = toupper(h);
switch (h) {
case 'A': return "equal";
case 'B': return "Alcabitius";
case 'C': return "Campanus";
case 'D': return "equal (MC)";
case 'E': return "equal";
case 'F': return "Carter poli-equ.";
case 'G': return "Gauquelin sectors";
case 'H': return "horizon/azimut";
case 'I': return "Sunshine";
case 'i': return "Sunshine/alt.";
case 'K': return "Koch";
case 'L': return "Pullen SD";
case 'M': return "Morinus";
case 'N': return "equal/1=Aries";
case 'O': return "Porphyry";
case 'Q': return "Pullen SR";
case 'R': return "Regiomontanus";
case 'S': return "Sripati";
case 'T': return "Polich/Page";
case 'U': return "Krusinski-Pisa-Goelzer";
case 'V': return "equal/Vehlow";
case 'W': return "equal/ whole sign";
case 'X': return "axial rotation system/Meridian houses";
case 'Y': return "APC houses";
default: return "Placidus";
}
}
// How to deal with Sunshine houses if the southern crossing point of Equator
// and Ecliptic is under the horizon:
// We follow the proposal by Dieter Koch, who wants to keep it in alalogy with
// Regiomontanus, where we keep the MC above the horozon, by switching it to the noth.
// This results in an clockwise sequence of house cusps in the chart.
//
// One can argue that the MC should be kept south, even when it is under the horizon.
// This would keep the sequence of houses in the chart counterclockwise as usual.
// To achieve it, the offsets on the diurnal arcs must be inverted.
#define SUNSHINE_KEEP_MC_SOUTH 0 // must be 0 or 1
double swi_armc_to_mc(double armc, double eps)
{
double tant, mc;
if (fabs(armc - 90) > VERY_SMALL
&& fabs(armc - 270) > VERY_SMALL) {
tant = tand(armc);
mc = atand(tant / cosd(eps));
if (armc > 90 && armc <= 270)
mc = swe_degnorm(mc + 180);
} else {
if (fabs(armc - 90) <= VERY_SMALL)
mc = 90;
else
mc = 270;
} /* if */
return mc;
}
//#define DEBUG_PLAC_ITER 1
#define VERY_SMALL_PLAC_ITER (1.0 / 360000.0 )
static int CalcH(
double th, double fi, double ekl, char hsy, struct houses *hsp)
/* *********************************************************
* Arguments: th = sidereal time (angle 0..360 degrees
* hsy = letter code for house system;
* A equal
* E equal
* B Alcabitius
* C Campanus
* D equal (MC)
* F Carter "Poli-Equatorial"
* G 36 Gauquelin sectors
* H horizon / azimut
* I Sunshine solution Treindl
* i Sunshine solution Makransky
* K Koch
* L Pullen SD "sinusoidal delta", ex Neo-Porphyry
* M Morinus
* N equal/1=Aries
* O Porphyry
* P Placidus
* Q Pullen SR "sinusoidal ratio"
* R Regiomontanus
* S Sripati
* T Polich/Page ("topocentric")
* U Krusinski-Pisa-Goelzer
* V equal Vehlow
* W equal, whole sign
* X axial rotation system/ Meridian houses
* Y APC houses
* fi = geographic latitude
* ekl = obliquity of the ecliptic
* *********************************************************
* Koch and Placidus don't work in the polar circle.
* We swap MC/IC so that MC is always before AC in the zodiac
* We than divide the quadrants into 3 equal parts.
* *********************************************************
* All angles are expressed in degrees.
* Special trigonometric functions sind, cosd etc. are
* implemented for arguments in degrees.
***********************************************************/
{
double tane, tanfi, cosfi, tant, sina, cosa, th2;
double a, c, f, fh1, fh2, xh1, xh2, rectasc, ad3, acmc, vemc;
int i, ih, ih2, retc = OK;
double sine, cose;
double x[3], krHorizonLon; /* BK 14.02.2006 */
int niter_max = 100; // maximum iterations allowed with Placidus
double cuspsv;
*hsp->serr = '\0';
hsp->do_interpol = 0;
cose = cosd(ekl);
sine = sind(ekl);
tane = tand(ekl);
/* north and south poles */
if (fabs(fabs(fi) - 90) < VERY_SMALL) {
if (fi < 0)
fi = -90 + VERY_SMALL;
else
fi = 90 - VERY_SMALL;
}
tanfi = tand(fi);
/* mc */
if (fabs(th - 90) > VERY_SMALL
&& fabs(th - 270) > VERY_SMALL) {
tant = tand(th);
hsp->mc = atand(tant / cose);
if (th > 90 && th <= 270)
hsp->mc = swe_degnorm(hsp->mc + 180);
} else {
if (fabs(th - 90) <= VERY_SMALL)
hsp->mc = 90;
else
hsp->mc = 270;
} /* if */
hsp->mc = swe_degnorm(hsp->mc);
if (hsp->do_speed) hsp->mc_speed = AscDash(th, 0, sine, cose);
/* ascendant */
hsp->ac = Asc1(th + 90, fi, sine, cose);
if (hsp->do_speed)
hsp->ac_speed = AscDash(th + 90, fi, sine, cose);
if (hsp->do_hspeed) {
for (i = 0; i <= 12; i++)
hsp->cusp_speed[i] = 0;
}
hsp->armc_speed = ARMCS;
// these cusp[1] and cusp[10] values may be changed further down for some house systems
hsp->cusp[1] = hsp->ac;
hsp->cusp[10] = hsp->mc;
if (hsp->do_hspeed) {
hsp->cusp_speed[1] = hsp->ac_speed;
hsp->cusp_speed[10] = hsp->mc_speed;
}
/* we respect smaller case letter for i, otherwise they are deprecated */
if (hsy > 95 && hsy != 'i') {
sprintf(hsp->serr, "use of lower case letters like %c for house systems is deprecated", hsy);
hsy = (char) (hsy - 32);/* translate into capital letter */
}
switch (hsy) {
case 'A': /* equal houses */
case 'E':
acmc = swe_difdeg2n(hsp->ac, hsp->mc);
if (acmc < 0) {
/* within polar circle we swap AC/DC if AC is on wrong side */
hsp->ac = swe_degnorm(hsp->ac + 180);
hsp->cusp[1] = hsp->ac;
}
for (i = 2; i <=12; i++) {
hsp->cusp[i] = swe_degnorm(hsp->cusp[1] + (i-1) * 30);
}
if (hsp->do_hspeed) {
for (i = 1; i <=12; i++) {
hsp->cusp_speed[i] = hsp->ac_speed;
}
}