-
Notifications
You must be signed in to change notification settings - Fork 7
/
Basics.cs
5361 lines (5013 loc) · 172 KB
/
Basics.cs
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
/******
Copyright (C) 2005 Ajit Krishnan (http://www.mudgala.com)
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,
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******/
using System;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.IO;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;
using System.Drawing.Design;
using System.Windows.Forms.Design;
namespace mhora
{
public class PGDisplayName : Attribute
{
public string DisplayName;
public PGDisplayName(string _display)
{
this.DisplayName=_display;
}
}
public class PGNotVisible: Attribute
{
}
[AttributeUsage(AttributeTargets.Property)]
public class PropertyOrderAttribute : Attribute
{
//
// Simple attribute to allow the order of a property to be specified
//
private int _order;
public PropertyOrderAttribute(int order)
{
_order = order;
}
public int Order
{
get
{
return _order;
}
}
}
public delegate void EvtChanged (Object h);
public delegate void SetOptionsDelegate (Object sender);
public delegate void Recalculate ();
/// <summary>
/// An interface which should be used by those whose properties
/// should be updateable using the mhoraOptions form.
/// </summary>
public interface IUpdateable
{
Object GetOptions();
Object SetOptions (Object a);
}
/// <summary>
/// Interface will return a HoraInfo object specifying all birth
/// time information required for a single chart.
/// </summary>
public interface IFileToHoraInfo
{
HoraInfo toHoraInfo ();
void ToFile (HoraInfo hi);
}
/// <summary>
/// Class deals with reading the Jhd file specification
/// used by Jagannatha Hora
/// </summary>
///
public class Mhd : IFileToHoraInfo
{
private string fname;
public Mhd (string fileName)
{
fname = fileName;
}
public HoraInfo toHoraInfo ()
{
try
{
HoraInfo hi = new HoraInfo();
FileStream sOut;
sOut = new FileStream(fname, FileMode.Open, FileAccess.Read);
BinaryFormatter formatter = new BinaryFormatter();
formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;
hi = (HoraInfo)formatter.Deserialize(sOut);
sOut.Close();
return hi;
}
catch
{
MessageBox.Show("Unable to read file");
return new HoraInfo();
}
}
public void ToFile (HoraInfo hi)
{
FileStream sOut = new FileStream(fname, FileMode.OpenOrCreate, FileAccess.Write);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize (sOut, hi);
sOut.Close();
}
}
public class Jhd : IFileToHoraInfo
{
private string fname;
public Jhd (string fileName)
{
fname = fileName;
}
private static int readIntLine (StreamReader sr)
{
String s = sr.ReadLine();
return int.Parse(s);
}
private static void writeHMSInfoLine (StreamWriter sw, HMSInfo hi)
{
string q;
if (hi.direction == HMSInfo.dir_type.NS && hi.degree >= 0)
q = "";
else if (hi.direction == HMSInfo.dir_type.NS)
q = "-";
else if (hi.direction == HMSInfo.dir_type.EW && hi.degree >= 0)
q = "-";
else q = "";
int thour = hi.degree >= 0 ? hi.degree : -hi.degree;
string w = q + thour.ToString() + "." + numToString(hi.minute) + numToString (hi.second) + "00";
sw.WriteLine(w);
}
private static HMSInfo readHmsLineInfo (StreamReader sr, bool negate, HMSInfo.dir_type dir)
{
int h=0, m=0, s=0;
readHmsLine (sr, ref h, ref m, ref s);
if (negate) h *= -1;
return new HMSInfo(h, m, s, dir);
}
private static void readHmsLine (StreamReader sr, ref int hour, ref int minute, ref int second)
{
String s = sr.ReadLine();
Regex re = new Regex("[0-9]*$");
Match m = re.Match (s);
String s2 = m.Value;
if (s[0] == '|') s = new string(s.ToCharArray(1, s.Length-1));
double dhour = double.Parse (s);
dhour = dhour < 0 ? Math.Ceiling (dhour) : Math.Floor (dhour);
hour = (int)dhour;
minute = int.Parse(s2.Substring(0, 2));
double _second = 0.0;
if (s2.Length > 5)
_second = (double.Parse(s2.Substring(2,4)) / 10000.0) * 60.0;
second = (int)_second;
}
private static Moment readMomentLine (StreamReader sr)
{
int month = readIntLine (sr);
int day = readIntLine (sr);
int year = readIntLine (sr);
int hour=0, minute=0, second=0;
readHmsLine (sr, ref hour, ref minute, ref second);
return new Moment (year, month, day, hour, minute, second);
}
private static string numToString (int _n)
{
int n = _n < 0 ? -_n : _n;
string s;
if (n < 10) s = "0" + n.ToString();
else s = n.ToString();
return s;
}
private static void writeMomentLine (StreamWriter sw, Moment m)
{
sw.WriteLine (m.month);
sw.WriteLine (m.day);
sw.WriteLine (m.year);
sw.WriteLine (m.hour.ToString() + "." + numToString(m.minute) + numToString(m.second) + "00");
}
public HoraInfo toHoraInfo ()
{
StreamReader sr = File.OpenText (fname);
Moment m = readMomentLine (sr);
HMSInfo tz = readHmsLineInfo (sr, true, HMSInfo.dir_type.EW);
HMSInfo lon = readHmsLineInfo (sr, true, HMSInfo.dir_type.EW);
HMSInfo lat = readHmsLineInfo (sr, false, HMSInfo.dir_type.NS);
HoraInfo hi = new HoraInfo(m, lat, lon, tz);
hi.FileType = HoraInfo.EFileType.JagannathaHora;
//hi.name = File.fname;
return hi;
}
public void ToFile (HoraInfo h)
{
StreamWriter sw = new StreamWriter(fname, false);
writeMomentLine (sw, h.tob);
writeHMSInfoLine (sw, h.tz);
writeHMSInfoLine (sw, h.lon);
writeHMSInfoLine (sw, h.lat);
sw.WriteLine ("0.000000");
sw.Flush();
sw.Close();
}
}
/// <summary>
/// Simple functions that don't belong anywhere else
/// </summary>
public class Basics
{
/// <summary>
/// Normalize a number between bounds
/// </summary>
/// <param name="lower">The lower bound of normalization</param>
/// <param name="upper">The upper bound of normalization</param>
/// <param name="x">The value to be normalized</param>
/// <returns>The normalized value of x, where lower <= x <= upper </returns>
public static int normalize_inc (int lower, int upper, int x)
{
int size = upper - lower + 1;
while (x > upper) x -= size;
while (x < lower) x += size;
Trace.Assert (x >= lower && x <= upper, "Basics.normalize failed");
return x;
}
/// <summary>
/// Normalize a number between bounds
/// </summary>
/// <param name="lower">The lower bound of normalization</param>
/// <param name="upper">The upper bound of normalization</param>
/// <param name="x">The value to be normalized</param>
/// <returns>The normalized value of x, where lower = x <= upper </returns>
public static double normalize_exc (double lower, double upper, double x)
{
double size = upper - lower;
while (x > upper) x -= size;
while (x <= lower) x += size;
Trace.Assert (x >= lower && x <= upper, "Basics.normalize failed");
return x;
}
public static double normalize_exc_lower (double lower, double upper, double x)
{
double size = upper - lower;
while (x >= upper) x -= size;
while (x < lower) x += size;
Trace.Assert (x >= lower && x <= upper, "Basics.normalize failed");
return x;
}
public static ZodiacHouse getMoolaTrikonaRasi (Body.Name b)
{
ZodiacHouse.Name z = ZodiacHouse.Name.Ari;
switch (b)
{
case Body.Name.Sun: z = ZodiacHouse.Name.Leo; break;
case Body.Name.Moon: z = ZodiacHouse.Name.Tau; break;
case Body.Name.Mars: z = ZodiacHouse.Name.Ari; break;
case Body.Name.Mercury: z = ZodiacHouse.Name.Vir; break;
case Body.Name.Jupiter: z = ZodiacHouse.Name.Sag; break;
case Body.Name.Venus: z = ZodiacHouse.Name.Lib; break;
case Body.Name.Saturn: z = ZodiacHouse.Name.Aqu; break;
case Body.Name.Rahu: z = ZodiacHouse.Name.Vir; break;
case Body.Name.Ketu: z = ZodiacHouse.Name.Pis; break;
}
return new ZodiacHouse (z);
}
public static Weekday bodyToWeekday (Body.Name b)
{
switch (b)
{
case Body.Name.Sun: return Weekday.Sunday;
case Body.Name.Moon: return Weekday.Monday;
case Body.Name.Mars: return Weekday.Tuesday;
case Body.Name.Mercury: return Weekday.Wednesday;
case Body.Name.Jupiter: return Weekday.Thursday;
case Body.Name.Venus: return Weekday.Friday;
case Body.Name.Saturn: return Weekday.Saturday;
}
Debug.Assert(false, string.Format("bodyToWeekday({0})", b));
throw new Exception();
}
public static Body.Name weekdayRuler (Weekday w)
{
switch (w)
{
case Weekday.Sunday: return Body.Name.Sun;
case Weekday.Monday: return Body.Name.Moon;
case Weekday.Tuesday: return Body.Name.Mars;
case Weekday.Wednesday: return Body.Name.Mercury;
case Weekday.Thursday: return Body.Name.Jupiter;
case Weekday.Friday: return Body.Name.Venus;
case Weekday.Saturday: return Body.Name.Saturn;
default:
Debug.Assert(false, "Basics::weekdayRuler");
return Body.Name.Sun;
}
}
// This matches the sweph definitions for easy conversion
public enum Weekday : int
{
Monday=0, Tuesday=1, Wednesday=2, Thursday=3, Friday=4, Saturday=5, Sunday=6
}
public static string weekdayToShortString (Weekday w)
{
switch (w)
{
case Weekday.Sunday: return "Su";
case Weekday.Monday: return "Mo";
case Weekday.Tuesday: return "Tu";
case Weekday.Wednesday: return "We";
case Weekday.Thursday: return "Th";
case Weekday.Friday: return "Fr";
case Weekday.Saturday: return "Sa";
}
return "";
}
/// <summary>
/// Enumeration of the various division types. Where a varga has multiple
/// definitions, each of these should be specified separately below
/// </summary>
[TypeConverter(typeof(EnumDescConverter))]
public enum DivisionType : int
{
[Description("D-1: Rasi")] Rasi=0,
[Description("D-9: Navamsa")] Navamsa,
[Description("D-2: Hora (Parashara)")] HoraParasara,
[Description("D-2: Hora (Jagannatha)")] HoraJagannath,
[Description("D-2: Hora (Parivritti)")] HoraParivrittiDwaya,
[Description("D-2: Hora (Kashinatha)")] HoraKashinath,
[Description("D-3: Dreshkana (Parashara)")] DrekkanaParasara,
[Description("D-3: Dreshkana (Jagannatha)")] DrekkanaJagannath,
[Description("D-3: Dreshkana (Somnatha)")] DrekkanaSomnath,
[Description("D-3: Dreshkana (Parivritti)")] DrekkanaParivrittitraya,
[Description("D-4: Chaturthamsa")] Chaturthamsa,
[Description("D-5: Panchamsa")] Panchamsa,
[Description("D-6: Shashtamsa")] Shashthamsa,
[Description("D-7: Saptamsa")] Saptamsa,
[Description("D-8: Ashtamsa")] Ashtamsa,
[Description("D-8: Ashtamsa (Raman)")] AshtamsaRaman,
[Description("D-10: Dasamsa")] Dasamsa,
[Description("D-11: Rudramsa (Rath)")] Rudramsa,
[Description("D-11: Rudramsa (Raman)")] RudramsaRaman,
[Description("D-12: Dwadasamsa")] Dwadasamsa,
[Description("D-16: Shodasamsa")] Shodasamsa,
[Description("D-20: Vimsamsa")] Vimsamsa,
[Description("D-24: Chaturvimsamsa")] Chaturvimsamsa,
[Description("D-27: Nakshatramsa")] Nakshatramsa,
[Description("D-30: Trimsamsa (Parashara)")] Trimsamsa,
[Description("D-30: Trimsamsa (Parivritti)")] TrimsamsaParivritti,
[Description("D-30: Trimsamsa (Simple)")] TrimsamsaSimple,
[Description("D-40: Khavedamsa")] Khavedamsa,
[Description("D-45: Akshavedamsa")] Akshavedamsa,
[Description("D-60: Shashtyamsa")] Shashtyamsa,
[Description("D-108: Ashtottaramsa (Regular)")] Ashtottaramsa,
[Description("D-150: Nadiamsa (Equal Division)")] Nadiamsa,
[Description("D-150: Nadiamsa (Chandra Kala Nadi)")] NadiamsaCKN,
[Description("D-9-12: Navamsa-Dwadasamsa (Composite)")] NavamsaDwadasamsa,
[Description("D-12-12: Dwadasamsa-Dwadasamsa (Composite)")] DwadasamsaDwadasamsa,
[Description("D-1: Bhava (9 Padas)")] BhavaPada,
[Description("D-1: Bhava (Equal Length)")] BhavaEqual,
[Description("D-1: Bhava (Alcabitus)")] BhavaAlcabitus,
[Description("D-1: Bhava (Axial)")] BhavaAxial,
[Description("D-1: Bhava (Campanus)")] BhavaCampanus,
[Description("D-1: Bhava (Koch)")] BhavaKoch,
[Description("D-1: Bhava (Placidus)")] BhavaPlacidus,
[Description("D-1: Bhava (Regiomontanus)")] BhavaRegiomontanus,
[Description("D-1: Bhava (Sripati)")] BhavaSripati,
[Description("Regular: Parivritti")] GenericParivritti,
[Description("Regular: Shashtamsa (d-6)")] GenericShashthamsa,
[Description("Regular: Saptamsa (d-7)")] GenericSaptamsa,
[Description("Regular: Dasamsa (d-10)")] GenericDasamsa,
[Description("Regular: Dwadasamsa (d-12)")] GenericDwadasamsa,
[Description("Regular: Chaturvimsamsa (d-24)")] GenericChaturvimsamsa,
[Description("Trikona: Drekkana (d-3)")] GenericDrekkana,
[Description("Trikona: Shodasamsa (d-16)")] GenericShodasamsa,
[Description("Trikona: Vimsamsa (d-20)")] GenericVimsamsa,
[Description("Kendra: Chaturthamsa (d-4)")] GenericChaturthamsa,
[Description("Kendra: Nakshatramsa (d-27)")] GenericNakshatramsa
}
public enum Muhurta : int
{
Rudra=1, Ahi, Mitra, Pitri, Vasu, Ambu, Visvadeva, Abhijit, Vidhata, Puruhuta,
Indragni, Nirriti, Varuna, Aryaman, Bhaga, Girisa, Ajapada, Ahirbudhnya, Pushan, Asvi,
Yama, Agni, Vidhaatri, Chanda, Aditi, Jiiva, Vishnu, Arka, Tvashtri, Maruta
}
static public Nakshatra28.Name NakLordOfMuhurta (Muhurta m)
{
switch (m)
{
case Muhurta.Rudra: return Nakshatra28.Name.Aridra;
case Muhurta.Ahi: return Nakshatra28.Name.Aslesha;
case Muhurta.Mitra: return Nakshatra28.Name.Anuradha;
case Muhurta.Pitri: return Nakshatra28.Name.Makha;
case Muhurta.Vasu: return Nakshatra28.Name.Dhanishta;
case Muhurta.Ambu: return Nakshatra28.Name.PoorvaShada;
case Muhurta.Visvadeva: return Nakshatra28.Name.UttaraShada;
case Muhurta.Abhijit: return Nakshatra28.Name.Abhijit;
case Muhurta.Vidhata: return Nakshatra28.Name.Rohini;
case Muhurta.Puruhuta: return Nakshatra28.Name.Jyestha;
case Muhurta.Indragni: return Nakshatra28.Name.Vishaka;
case Muhurta.Nirriti: return Nakshatra28.Name.Moola;
case Muhurta.Varuna: return Nakshatra28.Name.Satabisha;
case Muhurta.Aryaman: return Nakshatra28.Name.UttaraPhalguni;
case Muhurta.Bhaga: return Nakshatra28.Name.PoorvaPhalguni;
case Muhurta.Girisa: return Nakshatra28.Name.Aridra;
case Muhurta.Ajapada: return Nakshatra28.Name.PoorvaBhadra;
case Muhurta.Ahirbudhnya: return Nakshatra28.Name.UttaraBhadra;
case Muhurta.Pushan: return Nakshatra28.Name.Revati;
case Muhurta.Asvi: return Nakshatra28.Name.Aswini;
case Muhurta.Yama: return Nakshatra28.Name.Bharani;
case Muhurta.Agni: return Nakshatra28.Name.Krittika;
case Muhurta.Vidhaatri: return Nakshatra28.Name.Rohini;
case Muhurta.Chanda: return Nakshatra28.Name.Mrigarirsa;
case Muhurta.Aditi: return Nakshatra28.Name.Punarvasu;
case Muhurta.Jiiva: return Nakshatra28.Name.Pushya;
case Muhurta.Vishnu: return Nakshatra28.Name.Sravana;
case Muhurta.Arka: return Nakshatra28.Name.Hasta;
case Muhurta.Tvashtri: return Nakshatra28.Name.Chittra;
case Muhurta.Maruta: return Nakshatra28.Name.Swati;
}
Debug.Assert (false, string.Format("Basics::NakLordOfMuhurta Unknown Muhurta {0}", m));
return Nakshatra28.Name.Aswini;
}
public static string variationNameOfDivision (Division d)
{
if (d.MultipleDivisions.Length > 1)
return "Composite";
switch (d.MultipleDivisions[0].Varga)
{
case DivisionType.Rasi:
return "Rasi";
case DivisionType.Navamsa:
return "Navamsa";
case DivisionType.HoraParasara:
return "Parasara";
case DivisionType.HoraJagannath:
return "Jagannath";
case DivisionType.HoraParivrittiDwaya:
return "Parivritti";
case DivisionType.HoraKashinath:
return "Kashinath";
case DivisionType.DrekkanaParasara:
return "Parasara";
case DivisionType.DrekkanaJagannath:
return "Jagannath";
case DivisionType.DrekkanaParivrittitraya:
return "Parivritti";
case DivisionType.DrekkanaSomnath:
return "Somnath";
case DivisionType.Chaturthamsa:
return "";
case DivisionType.Panchamsa:
return "";
case DivisionType.Shashthamsa:
return "";
case DivisionType.Saptamsa:
return "";
case DivisionType.Ashtamsa:
return "Rath";
case DivisionType.AshtamsaRaman:
return "Raman";
case DivisionType.Dasamsa:
return "";
case DivisionType.Rudramsa:
return "Rath";
case DivisionType.RudramsaRaman:
return "Raman";
case DivisionType.Dwadasamsa:
return "";
case DivisionType.Shodasamsa:
return "";
case DivisionType.Vimsamsa:
return "";
case DivisionType.Chaturvimsamsa:
return "";
case DivisionType.Nakshatramsa:
return "";
case DivisionType.Trimsamsa:
return "";
case DivisionType.TrimsamsaParivritti:
return "Parivritti";
case DivisionType.TrimsamsaSimple:
return "Simple";
case DivisionType.Khavedamsa:
return "";
case DivisionType.Akshavedamsa:
return "";
case DivisionType.Shashtyamsa:
return "";
case DivisionType.Ashtottaramsa:
return "";
case DivisionType.Nadiamsa:
return "Equal Size";
case DivisionType.NadiamsaCKN:
return "Chandra Kala";
case DivisionType.NavamsaDwadasamsa:
return "Composite";
case DivisionType.DwadasamsaDwadasamsa:
return "Composite";
case DivisionType.BhavaPada:
return "9 Padas";
case DivisionType.BhavaEqual:
return "Equal Houses";
case DivisionType.BhavaAlcabitus:
return "Alcabitus";
case DivisionType.BhavaAxial:
return "Axial";
case DivisionType.BhavaCampanus:
return "Campanus";
case DivisionType.BhavaKoch:
return "Koch";
case DivisionType.BhavaPlacidus:
return "Placidus";
case DivisionType.BhavaRegiomontanus:
return "Regiomontanus";
case DivisionType.BhavaSripati:
return "Sripati";
case DivisionType.GenericParivritti:
return "Parivritti";
case DivisionType.GenericShashthamsa:
return "Regular: Shashtamsa";
case DivisionType.GenericSaptamsa:
return "Regular: Saptamsa";
case DivisionType.GenericDasamsa:
return "Regular: Dasamsa";
case DivisionType.GenericDwadasamsa:
return "Regular: Dwadasamsa";
case DivisionType.GenericChaturvimsamsa:
return "Regular: Chaturvimsamsa";
case DivisionType.GenericChaturthamsa:
return "Kendra: Chaturtamsa";
case DivisionType.GenericNakshatramsa:
return "Kendra: Nakshatramsa";
case DivisionType.GenericDrekkana:
return "Trikona: Drekkana";
case DivisionType.GenericShodasamsa:
return "Trikona: Shodasamsa";
case DivisionType.GenericVimsamsa:
return "Trikona: Vimsamsa";
}
Debug.Assert(false, string.Format("Basics::numPartsInBasics.DivisionType. Unknown Division {0}", d.MultipleDivisions[0].Varga));
return "";
}
public static string numPartsInDivisionString (Division div)
{
string sRet = "D";
foreach (Division.SingleDivision dSingle in div.MultipleDivisions)
{
sRet = string.Format("{0}-{1}", sRet, numPartsInDivision(dSingle));
}
return sRet;
}
public static int numPartsInDivision (Division div)
{
int parts = 1;
foreach (Division.SingleDivision dSingle in div.MultipleDivisions)
{
parts *= numPartsInDivision(dSingle);
}
return parts;
}
public static int numPartsInDivision (Division.SingleDivision dSingle)
{
switch (dSingle.Varga)
{
case DivisionType.Rasi:
return 1;
case DivisionType.Navamsa:
return 9;
case DivisionType.HoraParasara:
case DivisionType.HoraJagannath:
case DivisionType.HoraParivrittiDwaya:
case DivisionType.HoraKashinath:
return 2;
case DivisionType.DrekkanaParasara:
case DivisionType.DrekkanaJagannath:
case DivisionType.DrekkanaParivrittitraya:
case DivisionType.DrekkanaSomnath:
return 3;
case DivisionType.Chaturthamsa:
return 4;
case DivisionType.Panchamsa:
return 5;
case DivisionType.Shashthamsa:
return 6;
case DivisionType.Saptamsa:
return 7;
case DivisionType.Ashtamsa:
case DivisionType.AshtamsaRaman:
return 8;
case DivisionType.Dasamsa:
return 10;
case DivisionType.Rudramsa:
case DivisionType.RudramsaRaman:
return 11;
case DivisionType.Dwadasamsa:
return 12;
case DivisionType.Shodasamsa:
return 16;
case DivisionType.Vimsamsa:
return 20;
case DivisionType.Chaturvimsamsa:
return 24;
case DivisionType.Nakshatramsa:
return 27;
case DivisionType.Trimsamsa:
case DivisionType.TrimsamsaParivritti:
case DivisionType.TrimsamsaSimple:
return 30;
case DivisionType.Khavedamsa:
return 40;
case DivisionType.Akshavedamsa:
return 45;
case DivisionType.Shashtyamsa:
return 60;
case DivisionType.Ashtottaramsa:
return 108;
case DivisionType.Nadiamsa:
case DivisionType.NadiamsaCKN:
return 150;
case DivisionType.NavamsaDwadasamsa:
return 108;
case DivisionType.DwadasamsaDwadasamsa:
return 144;
case DivisionType.BhavaPada:
case DivisionType.BhavaEqual:
case DivisionType.BhavaAlcabitus:
case DivisionType.BhavaAxial:
case DivisionType.BhavaCampanus:
case DivisionType.BhavaKoch:
case DivisionType.BhavaPlacidus:
case DivisionType.BhavaRegiomontanus:
case DivisionType.BhavaSripati:
return 1;
default:
return dSingle.NumParts;
}
}
public static Division[] Shadvargas ()
{
return new Division[]
{
new Division(DivisionType.Rasi),
new Division(DivisionType.HoraParasara),
new Division(DivisionType.DrekkanaParasara),
new Division(DivisionType.Navamsa),
new Division(DivisionType.Dwadasamsa),
new Division(DivisionType.Trimsamsa)
};
}
public static Division[] Saptavargas ()
{
return new Division[]
{
new Division(DivisionType.Rasi),
new Division(DivisionType.HoraParasara),
new Division(DivisionType.DrekkanaParasara),
new Division(DivisionType.Saptamsa),
new Division(DivisionType.Navamsa),
new Division(DivisionType.Dwadasamsa),
new Division(DivisionType.Trimsamsa)
};
}
public static Division[] Dasavargas ()
{
return new Division[]
{
new Division(DivisionType.Rasi),
new Division(DivisionType.HoraParasara),
new Division(DivisionType.DrekkanaParasara),
new Division(DivisionType.Saptamsa),
new Division(DivisionType.Navamsa),
new Division(DivisionType.Dasamsa),
new Division(DivisionType.Dwadasamsa),
new Division(DivisionType.Shodasamsa),
new Division(DivisionType.Trimsamsa),
new Division(DivisionType.Shashtyamsa)
};
}
public static Division[] Shodasavargas ()
{
return new Division[]
{
new Division(DivisionType.Rasi),
new Division(DivisionType.HoraParasara),
new Division(DivisionType.DrekkanaParasara),
new Division(DivisionType.Chaturthamsa),
new Division(DivisionType.Saptamsa),
new Division(DivisionType.Navamsa),
new Division(DivisionType.Dasamsa),
new Division(DivisionType.Dwadasamsa),
new Division(DivisionType.Shodasamsa),
new Division(DivisionType.Vimsamsa),
new Division(DivisionType.Chaturvimsamsa),
new Division(DivisionType.Nakshatramsa),
new Division(DivisionType.Trimsamsa),
new Division(DivisionType.Khavedamsa),
new Division(DivisionType.Akshavedamsa),
new Division(DivisionType.Shashtyamsa)
};
}
/// <summary>
/// Specify the Lord of a ZodiacHouse. The owernership of the nodes is not considered
/// </summary>
/// <param name="zh">The House whose lord should be returned</param>
/// <returns>The lord of zh</returns>
public static Body.Name SimpleLordOfZodiacHouse (ZodiacHouse.Name zh)
{
switch (zh)
{
case ZodiacHouse.Name.Ari: return Body.Name.Mars;
case ZodiacHouse.Name.Tau: return Body.Name.Venus;
case ZodiacHouse.Name.Gem: return Body.Name.Mercury;
case ZodiacHouse.Name.Can: return Body.Name.Moon;
case ZodiacHouse.Name.Leo: return Body.Name.Sun;
case ZodiacHouse.Name.Vir: return Body.Name.Mercury;
case ZodiacHouse.Name.Lib: return Body.Name.Venus;
case ZodiacHouse.Name.Sco: return Body.Name.Mars;
case ZodiacHouse.Name.Sag: return Body.Name.Jupiter;
case ZodiacHouse.Name.Cap: return Body.Name.Saturn;
case ZodiacHouse.Name.Aqu: return Body.Name.Saturn;
case ZodiacHouse.Name.Pis: return Body.Name.Jupiter;
}
Trace.Assert (false,
string.Format ("Basics.SimpleLordOfZodiacHouse for {0} failed", (int)zh));
return Body.Name.Other;
}
public static Longitude CalculateBodyLongitude (double ut, int ipl)
{
double[] xx = new Double[6]{0,0,0,0,0,0};
try
{
sweph.swe_calc_ut(ut, ipl, 0, xx);
return new Longitude(xx[0]);
}
catch (SwephException exc)
{
System.Console.WriteLine ( "Sweph: {0}\n", exc.status);
throw new System.Exception("");
}
}
/// <summary>
/// Calculated a BodyPosition for a given time and place using the swiss ephemeris
/// </summary>
/// <param name="ut">The time for which the calculations should be performed</param>
/// <param name="ipl">The Swiss Ephemeris body Name</param>
/// <param name="body">The local application body name</param>
/// <param name="type">The local application body type</param>
/// <returns>A BodyPosition class</returns>
///
public static BodyPosition CalculateSingleBodyPosition (double ut, int ipl, Body.Name body, BodyType.Name type, Horoscope h)
{
if (body == Body.Name.Lagna)
{
BodyPosition b = new BodyPosition(h, body, type, new Longitude(sweph.swe_lagna(ut)), 0, 0, 0, 0, 0);
return b;
}
double[] xx = new Double[6] {0,0,0,0,0,0};
try
{
sweph.swe_calc_ut (ut, ipl, 0, xx);
BodyPosition b = new BodyPosition (h, body, type, new Longitude(xx[0]), xx[1], xx[2],
xx[3], xx[4], xx[5]);
return b;
}
catch (SwephException exc)
{
System.Console.WriteLine ( "Sweph: {0}\n", exc.status);
throw new System.Exception("");
}
}
/// <summary>
/// Given a HoraInfo object (all required user inputs), calculate a list of
/// all bodypositions we will ever require
/// </summary>
/// <param name="h">The HoraInfo object</param>
/// <returns></returns>
public static ArrayList CalculateBodyPositions (Horoscope h, double sunrise)
{
HoraInfo hi = h.info;
HoroscopeOptions o = h.options;
StringBuilder serr = new StringBuilder (256);
string ephe_path = MhoraGlobalOptions.Instance.HOptions.EphemerisPath;
// The order of the array must reflect the order define in Basics.GrahaIndex
ArrayList std_grahas = new ArrayList (20);
sweph.swe_set_ephe_path (ephe_path);
double julday_ut = sweph.swe_julday (hi.tob.year, hi.tob.month, hi.tob.day,
hi.tob.time - hi.tz.toDouble());
// h.tob.hour + (((double)h.tob.minute) / 60.0) + (((double)h.tob.second) / 3600.0));
// (h.tob.time / 24.0) + (h.tz.toDouble()/24.0));
//(h.tob.hour/24.0) + (((double)h.tob.minute) / 60.0) + (((double)h.tob.second) / 3600.0));
//julday_ut = julday_ut - (h.tz.toDouble() / 24.0);
int swephRahuBody = sweph.SE_MEAN_NODE;
if (o.nodeType == HoroscopeOptions.ENodeType.True)
swephRahuBody = sweph.SE_TRUE_NODE;
int addFlags = 0;
if (o.grahaPositionType == HoroscopeOptions.EGrahaPositionType.True)
addFlags = sweph.SEFLG_TRUEPOS;
std_grahas.Add (CalculateSingleBodyPosition (julday_ut, sweph.SE_SUN, Body.Name.Sun, BodyType.Name.Graha, h));
std_grahas.Add (CalculateSingleBodyPosition (julday_ut, sweph.SE_MOON, Body.Name.Moon, BodyType.Name.Graha, h));
std_grahas.Add (CalculateSingleBodyPosition (julday_ut, sweph.SE_MARS, Body.Name.Mars, BodyType.Name.Graha, h));
std_grahas.Add (CalculateSingleBodyPosition (julday_ut, sweph.SE_MERCURY, Body.Name.Mercury, BodyType.Name.Graha, h));
std_grahas.Add (CalculateSingleBodyPosition (julday_ut, sweph.SE_JUPITER, Body.Name.Jupiter, BodyType.Name.Graha, h));
std_grahas.Add (CalculateSingleBodyPosition (julday_ut, sweph.SE_VENUS, Body.Name.Venus, BodyType.Name.Graha, h));
std_grahas.Add (CalculateSingleBodyPosition (julday_ut, sweph.SE_SATURN, Body.Name.Saturn, BodyType.Name.Graha, h));
BodyPosition rahu = CalculateSingleBodyPosition (julday_ut, swephRahuBody, Body.Name.Rahu, BodyType.Name.Graha, h);
BodyPosition ketu = CalculateSingleBodyPosition (julday_ut, swephRahuBody, Body.Name.Ketu, BodyType.Name.Graha, h);
ketu.longitude = rahu.longitude.add (new Longitude (180.0));
std_grahas.Add (rahu);
std_grahas.Add (ketu);
double asc = sweph.swe_lagna(julday_ut);
std_grahas.Add (new BodyPosition (h, Body.Name.Lagna, BodyType.Name.Lagna, new Longitude (asc), 0, 0, 0, 0, 0));
double ista_ghati = normalize_exc( 0.0, 24.0, hi.tob.time - sunrise) * 2.5;
Longitude gl_lon = ((BodyPosition)std_grahas[0]).longitude.add(new Longitude(ista_ghati * 30.0));
Longitude hl_lon = ((BodyPosition)std_grahas[0]).longitude.add(new Longitude(ista_ghati * 30.0/ 2.5));
Longitude bl_lon = ((BodyPosition)std_grahas[0]).longitude.add(new Longitude(ista_ghati * 30.0/ 5.0));
double vl = ista_ghati * 5.0;
while (ista_ghati > 12.0) ista_ghati -= 12.0;
Longitude vl_lon = ((BodyPosition)std_grahas[0]).longitude.add(new Longitude(vl * 30.0));
std_grahas.Add (new BodyPosition (h, Body.Name.BhavaLagna, BodyType.Name.SpecialLagna, bl_lon,0,0,0,0,0));
std_grahas.Add (new BodyPosition (h, Body.Name.HoraLagna, BodyType.Name.SpecialLagna, hl_lon,0,0,0,0,0));
std_grahas.Add (new BodyPosition (h, Body.Name.GhatiLagna, BodyType.Name.SpecialLagna, gl_lon, 0,0,0,0,0));
std_grahas.Add (new BodyPosition (h, Body.Name.VighatiLagna, BodyType.Name.SpecialLagna, vl_lon,0,0,0,0,0));
return std_grahas;
}
}
/// <summary>
/// Mutually exclusive classes of BodyTypes
/// </summary>
public class BodyType
{
public enum Name : int
{
Lagna, Graha, NonLunarNode,
SpecialLagna, ChandraLagna,
BhavaArudha, BhavaArudhaSecondary, GrahaArudha,
Varnada, Upagraha, Sahama, Other
}
}
/// <summary>
/// A compile-time list of every body we will use in this program
/// </summary>
public class Body
{
[TypeConverter(typeof(EnumDescConverter))]
public enum Name :int
{
// Do NOT CHANGE ORDER WITHOUT CHANING NARAYANA DASA ETC
// RELY ON EXPLICIT EQUAL CONVERSION FOR STRONGER CO_LORD ETC
Sun=0, Moon=1, Mars=2, Mercury=3, Jupiter=4, Venus=5, Saturn=6,
Rahu=7, Ketu=8, Lagna=9,
// And now, we're no longer uptight about the ordering :-)
[Description("Bhava Lagna")] BhavaLagna,
[Description("Hora Lagna")] HoraLagna,
[Description("Ghati Lagna")] GhatiLagna,
[Description("Sree Lagna")] SreeLagna,
Pranapada,
[Description("Vighati Lagna")] VighatiLagna,
Dhuma, Vyatipata, Parivesha, Indrachapa, Upaketu,
Kala, Mrityu, ArthaPraharaka, YamaGhantaka, Gulika, Maandi,
[Description("Chandra Ayur Lagna")] ChandraAyurLagna,
MrityuPoint, Other,
AL, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, UL,
}
public static int toInt (Body.Name b)
{
return ((int)b);
}
public static Longitude exaltationDegree (Body.Name b)
{
int _b = (int)b;
Debug.Assert (_b >= (int)Name.Sun && _b <= (int)Name.Saturn);
double d = 0;
switch (b)
{
case Name.Sun: d = 10; break;
case Name.Moon: d = 33; break;
case Name.Mars: d = 298; break;
case Name.Mercury: d = 165; break;
case Name.Jupiter: d = 95; break;
case Name.Venus: d = 357; break;
case Name.Saturn: d = 200; break;
}
return new Longitude(d);
}
public static Longitude debilitationDegree (Body.Name b)
{
return exaltationDegree (b).add(180);
}
public static string toString (Body.Name b)
{
switch (b)
{
case Name.Lagna: return "Lagna";
case Name.Sun: return "Sun";
case Name.Moon: return "Moon";
case Name.Mars: return "Mars";
case Name.Mercury: return "Mercury";
case Name.Jupiter: return "Jupiter";
case Name.Venus: return "Venus";
case Name.Saturn: return "Saturn";
case Name.Rahu: return "Rahu";
case Name.Ketu: return "Ketu";
}
return "";
}
public static string toShortString(Body.Name b)
{
switch (b)
{
case Name.Lagna: return "As";
case Name.Sun: return "Su";
case Name.Moon: return "Mo";
case Name.Mars: return "Ma";
case Name.Mercury: return "Me";
case Name.Jupiter: return "Ju";
case Name.Venus: return "Ve";
case Name.Saturn: return "Sa";
case Name.Rahu: return "Ra";
case Name.Ketu: return "Ke";
case Name.AL: return "AL";
case Name.A2: return "A2";
case Name.A3: return "A3";
case Name.A4: return "A4";
case Name.A5: return "A5";
case Name.A6: return "A6";
case Name.A7: return "A7";
case Name.A8: return "A8";
case Name.A9: return "A9";
case Name.A10: return "A10";
case Name.A11: return "A11";