Beispiel #1
0
        public GPLocation getLocation(double jdate)
        {
            if (jdate < julianStart)
            {
                return(temp);
            }
            if (jdate > julianEnd)
            {
                return(temp);
            }

            double lonA, lonB;
            double latA, latB;

            lonA = LocationA.GetLongitudeEastPositive();
            lonB = LocationB.GetLongitudeEastPositive();
            latA = LocationA.GetLatitudeNorthPositive();
            latB = LocationB.GetLatitudeNorthPositive();

            temp.setTimeZone(TimezoneStart ? LocationA.getTimeZone() : LocationB.getTimeZone());
            temp.setLongitudeEastPositive(lonA + (lonB - lonA) * (jdate - julianStart) / (julianEnd - julianStart));
            temp.setLatitudeNorthPositive(latA + (latB - latA) * (jdate - julianStart) / (julianEnd - julianStart));
            //Debugger.Log(0, "", String.Format("== longitude/latitude {0} {1}\n", temp.getLongitudeString(), temp.getLatitudeString()));
            temp.SetAltitude(0);

            return(temp);
        }
Beispiel #2
0
        public static GPLocationProvider getMyLocation()
        {
            if (myLocation == null)
            {
                myLocation = new GPLocationProvider();
                bool   bSucc        = false;
                string possibleFile = GPFileHelper.getAppDataFile("mylocation.xml");
                if (File.Exists(possibleFile))
                {
                    try
                    {
                        myLocation.loadXml(possibleFile);
                        bSucc = true;
                    }
                    catch
                    {
                    }
                }

                if (bSucc == false)
                {
                    NumberFormatInfo fmt = new NumberFormatInfo();
                    GPLocation       loc = new GPLocation();
                    loc.setCity(GPUserDefaults.StringForKey("myloc.city", "Mayapur"));
                    loc.setCountryCode(GPUserDefaults.StringForKey("myloc.country", "IN"));
                    loc.setLatitudeNorthPositive(double.Parse(GPUserDefaults.StringForKey("myloc.lat", "23.423413"), fmt));
                    loc.setLongitudeEastPositive(double.Parse(GPUserDefaults.StringForKey("myloc.lon", "88.388079"), fmt));
                    loc.setTimeZoneName(GPUserDefaults.StringForKey("myloc.tzname", "Asia/Calcutta"));
                    myLocation.setDefaultLocation(loc);
                }
            }

            return(myLocation);
        }
