Пример #1
0
 static int main_test(int argc, string[] argv) {
     string sdate_save = String.Empty;
     string s1 = String.Empty, s2 = String.Empty;
     string sp/*, sp2*/; int spi, sp2i;
     char spno;
     string plsel = PLSEL_D;
     //#if HPUNIX
     //  char hostname[80];
     //#endif
     int i, j, n, iflag_f = -1, iflgt;
     int line_count, line_limit = 32000;
     double daya;
     double top_long = 0.0;	/* Greenwich UK */
     double top_lat = 51.5;
     double top_elev = 0;
     bool have_geopos = false;
     char ihsy = 'p';
     bool do_houses = false;
     string fname = String.Empty;
     string sdate = String.Empty;
     string begindate = null;
     Int32 iflgret;
     bool with_header = true;
     bool with_header_always = false;
     bool do_ayanamsa = false;
     Int32 sid_mode = SwissEph.SE_SIDM_FAGAN_BRADLEY;
     double t2, tstep = 1, thour = 0;
     double delt;
     datm[0] = 0; datm[1] = 0; datm[2] = 0; datm[3] = 0;
     dobs[0] = 0; dobs[1] = 0;
     dobs[2] = 0; dobs[3] = 0; dobs[4] = 0; dobs[5] = 0;
     serr = serr_save = serr_warn = sdate_save = String.Empty;
     //# ifdef MACOS
     //  argc = ccommand(&argv); /* display the arguments window */    
     //# endif
     using (sweph = new SwissEph()) {
         sweph.OnLoadFile += sweph_OnLoadFile;
         ephepath = @".;C:\\sweph\ephe";
         fname = SwissEph.SE_FNAME_DFT;
         for (i = 1; i < argc; i++) {
             if (argv[i].StartsWith("-ut")) {
                 universal_time = true;
                 if (argv[i].Length > 3) {
                     s1 = string.Empty;
                     s1 += argv[i] + 3;
                     if ((spi = s1.IndexOf(':')) >= 0) {
                         s1 = String.Concat(s1.Substring(0, spi), ".", s1.Substring(spi + 1));
                         if ((spi = s1.IndexOf(':')) >= 0) {
                             s1 = String.Concat(s1.Substring(0, spi), s1.Substring(spi + 1));
                         }
                     }
                     thour = double.Parse(s1);
                     /* h.mmss -> decimal */
                     t = (thour % 1.0) * 100 + 1e-6;
                     j = (int)t;
                     t = (t % 1.0) * 100 + 1e-6;
                     thour = (int)thour + j / 60.0 + t / 3600.0;
                 }
             } else if (argv[i].StartsWith("-head")) {
                 with_header = false;
             } else if (argv[i].StartsWith("+head")) {
                 with_header_always = true;
             } else if (String.Compare(argv[i], "-j2000") == 0) {
                 iflag |= SwissEph.SEFLG_J2000;
             } else if (String.Compare(argv[i], "-icrs") == 0) {
                 iflag |= SwissEph.SEFLG_ICRS;
             } else if (argv[i].StartsWith("-ay")) {
                 do_ayanamsa = true;
                 sid_mode = int.Parse(argv[i] + 3);
                 //sweph.swe_set_sid_mode(sid_mode, 0, 0);
             } else if (argv[i].StartsWith("-sidt0")) {
                 iflag |= SwissEph.SEFLG_SIDEREAL;
                 sid_mode = int.Parse(argv[i] + 6);
                 if (sid_mode == 0)
                     sid_mode = SwissEph.SE_SIDM_FAGAN_BRADLEY;
                 sid_mode |= SwissEph.SE_SIDBIT_ECL_T0;
                 //sweph.swe_set_sid_mode(sid_mode, 0, 0);
             } else if (argv[i].StartsWith("-sidsp")) {
                 iflag |= SwissEph.SEFLG_SIDEREAL;
                 sid_mode = int.Parse(argv[i] + 6);
                 if (sid_mode == 0)
                     sid_mode = SwissEph.SE_SIDM_FAGAN_BRADLEY;
                 sid_mode |= SwissEph.SE_SIDBIT_SSY_PLANE;
                 //sweph.swe_set_sid_mode(sid_mode, 0, 0);
             } else if (argv[i].StartsWith("-sid")) {
                 iflag |= SwissEph.SEFLG_SIDEREAL;
                 sid_mode = int.Parse(argv[i] + 4);
                 //if (sid_mode > 0)
                 //    sweph.swe_set_sid_mode(sid_mode, 0, 0);
             } else if (String.Compare(argv[i], "-jplhora") == 0) {
                 iflag |= SwissEph.SEFLG_JPLHOR_APPROX;
             } else if (String.Compare(argv[i], "-jplhor") == 0) {
                 iflag |= SwissEph.SEFLG_JPLHOR;
             } else if (argv[i].StartsWith("-j")) {
                 begindate = argv[i] + 1;
             } else if (argv[i].StartsWith("-ejpl")) {
                 whicheph = SwissEph.SEFLG_JPLEPH;
                 if (argv[i].Length > 5) {
                     fname = argv[i].Substring(5);
                 }
             } else if (argv[i].StartsWith("-edir")) {
                 if (argv[i].Length > 5) {
                     ephepath = argv[i].Substring(5);
                 }
             } else if (String.Compare(argv[i], "-eswe") == 0) {
                 whicheph = SwissEph.SEFLG_SWIEPH;
             } else if (String.Compare(argv[i], "-emos") == 0) {
                 whicheph = SwissEph.SEFLG_MOSEPH;
             } else if (argv[i].StartsWith("-helflag")) {
                 helflag = int.Parse(argv[i] + 8);
                 if (helflag >= SwissEph.SE_HELFLAG_AV)
                     hel_using_AV = true;
             } else if (String.Compare(argv[i], "-hel") == 0) {
                 iflag |= SwissEph.SEFLG_HELCTR;
             } else if (String.Compare(argv[i], "-bary") == 0) {
                 iflag |= SwissEph.SEFLG_BARYCTR;
             } else if (argv[i].StartsWith("-house")) {
                 sout = String.Empty;
                 C.sscanf(argv[i].Substring(6), "%lf,%lf,%c", ref top_long, ref top_lat, ref sout);
                 top_elev = 0;
                 if (!String.IsNullOrEmpty(sout)) ihsy = sout[0];
                 do_houses = true;
                 have_geopos = true;
             } else if (argv[i].StartsWith("-hsy")) {
                 ihsy = argv[i].Length > 4 ? argv[i][4] : '\0';
                 if (ihsy == '\0') ihsy = 'p';
                 if (argv[i].Length > 5)
                     hpos_meth = int.Parse(argv[i].Substring(5));
                 have_geopos = true;
             } else if (argv[i].StartsWith("-topo")) {
                 iflag |= SwissEph.SEFLG_TOPOCTR;
                 C.sscanf(argv[i].Substring(5), "%lf,%lf,%lf", ref top_long, ref top_lat, ref top_elev);
                 have_geopos = true;
             } else if (argv[i].StartsWith("-geopos")) {
                 C.sscanf(argv[i].Substring(7), "%lf,%lf,%lf", ref top_long, ref top_lat, ref top_elev);
                 have_geopos = true;
             } else if (String.Compare(argv[i], "-true") == 0) {
                 iflag |= SwissEph.SEFLG_TRUEPOS;
             } else if (String.Compare(argv[i], "-noaberr") == 0) {
                 iflag |= SwissEph.SEFLG_NOABERR;
             } else if (String.Compare(argv[i], "-nodefl") == 0) {
                 iflag |= SwissEph.SEFLG_NOGDEFL;
             } else if (String.Compare(argv[i], "-nonut") == 0) {
                 iflag |= SwissEph.SEFLG_NONUT;
             } else if (String.Compare(argv[i], "-speed3") == 0) {
                 iflag |= SwissEph.SEFLG_SPEED3;
             } else if (String.Compare(argv[i], "-speed") == 0) {
                 iflag |= SwissEph.SEFLG_SPEED;
             } else if (argv[i].StartsWith("-testaa")) {
                 whicheph = SwissEph.SEFLG_JPLEPH;
                 fname = SwissEph.SE_FNAME_DE200;
                 if (String.Compare(argv[i].Substring(7), "95") == 0)
                     begindate = "j2449975.5";
                 if (String.Compare(argv[i].Substring(7), "96") == 0)
                     begindate = "j2450442.5";
                 if (String.Compare(argv[i].Substring(7), "97") == 0)
                     begindate = "j2450482.5";
                 fmt = "PADRu";
                 universal_time = false;
                 plsel = "3";
             } else if (String.Compare(argv[i], "-lmt") == 0) {
                 universal_time = true;
                 time_flag |= BIT_TIME_LMT;
             } else if (String.Compare(argv[i], "-lat") == 0) {
                 universal_time = true;
                 time_flag |= BIT_TIME_LAT;
             } else if (String.Compare(argv[i], "-lunecl") == 0) {
                 special_event = SP_LUNAR_ECLIPSE;
             } else if (String.Compare(argv[i], "-solecl") == 0) {
                 special_event = SP_SOLAR_ECLIPSE;
                 have_geopos = true;
             } else if (String.Compare(argv[i], "-short") == 0) {
                 short_output = true;
             } else if (String.Compare(argv[i], "-occult") == 0) {
                 special_event = SP_OCCULTATION;
                 have_geopos = true;
             } else if (String.Compare(argv[i], "-hocal") == 0) {
                 /* used to create a listing for inclusion in hocal.c source code */
                 special_mode |= SP_MODE_HOCAL;
             } else if (String.Compare(argv[i], "-how") == 0) {
                 special_mode |= SP_MODE_HOW;
             } else if (String.Compare(argv[i], "-total") == 0) {
                 search_flag |= SwissEph.SE_ECL_TOTAL | SwissEph.SE_ECL_CENTRAL | SwissEph.SE_ECL_NONCENTRAL;
             } else if (String.Compare(argv[i], "-annular") == 0) {
                 search_flag |= SwissEph.SE_ECL_ANNULAR | SwissEph.SE_ECL_CENTRAL | SwissEph.SE_ECL_NONCENTRAL;
             } else if (String.Compare(argv[i], "-anntot") == 0) {
                 search_flag |= SwissEph.SE_ECL_ANNULAR_TOTAL | SwissEph.SE_ECL_CENTRAL | SwissEph.SE_ECL_NONCENTRAL;
             } else if (String.Compare(argv[i], "-partial") == 0) {
                 search_flag |= SwissEph.SE_ECL_PARTIAL | SwissEph.SE_ECL_CENTRAL | SwissEph.SE_ECL_NONCENTRAL;
             } else if (String.Compare(argv[i], "-penumbral") == 0) {
                 search_flag |= SwissEph.SE_ECL_PENUMBRAL;
             } else if (String.Compare(argv[i], "-noncentral") == 0) {
                 search_flag &= ~SwissEph.SE_ECL_CENTRAL;
                 search_flag |= SwissEph.SE_ECL_NONCENTRAL;
             } else if (String.Compare(argv[i], "-central") == 0) {
                 search_flag &= ~SwissEph.SE_ECL_NONCENTRAL;
                 search_flag |= SwissEph.SE_ECL_CENTRAL;
             } else if (String.Compare(argv[i], "-local") == 0) {
                 special_mode |= SP_MODE_LOCAL;
             } else if (String.Compare(argv[i], "-rise") == 0) {
                 special_event = SP_RISE_SET;
                 have_geopos = true;
             } else if (String.Compare(argv[i], "-norefrac") == 0) {
                 norefrac = 1;
             } else if (String.Compare(argv[i], "-disccenter") == 0) {
                 disccenter = 1;
             } else if (String.Compare(argv[i], "-hindu") == 0) {
                 norefrac = 1;
                 disccenter = 1;
             } else if (String.Compare(argv[i], "-discbottom") == 0) {
                 discbottom = 1;
             } else if (String.Compare(argv[i], "-metr") == 0) {
                 special_event = SP_MERIDIAN_TRANSIT;
                 have_geopos = true;
                 /* secret test feature for dieter */
             } else if (argv[i].StartsWith("-prec")) {
                 j = 0;
                 //astro_models[j] = atoi(argv[i] + 5);
                 //sp = argv[i];
                 //while ((sp2 = strchr(sp, ',')) != NULL)
                 //{
                 //    sp = sp2 + 1;
                 //    j++;
                 //    astro_models[j] = atoi(sp);
                 //}
                 var parts = argv[i].Substring(5).Split(',');
                 foreach (var p in parts)
                 {
                     int xx = 0;
                     int.TryParse(p, out xx);
                     j++;
                     astro_models[j] = xx;
                 }
                 do_set_astro_models = true;
             } else if (argv[i].StartsWith("-hev"))
             {
                 special_event = SP_HELIACAL;
                 search_flag = 0;
                 if (argv[i].Length > 4)
                     search_flag = int.Parse(argv[i].Substring(4));
                 have_geopos = true;
                 if (argv[i].Contains("AV")) hel_using_AV = true;
             } else if (argv[i].StartsWith("-at")) {
                 C.sscanf(argv[i].Substring(3), "%lf,%lf,%lf,%lf", ref datm[0], ref datm[1], ref datm[2], ref datm[3]);
             } else if (argv[i].StartsWith("-obs")) {
                 C.sscanf(argv[i].Substring(4), "%lf,%lf", ref (dobs[0]), ref (dobs[1]));
             } else if (argv[i].StartsWith("-opt")) {
                 C.sscanf(argv[i].Substring(4), "%lf,%lf,%lf,%lf,%lf,%lf", ref (dobs[0]), ref (dobs[1]), ref (dobs[2]), ref (dobs[3]), ref (dobs[4]), ref (dobs[5]));
             } else if (String.Compare(argv[i], "-bwd") == 0) {
                 direction = -1;
                 direction_flag = true;
             } else if (argv[i].StartsWith("-p")) {
                 spno = argv[i][2];
                 switch (spno) {
                     case 'd':
                         /*
                         case '\0':
                         case ' ':  
                         */
                         plsel = PLSEL_D; break;
                     case 'p': plsel = PLSEL_P; break;
                     case 'h': plsel = PLSEL_H; break;
                     case 'a': plsel = PLSEL_A; break;
                     default: plsel = spno.ToString(); break;
                 }
             } else if (argv[i].StartsWith("-xs")) {
                 /* number of asteroid */
                 sastno = argv[i].Substring(3);
             } else if (argv[i].StartsWith("-xf")) {
                 /* name or number of fixed star */
                 star = argv[i].Substring(3);
             } else if (argv[i].StartsWith("-xz")) {
                 /* number of hypothetical body */
                 shyp = argv[i].Substring(3);
             } else if (argv[i].StartsWith("-x")) {
                 /* name or number of fixed star */
                 star = argv[i].Substring(2);
             } else if (argv[i].StartsWith("-n")) {
                 nstep = int.Parse(argv[i].Substring(2));
                 if (nstep == 0)
                     nstep = 20;
             } else if (argv[i].StartsWith("-i")) {
                 iflag_f = int.Parse(argv[i].Substring(2));
                 if ((iflag_f & SwissEph.SEFLG_XYZ) != 0)
                     fmt = "PX";
             } else if (argv[i].StartsWith("-s")) {
                 tstep = double.Parse(argv[i].Substring(2));
             } else if (argv[i].StartsWith("-b")) {
                 begindate = argv[i].Substring(2);
             } else if (argv[i].StartsWith("-f")) {
                 fmt = argv[i].Substring(2);
             } else if (argv[i].StartsWith("-g")) {
                 gap = argv[i].Substring(2);
                 if (String.IsNullOrEmpty(gap)) gap = "\t";
             } else if (argv[i].StartsWith("-d") || argv[i].StartsWith("-D")) {
                 diff_mode = argv[i][1];	/* 'd' or 'D' */
                 sp = argv[i].Substring(2);
                 ipldiff = letter_to_ipl(String.IsNullOrEmpty(sp) ? '\0' : sp[0]);
                 if (ipldiff < 0) ipldiff = SwissEph.SE_SUN;
                 spnam2 = sweph.swe_get_planet_name(ipldiff);
             } else if (String.Compare(argv[i], "-roundsec") == 0) {
                 round_flag |= BIT_ROUND_SEC;
             } else if (String.Compare(argv[i], "-roundmin") == 0) {
                 round_flag |= BIT_ROUND_MIN;
             /*} else if (strncmp(argv[i], "-timeout", 8) == 0) {
                   swe_set_timeout(atoi(argv[i]) + 8);*/
             }
             else if (argv[i].StartsWith("-t"))
             {
                 if (argv[i].Length > 2) {
                     s1 = argv[i].Substring(2);
                     if ((spi = s1.IndexOf(':')) >= 0) {
                         s1 = String.Concat(s1.Substring(0, spi), ".", s1.Substring(spi + 1));
                         if ((spi = s1.IndexOf(':')) >= 0) {
                             s1 = String.Concat(s1.Substring(0, spi), s1.Substring(spi + 1));
                         }
                     }
                     thour = double.Parse(s1);
                     /* h.mmss -> decimal */
                     t = (thour % 1.0) * 100 + 1e-6;
                     j = (int)t;
                     t = (t % 1.0) * 100 + 1e-6;
                     thour = (int)thour + j / 60.0 + t / 3600.0;
                 }
             } else if (argv[i].StartsWith("-h") || argv[i].StartsWith("-?")) {
                 sp = argv[i].Length > 2 ? argv[i].Substring(2, 1) : String.Empty;
                 if (sp == "c" || sp == String.Empty) {
                     Console.Write(infocmd0);
                     Console.Write(infocmd1);
                     Console.Write(infocmd2);
                     Console.Write(infocmd3);
                     Console.Write(infocmd4);
                     Console.Write(infocmd5);
                     Console.Write(infocmd6);
                 }
                 if (sp == "p" || sp == String.Empty)
                     Console.Write(infoplan);
                 if (sp == "f" || sp == String.Empty) {
                     Console.Write(infoform);
                     Console.Write(infoform2);
                 }
                 if (sp == "d" || sp == String.Empty)
                     Console.Write(infodate);
                 if (sp == "e" || sp == String.Empty)
                     Console.Write(infoexamp);
                 goto end_main;
             } else {
                 sout = "illegal option ";
                 sout += argv[i];
                 sout += "\n";
                 Console.Write(sout);
                 return 1;
             }
         }
         if (special_event == SP_OCCULTATION ||
             special_event == SP_RISE_SET ||
             special_event == SP_MERIDIAN_TRANSIT ||
             special_event == SP_HELIACAL
             ) {
             ipl = letter_to_ipl(string.IsNullOrEmpty(plsel) ? '\0' : plsel[0]);
             if (plsel == "f")
                 ipl = SwissEph.SE_FIXSTAR;
             else
                 star = String.Empty;
             if (special_event == SP_OCCULTATION && ipl == 1)
                 ipl = 2; /* no occultation of moon by moon */
         }
         //#if HPUNIX
         //  gethostname (hostname, 80);
         //  if (strstr(hostname, "as10") != NULL) 
         //    line_limit = 1000;
         //#endif
         if (with_header) {
             for (i = 0; i < argc; i++) {
                 Console.Write(argv[i]);
                 Console.Write(" ");
             }
         }
         iflag = (iflag & ~SEFLG_EPHMASK) | whicheph;
         if (fmt.IndexOfAny("SsQ".ToCharArray()) >= 0 && (iflag & SwissEph.SEFLG_SPEED3) == 0)
             iflag |= SwissEph.SEFLG_SPEED;
         if (String.IsNullOrEmpty(ephepath)) {
             if (make_ephemeris_path(iflag, argv[0], ref ephepath) == SwissEph.ERR) {
                 iflag = (iflag & ~SwissEph.SEFLG_EPHMASK) | SwissEph.SEFLG_MOSEPH;
                 whicheph = SwissEph.SEFLG_MOSEPH;
             }
         }
         sweph.swe_set_ephe_path(ephepath);
         if ((whicheph & SwissEph.SEFLG_JPLEPH) != 0)
             sweph.swe_set_jpl_file(fname);
         /* the following is only a test feature */
         if (do_set_astro_models)
             sweph.swe_set_astro_models(astro_models); /* secret test feature for dieter */
         if ((iflag & SwissEph.SEFLG_SIDEREAL) != 0 || do_ayanamsa)
             sweph.swe_set_sid_mode(sid_mode, 0, 0);
         geopos[0] = top_long;
         geopos[1] = top_lat;
         geopos[2] = top_elev;
         sweph.swe_set_topo(top_long, top_lat, top_elev);
         /*swe_set_tid_acc(-25.82);  * to test delta t output */
         while (true)
         {
             serr = serr_save = serr_warn = String.Empty;
             if (begindate == null) {
                 Console.Write("\nDate ?");
                 sdate = String.Empty;
                 sdate = Console.ReadLine();
                 if (sdate == null) goto end_main;
             } else {
                 sdate = String.Empty;
                 sdate = begindate;
                 begindate = ".";  /* to exit afterwards */
             }
             if (String.Compare(sdate, "-bary") == 0) {
                 iflag = iflag & ~SwissEph.SEFLG_HELCTR;
                 iflag |= SwissEph.SEFLG_BARYCTR;
                 sdate = String.Empty;
             } else if (String.Compare(sdate, "-hel") == 0) {
                 iflag = iflag & ~SwissEph.SEFLG_BARYCTR;
                 iflag |= SwissEph.SEFLG_HELCTR;
                 sdate = String.Empty;
             } else if (String.Compare(sdate, "-geo") == 0) {
                 iflag = iflag & ~SwissEph.SEFLG_BARYCTR;
                 iflag = iflag & ~SwissEph.SEFLG_HELCTR;
                 sdate = String.Empty;
             } else if (String.Compare(sdate, "-ejpl") == 0) {
                 iflag &= ~SwissEph.SEFLG_EPHMASK;
                 iflag |= SwissEph.SEFLG_JPLEPH;
                 sdate = String.Empty;
             } else if (String.Compare(sdate, "-eswe") == 0) {
                 iflag &= ~SwissEph.SEFLG_EPHMASK;
                 iflag |= SwissEph.SEFLG_SWIEPH;
                 sdate = String.Empty;
             } else if (String.Compare(sdate, "-emos") == 0) {
                 iflag &= ~SwissEph.SEFLG_EPHMASK;
                 iflag |= SwissEph.SEFLG_MOSEPH;
                 sdate = String.Empty;
             } else if (sdate.StartsWith("-xs")) {
                 /* number of asteroid */
                 sastno = sdate.Substring(3);
                 sdate = String.Empty;
             }
             //    swe_set_tid_acc((double) (iflag & SEFLG_EPHMASK));
             sp = sdate;
             if (sp.StartsWith(".")) {
                 goto end_main;
             } else if (String.IsNullOrEmpty(sp)) {
                 sdate = sdate_save;
             } else {
                 sdate_save = sdate;
             }
             if (String.IsNullOrEmpty(sdate)) {
                 sdate = C.sprintf("j%f", tjd);
             }
             if (sp.StartsWith("j")) {   /* it's a day number */
                 if ((sp2i = sp.IndexOf(',')) >= 0)
                     //*sp2 = '.';
                     sp = String.Concat(sp.Substring(0, sp2i), '.', sp.Substring(sp2i + 1));
                 sdate = sp;
                 C.sscanf(sp.Substring(1), "%lf", ref tjd);
                 if (tjd < 2299160.5)
                     gregflag = SwissEph.SE_JUL_CAL;
                 else
                     gregflag = SwissEph.SE_GREG_CAL;
                 if (sp.Contains("jul"))
                     gregflag = SwissEph.SE_JUL_CAL;
                 else if (sp.Contains("greg"))
                     gregflag = SwissEph.SE_GREG_CAL;
                 sweph.swe_revjul(tjd, gregflag, ref jyear, ref jmon, ref jday, ref jut);
             } else if (sp.StartsWith("+")) {
                 n = int.Parse(sp);
                 if (n == 0) n = 1;
                 tjd += n;
                 sweph.swe_revjul(tjd, gregflag, ref jyear, ref jmon, ref jday, ref jut);
             } else if (sp.StartsWith("-")) {
                 n = int.Parse(sp);
                 if (n == 0) n = -1;
                 tjd += n;
                 sweph.swe_revjul(tjd, gregflag, ref jyear, ref jmon, ref jday, ref jut);
             } else {
                 if (C.sscanf(sp, "%d%*c%d%*c%d", ref jday, ref jmon, ref jyear) < 1) return 1;
                 if ((Int32)jyear * 10000L + (Int32)jmon * 100L + (Int32)jday < 15821015L)
                     gregflag = SwissEph.SE_JUL_CAL;
                 else
                     gregflag = SwissEph.SE_GREG_CAL;
                 if (sp.Contains("jul"))
                     gregflag = SwissEph.SE_JUL_CAL;
                 else if (sp.Contains("greg"))
                     gregflag = SwissEph.SE_GREG_CAL;
                 jut = 0;
                 tjd = sweph.swe_julday(jyear, jmon, jday, jut, gregflag);
                 tjd += thour / 24.0;
             }
             if (special_event > 0) {
                 do_special_event(tjd, ipl, star, special_event, special_mode, geopos, datm, dobs, ref serr);
                 //swe_close();
                 return SwissEph.OK;
             }
             line_count = 0;
             for (t = tjd, istep = 1; istep <= nstep; t += tstep, istep++) {
                 if (t < 2299160.5)
                     gregflag = SwissEph.SE_JUL_CAL;
                 else
                     gregflag = SwissEph.SE_GREG_CAL;
                 if (sdate.Contains("jul"))
                     gregflag = SwissEph.SE_JUL_CAL;
                 else if (sdate.Contains("greg"))
                     gregflag = SwissEph.SE_GREG_CAL;
                 t2 = t;
                 sweph.swe_revjul(t2, gregflag, ref jyear, ref jmon, ref jday, ref jut);
                 if (with_header) {
                     printf("\ndate (dmy) %d.%d.%d", jday, jmon, jyear);
                     if (gregflag != 0)
                         Console.Write(" greg.");
                     else
                         Console.Write(" jul.");
                     t2 = jut;
                     printf("  % 2d:", (int)t2);
                     t2 = (t2 - (Int32)t2) * 60;
                     printf("%02d:", (int)t2);
                     t2 = (t2 - (Int32)t2) * 60;
                     printf("%02d", (int)t2);
                     if (universal_time)
                         Console.Write(" UT");
                     else
                         Console.Write(" ET");
                     printf("\t\tversion %s", sweph.swe_version());
                 }
                 delt = sweph.swe_deltat(t);
                 if (universal_time) {
                     if (with_header) {
                         printf("\nUT: %.11f", t);
                     }
                     if (with_header) {
                         printf("     delta t: %f sec", delt * 86400.0);
                     }
                     te = t + delt;
                     tut = t;
                 } else {
                     te = t;
                     tut = t - delt;
                 }
                 iflgret = sweph.swe_calc(te, SwissEph.SE_ECL_NUT, iflag, xobl, ref serr);
                 if (with_header) {
                     printf("\nET: %.11f", te);
                     if ((iflag & SwissEph.SEFLG_SIDEREAL) != 0) {
                         daya = sweph.swe_get_ayanamsa(te);
                         printf("   ayanamsa = %s (%s)", dms(daya, round_flag), sweph.swe_get_ayanamsa_name(sid_mode));
                     }
                     if (have_geopos) {
                         printf("\ngeo. long %f, lat %f, alt %f", geopos[0], geopos[1], geopos[2]);
                     }
                     if (iflag_f >= 0)
                         iflag = iflag_f;
                     if (plsel.IndexOf('o') < 0) {
                         printf("\n%-15s %s", "Epsilon (true)", dms(xobl[0], round_flag));
                     }
                     if (plsel.IndexOf('n') < 0) {
                         Console.Write("\nNutation        ");
                         Console.Write(dms(xobl[2], round_flag));
                         Console.Write(gap);
                         Console.Write(dms(xobl[3], round_flag));
                     }
                     printf("\n");
                     if (do_houses) {
                         var shsy = sweph.swe_house_name(ihsy);
                         if (!universal_time) {
                             do_houses = false;
                             printf("option -house requires option -ut for Universal Time\n");
                         } else {
                             s1 = dms(top_long, round_flag);
                             s2 = dms(top_lat, round_flag);
                             printf("Houses system %c (%s) for long=%s, lat=%s\n", ihsy, shsy, s1, s2);
                         }
                     }
                 }
                 if (with_header && !with_header_always)
                     with_header = false;
                 if (do_ayanamsa) {
                     daya = sweph.swe_get_ayanamsa(te);
                     Console.Write("Ayanamsa");
                     Console.Write(gap);
                     Console.Write(dms(daya, round_flag));
                     Console.Write("\n");
                     /*printf("Ayanamsa%s%s\n", gap, dms(daya, round_flag));*/
                     continue;
                 }
                 if (plsel.IndexOf('e') >= 0)
                     print_line(MODE_LABEL);
                 for (var pspi = 0; pspi < plsel.Length; pspi++) {
                     psp = plsel[pspi];
                     if (psp == 'e') continue;
                     ipl = letter_to_ipl(psp);
                     if (ipl == -2) {
                         printf("illegal parameter -p%s\n", plsel);
                         return 1;
                     }
                     if (psp == 'f')
                         ipl = SwissEph.SE_FIXSTAR;
                     else if (psp == 's')
                         ipl = int.Parse(sastno) + 10000;
                     else if (psp == 'z')
                         ipl = int.Parse(shyp) + SwissEph.SE_FICT_OFFSET_1;
                     if ((iflag & SwissEph.SEFLG_HELCTR) != 0) {
                         if (ipl == SwissEph.SE_SUN
                               || ipl == SwissEph.SE_MEAN_NODE || ipl == SwissEph.SE_TRUE_NODE
                               || ipl == SwissEph.SE_MEAN_APOG || ipl == SwissEph.SE_OSCU_APOG)
                             continue;
                     } else if ((iflag & SwissEph.SEFLG_BARYCTR) != 0) {
                         if (ipl == SwissEph.SE_MEAN_NODE || ipl == SwissEph.SE_TRUE_NODE
                               || ipl == SwissEph.SE_MEAN_APOG || ipl == SwissEph.SE_OSCU_APOG)
                             continue;
                     } else          /* geocentric */
                         if (ipl == SwissEph.SE_EARTH)
                             continue;
                     /* ecliptic position */
                     if (iflag_f >= 0)
                         iflag = iflag_f;
                     if (ipl == SwissEph.SE_FIXSTAR) {
                         iflgret = sweph.swe_fixstar(star, te, iflag, x, ref serr);
                         /* magnitude, etc. */
                         if (iflgret != SwissEph.ERR && fmt.IndexOf('=') >= 0) {
                             double mag = 0;
                             iflgret = sweph.swe_fixstar_mag(ref star, ref mag, ref serr);
                             attr[4] = mag;
                         }
                         se_pname = star;
                     } else {
                         iflgret = sweph.swe_calc(te, ipl, iflag, x, ref serr);
                         /* phase, magnitude, etc. */
                         if (iflgret != SwissEph.ERR && fmt.IndexOfAny("+-*/=".ToCharArray()) >= 0)
                             iflgret = sweph.swe_pheno(te, ipl, iflag, attr, ref serr);
                         se_pname = sweph.swe_get_planet_name(ipl);
                     }
                     if (psp == 'q') {/* delta t */
                         x[0] = sweph.swe_deltat(te) * 86400;
                         x[1] = x[2] = x[3] = 0;
                         se_pname = "Delta T";
                     }
                     if (psp == 'o') {/* ecliptic is wanted, remove nutation */
                         x[2] = x[3] = 0;
                         se_pname = "Ecl. Obl.";
                     }
                     if (psp == 'n') {/* nutation is wanted, remove ecliptic */
                         x[0] = x[2];
                         x[1] = x[3];
                         x[2] = x[3] = 0;
                         se_pname = "Nutation";
                     }
                     if (psp == 'y') {/* time equation */
                         iflgret = sweph.swe_time_equ(tut, out (x[0]), ref serr);
                         x[0] *= 86400; /* in seconds */;
                         x[1] = x[2] = x[3] = 0;
                         se_pname = "Time Equ.";
                     }
                     if (iflgret < 0) {
                         if (String.Compare(serr, serr_save) != 0
                           && (ipl == SwissEph.SE_SUN || ipl == SwissEph.SE_MOON
                               || ipl == SwissEph.SE_MEAN_NODE || ipl == SwissEph.SE_TRUE_NODE
                               || ipl == SwissEph.SE_CHIRON || ipl == SwissEph.SE_PHOLUS || ipl == SwissEph.SE_CUPIDO
                               || ipl >= SwissEph.SE_AST_OFFSET || ipl == SwissEph.SE_FIXSTAR)) {
                             Console.Write("error: ");
                             Console.Write(serr);
                             Console.Write("\n");
                         }
                         serr_save = serr;
                     } else if (!String.IsNullOrEmpty(serr) && String.IsNullOrEmpty(serr_warn)) {
                         if (!serr.Contains("'seorbel.txt' not found"))
                             serr_warn = serr;
                     }
                     if (diff_mode != 0) {
                         iflgret = sweph.swe_calc(te, ipldiff, iflag, x2, ref serr);
                         if (iflgret < 0) {
                             Console.Write("error: ");
                             Console.Write(serr);
                             Console.Write("\n");
                         }
                         if (diff_mode == DIFF_DIFF) {
                             for (i = 1; i < 6; i++)
                                 x[i] -= x2[i];
                             if ((iflag & SwissEph.SEFLG_RADIANS) == 0)
                                 x[0] = sweph.swe_difdeg2n(x[0], x2[0]);
                             else
                                 x[0] = sweph.swe_difrad2n(x[0], x2[0]);
                         } else {	/* DIFF_MIDP */
                             for (i = 1; i < 6; i++)
                                 x[i] = (x[i] + x2[i]) / 2;
                             if ((iflag & SwissEph.SEFLG_RADIANS) == 0)
                                 x[0] = sweph.swe_deg_midp(x[0], x2[0]);
                             else
                                 x[0] = sweph.swe_rad_midp(x[0], x2[0]);
                         }
                     }
                     /* equator position */
                     if (fmt.IndexOfAny("aADdQ".ToCharArray()) >= 0) {
                         iflag2 = iflag | SwissEph.SEFLG_EQUATORIAL;
                         if (ipl == SwissEph.SE_FIXSTAR)
                             iflgret = sweph.swe_fixstar(star, te, iflag2, xequ, ref serr);
                         else
                             iflgret = sweph.swe_calc(te, ipl, iflag2, xequ, ref serr);
                         if (diff_mode != 0) {
                             iflgret = sweph.swe_calc(te, ipldiff, iflag2, x2, ref serr);
                             if (diff_mode == DIFF_DIFF) {
                                 for (i = 1; i < 6; i++)
                                     xequ[i] -= x2[i];
                                 if ((iflag & SwissEph.SEFLG_RADIANS) == 0)
                                     xequ[0] = sweph.swe_difdeg2n(xequ[0], x2[0]);
                                 else
                                     xequ[0] = sweph.swe_difrad2n(xequ[0], x2[0]);
                             } else {	/* DIFF_MIDP */
                                 for (i = 1; i < 6; i++)
                                     xequ[i] = (xequ[i] + x2[i]) / 2;
                                 if ((iflag & SwissEph.SEFLG_RADIANS) == 0)
                                     xequ[0] = sweph.swe_deg_midp(xequ[0], x2[0]);
                                 else
                                     xequ[0] = sweph.swe_rad_midp(xequ[0], x2[0]);
                             }
                         }
                     }
                     /* azimuth and height */
                     if (fmt.IndexOfAny("IiHhKk".ToCharArray()) >= 0) {
                         /* first, get topocentric equatorial positions */
                         iflgt = whicheph | SwissEph.SEFLG_EQUATORIAL | SwissEph.SEFLG_TOPOCTR;
                         if (ipl == SwissEph.SE_FIXSTAR)
                             iflgret = sweph.swe_fixstar(star, te, iflgt, xt, ref serr);
                         else
                             iflgret = sweph.swe_calc(te, ipl, iflgt, xt, ref serr);
                         /* to azimuth/height */
                         /* atmospheric pressure "0" has the effect that a value
                          * of 1013.25 mbar is assumed at 0 m above sea level.
                          * If the altitude of the observer is given (in geopos[2])
                          * pressure is estimated according to that */
                         sweph.swe_azalt(tut, SwissEph.SE_EQU2HOR, geopos, 0, 10, xt, xaz);
                         if (diff_mode != 0) {
                             iflgret = sweph.swe_calc(te, ipldiff, iflgt, xt, ref serr);
                             sweph.swe_azalt(tut, SwissEph.SE_EQU2HOR, geopos, 0, 10, xt, x2);
                             if (diff_mode == DIFF_DIFF) {
                                 for (i = 1; i < 3; i++)
                                     xaz[i] -= x2[i];
                                 if ((iflag & SwissEph.SEFLG_RADIANS) == 0)
                                     xaz[0] = sweph.swe_difdeg2n(xaz[0], x2[0]);
                                 else
                                     xaz[0] = sweph.swe_difrad2n(xaz[0], x2[0]);
                             } else {	/* DIFF_MIDP */
                                 for (i = 1; i < 3; i++)
                                     xaz[i] = (xaz[i] + x2[i]) / 2;
                                 if ((iflag & SwissEph.SEFLG_RADIANS) == 0)
                                     xaz[0] = sweph.swe_deg_midp(xaz[0], x2[0]);
                                 else
                                     xaz[0] = sweph.swe_rad_midp(xaz[0], x2[0]);
                             }
                         }
                     }
                     /* ecliptic cartesian position */
                     if (fmt.IndexOfAny("XU".ToCharArray()) >= 0) {
                         iflag2 = iflag | SwissEph.SEFLG_XYZ;
                         if (ipl == SwissEph.SE_FIXSTAR)
                             iflgret = sweph.swe_fixstar(star, te, iflag2, xcart, ref serr);
                         else
                             iflgret = sweph.swe_calc(te, ipl, iflag2, xcart, ref serr);
                         if (diff_mode != 0) {
                             iflgret = sweph.swe_calc(te, ipldiff, iflag2, x2, ref serr);
                             if (diff_mode == DIFF_DIFF) {
                                 for (i = 0; i < 6; i++)
                                     xcart[i] -= x2[i];
                             } else {
                                 xcart[i] = (xcart[i] + x2[i]) / 2;
                             }
                         }
                     }
                     /* equator cartesian position */
                     if (fmt.IndexOfAny("xu".ToCharArray()) >= 0) {
                         iflag2 = iflag | SwissEph.SEFLG_XYZ | SwissEph.SEFLG_EQUATORIAL;
                         if (ipl == SwissEph.SE_FIXSTAR)
                             iflgret = sweph.swe_fixstar(star, te, iflag2, xcartq, ref serr);
                         else
                             iflgret = sweph.swe_calc(te, ipl, iflag2, xcartq, ref serr);
                         if (diff_mode != 0) {
                             iflgret = sweph.swe_calc(te, ipldiff, iflag2, x2, ref serr);
                             if (diff_mode == DIFF_DIFF) {
                                 for (i = 0; i < 6; i++)
                                     xcartq[i] -= x2[i];
                             } else {
                                 xcartq[i] = (xcart[i] + x2[i]) / 2;
                             }
                         }
                     }
                     /* house position */
                     if (fmt.IndexOfAny("gGj".ToCharArray()) >= 0) {
                         armc = sweph.swe_degnorm(sweph.swe_sidtime(tut) * 15 + geopos[0]);
                         for (i = 0; i < 6; i++)
                             xsv[i] = x[i];
                         if (hpos_meth == 1)
                             xsv[1] = 0;
                         if (ipl == SwissEph.SE_FIXSTAR)
                             star2 = star;
                         else
                             star2 = String.Empty;
                         if (hpos_meth >= 2 && char.ToLower(ihsy) == 'g') {
                             sweph.swe_gauquelin_sector(tut, ipl, star2, iflag, hpos_meth, geopos, 0, 0, ref hposj, ref serr);
                         } else {
                             hposj = sweph.swe_house_pos(armc, geopos[1], xobl[0], ihsy, xsv, ref serr);
                         }
                         if (char.ToLower(ihsy) == 'g')
                             hpos = (hposj - 1) * 10;
                         else
                             hpos = (hposj - 1) * 30;
                         if (diff_mode != 0) {
                             for (i = 0; i < 6; i++)
                                 xsv[i] = x2[i];
                             if (hpos_meth == 1)
                                 xsv[1] = 0;
                             hpos2 = sweph.swe_house_pos(armc, geopos[1], xobl[0], ihsy, xsv, ref serr);
                             if (Char.ToLower(ihsy) == 'g')
                                 hpos2 = (hpos2 - 1) * 10;
                             else
                                 hpos2 = (hpos2 - 1) * 30;
                             if (diff_mode == DIFF_DIFF) {
                                 if ((iflag & SwissEph.SEFLG_RADIANS) == 0)
                                     hpos = sweph.swe_difdeg2n(hpos, hpos2);
                                 else
                                     hpos = sweph.swe_difrad2n(hpos, hpos2);
                             } else {	/* DIFF_MIDP */
                                 if ((iflag & SwissEph.SEFLG_RADIANS) == 0)
                                     hpos = sweph.swe_deg_midp(hpos, hpos2);
                                 else
                                     hpos = sweph.swe_rad_midp(hpos, hpos2);
                             }
                         }
                     }
                     spnam = se_pname;
                     print_line(0);
                     line_count++;
                     if (line_count >= line_limit) {
                         printf("****** line count %d was exceeded\n", line_limit);
                         break;
                     }
                 }         /* for psp */
                 if (do_houses) {
                     double[] cusp = new double[100];
                     int iofs;
                     if (char.ToLower(ihsy) == 'g')
                         nhouses = 36;
                     iofs = nhouses + 1;
                     iflgret = sweph.swe_houses_ex(t, iflag, top_lat, top_long, ihsy, cusp, cusp.GetPointer(iofs));
                     if (iflgret < 0) {
                         if (String.Compare(serr, serr_save) != 0) {
                             Console.Write("error: ");
                             Console.Write(serr);
                             Console.Write("\n");
                         }
                         serr_save = serr;
                     } else {
                         for (ipl = 1; ipl < iofs + 4; ipl++) {
                             x[0] = cusp[ipl];
                             x[1] = 0;	/* latitude */
                             x[2] = 1.0;	/* pseudo radius vector */
                             if (fmt.IndexOfAny("aADdQ".ToCharArray()) >= 0) {
                                 sweph.swe_cotrans(x, xequ, -xobl[0]);
                             }
                             print_line(MODE_HOUSE);
                             line_count++;
                         }
                     }
                 }
                 if (line_count >= line_limit)
                     break;
             }           /* for tjd */
             if (!String.IsNullOrEmpty(serr_warn)) {
                 printf("\nwarning: ");
                 Console.Write(serr_warn);
                 printf("\n");
             }
         }             /* while 1 */
     /* close open files and free allocated space */
     end_main:
         //swe_close();
         return SwissEph.OK;
     }
 }