Beispiel #3
0
 public override void InsertNewObjectFromStrings(string[] parts, FileKey fk)
 {
     if (parts.Length >= 5 && parts[0].Length > 0)
     {
         NumberFormatInfo fmt      = new NumberFormatInfo();
         GPLocation       location = new GPLocation();
         location.setCity(parts[0]);
         location.setLatitudeNorthPositive(double.Parse(parts[1], fmt));
         location.setLongitudeEastPositive(double.Parse(parts[2], fmt));
         location.setCountryCode(parts[3]);
         location.setTimeZoneName(parts[4]);
         locations.Add(location);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Creates GPLocationProvider object from given data.
        /// </summary>
        /// <param name="city">Any string</param>
        /// <param name="longitude">Unit is degrees. Positive values are to the east, negative values are to the west.</param>
        /// <param name="latitude">Unit is degrees. Positive values are for the north hemisphere, negative values are for south hemisphere.</param>
        /// <param name="timeZoneName">Name of timezone. This is one of the values returned by function GPTimeZoneList.sharedTimeZones().getTimeZones()</param>
        /// <returns></returns>
        public static GPLocationProvider EncapsulateLocation(string city, double longitude, double latitude, string timeZoneName)
        {
            GPLocation loca = new GPLocation();

            loca.setCity(city);
            loca.setLongitudeEastPositive(longitude);
            loca.setLatitudeNorthPositive(latitude);
            loca.setTimeZoneName(timeZoneName);

            GPLocationProvider locProv = new GPLocationProvider();

            locProv.setDefaultLocation(loca);

            return(locProv);
        }
Beispiel #5
0
        public static void TestMoonEvents()
        {
            TRiseSet     kind;
            GPJulianTime dp = new GPJulianTime();

            dp.setLocalJulianDay(defJulian);
            GPLocation obs = new GPLocation();

            obs.setLatitudeNorthPositive(defLatitude).setLongitudeEastPositive(defLongitude).SetAltitude(0.2);
            GPLocationProvider prov = new GPLocationProvider(obs);

            for (int k = 0; k < 26; k++)
            {
                dp = GPAstroEngine.GetNextMoonEvent(dp, prov, out kind);
                Log("next event = {0}, {1}\n", dp, kind);
                dp.AddHours(1);
            }
        }
Beispiel #6
0
        public GPLocation getTravellingLocation(double ratio)
        {
            double lonA, lonB;
            double latA, latB;

            lonA = LocationA.GetLongitudeEastPositive();
            lonB = LocationB.GetLongitudeEastPositive();
            latA = LocationA.GetLatitudeNorthPositive();
            latB = LocationB.GetLatitudeNorthPositive();

            GPLocation newLoc = new GPLocation();

            newLoc.setTimeZone(TimezoneStart ? LocationA.getTimeZone() : LocationB.getTimeZone());
            newLoc.setLongitudeEastPositive(lonA + (lonB - lonA) * ratio);
            newLoc.setLatitudeNorthPositive(latA + (latB - latA) * ratio);
            newLoc.SetAltitude(0);

            return(newLoc);
        }
Beispiel #7
0
        /// <summary>
        /// Main function of this class
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public bool ParseCommandArguments(string[] args)
        {
            GPLocationProvider loc = new GPLocationProvider();
            GPLocation         loc1 = new GPLocation();
            GPGregorianTime    vcStart = new GPGregorianTime(loc), vcEnd = new GPGregorianTime(loc);
            GPVedicTime        vaStart = new GPVedicTime(), vaEnd = new GPVedicTime();
            int    nCount;
            int    nReq = 0;
            string strFileOut = "";

            try
            {
                loc1.setLatitudeNorthPositive(0.0);
                loc1.setLongitudeEastPositive(0.0);
                loc1.setTimeZoneName("");
                loc.setDefaultLocation(loc1);
                vcStart.Clear();
                vcEnd         = vcStart;
                vaStart.tithi = vaStart.masa = vaStart.gyear = 0;
                vaEnd         = vaStart;
                nCount        = -1;

                int argc = args.Length;
                for (int i = 0; i < argc; i++)
                {
                    //TRACE2("arg %d = %s\n", i, args[i]);
                    if (args[i] == "-L")
                    {
                        if (argc >= i + 2)
                        {
                            loc1.setLongitudeString(args[i + 1]);
                            double lat   = 0.0;
                            double longi = 0.0;
                            GetArg_EarthPos(args[i + 1], ref lat, ref longi);
                            loc1.setLongitudeEastPositive(longi);
                            loc1.setLatitudeNorthPositive(lat);
                            //TRACE2("-L latitude=%f longitude=%f\n", loc.m_fLatitude, loc.m_fLongitude);
                        }
                        i++;
                    }
                    else if (args[i] == "-N")
                    {
                        if (argc >= i + 2)
                        {
                            loc1.setCity(args[i + 1]);
                            //TRACE1("-N name=%s\n", loc.m_strName);
                        }
                        i++;
                    }
                    else if (args[i] == "-SV")
                    {
                        if (argc >= i + 2)
                        {
                            GetArg_VaisnDate(args[i + 1], out vaStart);
                        }
                        i++;
                    }
                    else if (args[i] == "-SG")
                    {
                        if (argc >= i + 2)
                        {
                            GetArg_Date(args[i + 1], out vcStart);
                        }
                        i++;
                    }
                    else if (args[i] == "-ST")
                    {
                        if (argc >= i + 2)
                        {
                            GetArg_Time(args[i + 1], out vcStart);
                        }
                        i++;
                    }
                    else if (args[i] == "-EG")
                    {
                        if (argc >= i + 2)
                        {
                            GetArg_Date(args[i + 1], out vcEnd);
                            //AfxTrace("-EG day=%d month=%d year=%d\n", vcEnd.day, vcEnd.month, vcEnd.year);
                        }
                        i++;
                    }
                    else if (args[i] == "-EV")
                    {
                        if (argc >= i + 2)
                        {
                            GetArg_VaisnDate(args[i + 1], out vaEnd);
                            //AfxTrace("-EV tithi=%d masa=%d gyear=%d\n", vaEnd.tithi, vaEnd.masa, vaEnd.gyear);
                        }
                        i++;
                    }
                    else if (args[i] == "-EC")
                    {
                        if (argc >= i + 2)
                        {
                            int.TryParse(args[i + 1], out nCount);
                        }
                        i++;
                    }
                    else if (args[i] == "-TZ")
                    {
                        if (argc >= i + 2)
                        {
                            loc1.setTimeZoneName(args[i + 1]);
                        }
                        i++;
                    }
                    else if (args[i] == "-O")
                    {
                        if (argc >= i + 2)
                        {
                            strFileOut = args[i + 1];
                        }
                        i++;
                    }
                    else if (args[i] == "-R")
                    {
                        if (argc >= i + 2)
                        {
                            if (args[i + 1] == "calendar")
                            {
                                nReq = 10;
                            }
                            else if (args[i + 1] == "appday")
                            {
                                nReq = 11;
                            }
                            else if (args[i + 1] == "tithi")
                            {
                                nReq = 12;
                            }
                            else if (args[i + 1] == "sankranti")
                            {
                                nReq = 13;
                            }
                            else if (args[i + 1] == "naksatra")
                            {
                                nReq = 14;
                            }
                            else if (args[i + 1] == "firstday")
                            {
                                nReq = 15;
                            }
                            else if (args[i + 1] == "gcalendar")
                            {
                                nReq = 16;
                            }
                            else if (args[i + 1] == "gtithi")
                            {
                                nReq = 17;
                            }
                            else if (args[i + 1] == "next")
                            {
                                nReq = 18;
                            }
                            else if (args[i + 1] == "help")
                            {
                                nReq = 60;
                            }

                            /*else if (args[i+1] == "")
                             * {
                             * } else if (args[i+1] == "")
                             * {
                             * } else if (args[i+1] == "")
                             * {
                             * } else if (args[i+1] == "")
                             * {
                             * }*/
                        }
                        i++;
                    }
                }

                vcStart.setLocationProvider(loc);
                vcEnd.setLocationProvider(loc);

                switch (nReq)
                {
                case 10:
                case 13:
                case 14:
                    if (vcStart.getYear() == 0 && vaStart.gyear != 0)
                    {
                        GPEngine.VATIMEtoVCTIME(vaStart, out vcStart, loc);
                    }
                    if (vcEnd.getYear() == 0 && vaEnd.gyear != 0)
                    {
                        GPEngine.VATIMEtoVCTIME(vaEnd, out vcEnd, loc);
                    }
                    break;

                default:
                    break;
                }

                if (vcStart.getYear() != 0 && vcEnd.getYear() != 0 && nCount < 0)
                {
                    nCount = Convert.ToInt32(vcEnd.getJulianLocalNoon() - vcStart.getJulianLocalNoon());
                }

                if (nCount < 0)
                {
                    nCount = 30;
                }

                GPAppDayResults   appday   = new GPAppDayResults();
                GPCalendarResults calendar = new GPCalendarResults();
                //AfxTrace("Count === %d\n", nCount);

                StringBuilder fout = new StringBuilder();
                switch (nReq)
                {
                case 10:
                    // -R -O -LAT -LON -SG -C [-DST -NAME]
                    vcStart.NextDay();
                    vcStart.PreviousDay();
                    calendar.CalculateCalendar(vcStart, nCount);
                    FormaterXml.WriteXml(FormaterXml.GetCalendarXmlDocument(calendar), fout);
                    break;

                case 11:
                    // -R -O -LAT -LON -SG -ST [-NAME]
                    appday.calculateAppearanceDayData(loc, vcStart);
                    FormaterXml.FormatAppDayXML(appday, fout);
                    break;

                case 12:
                    FormaterXml.WriteXML_Tithi(fout, loc, vcStart);
                    break;

                case 13:
                    if (vcEnd.getYear() == 0)
                    {
                        vcEnd = vcStart;
                        vcEnd.AddDays(nCount);
                    }
                    FormaterXml.WriteXml(FormaterXml.GetSankrantiXml(loc, vcStart, vcEnd), fout);
                    break;

                case 14:
                    FormaterXml.WriteXML_Naksatra(fout, loc, vcStart, nCount);
                    break;

                case 15:
                    FormaterXml.WriteXML_FirstDay_Year(fout, vcStart);
                    break;

                case 16:
                    vcStart = GPGaurabdaYear.getFirstDayOfYear(loc, vcStart.getYear());
                    vcEnd   = GPGaurabdaYear.getFirstDayOfYear(loc, vcStart.getYear() + 1);
                    nCount  = Convert.ToInt32(vcEnd.getJulianLocalNoon() - vcStart.getJulianLocalNoon());
                    calendar.CalculateCalendar(vcStart, nCount);
                    FormaterXml.WriteXml(FormaterXml.GetCalendarXmlDocument(calendar), fout);
                    break;

                case 17:
                    FormaterXml.WriteXML_GaurabdaTithi(fout, loc, vaStart, vaEnd);
                    break;

                case 18:
                    FormaterXml.WriteXML_GaurabdaNextTithi(fout, loc, vcStart, vaStart);
                    break;
                }
                // application should be windowless
                // since some parameters are present

                File.WriteAllText(strFileOut, fout.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception during execution: " + ex.Message);
            }

            return(true);
        }