Exemplo n.º 1
0
        /*********************************************************************/
        /*                                                                   */
        /*   finds previous time when starts next yoga                       */
        /*                                                                   */
        /*   timezone is not changed                                         */
        /*                                                                   */
        /*   return value: index of yoga 0..26                               */
        /*                 or -1 if failed                                   */
        /*********************************************************************/

        public static int GetPrevStart(GPGregorianTime startDate, out GPGregorianTime nextDate)
        {
            double          phi = 12.0;
            double          l1, l2, sunl;
            double          jday = startDate.getJulianGreenwichTime();
            double          xj;
            double          ayanamsa  = GPAyanamsa.GetAyanamsa(jday);
            GPMoon          moon      = new GPMoon();
            GPGregorianTime d         = new GPGregorianTime(startDate);
            GPGregorianTime xd        = new GPGregorianTime(startDate.getLocationProvider());
            double          scan_step = 0.5;
            int             prev_tit  = 0;
            int             new_tit   = -1;

            moon.MoonCalc(jday);
            sunl     = GPSun.GetSunLongitude(jday);
            l1       = GPMath.putIn360(moon.longitude_deg + sunl - 2 * ayanamsa);
            prev_tit = Convert.ToInt32(Math.Floor(l1 / phi));

            int counter = 0;

            while (counter < 20)
            {
                xj = jday;
                xd.Copy(d);

                jday -= scan_step;
                d.setDayHours(d.getDayHours() - scan_step);
                if (d.getDayHours() < 0.0)
                {
                    d.setDayHours(d.getDayHours() + 1.0);
                    d.PreviousDay();
                }

                moon.MoonCalc(jday);
                sunl    = GPSun.GetSunLongitude(jday);
                l2      = GPMath.putIn360(moon.longitude_deg + sunl - 2 * ayanamsa);
                new_tit = Convert.ToInt32(Math.Floor(l2 / phi));

                if (prev_tit != new_tit)
                {
                    jday = xj;
                    d.Copy(xd);
                    scan_step *= 0.5;
                    counter++;
                    continue;
                }
                else
                {
                    l1 = l2;
                }
            }
            nextDate = d;
            //	nextDate.shour += startDate.tzone / 24.0;
            //	nextDate.NormalizeValues();
            return(new_tit);
        }
Exemplo n.º 2
0
        /*********************************************************************/
        /*                                                                   */
        /*   finds previous time when starts next naksatra                   */
        /*                                                                   */
        /*   timezone is not changed                                         */
        /*                                                                   */
        /*   return value: index of naksatra 0..26                           */
        /*                 or -1 if failed                                   */
        /*********************************************************************/

        public static int GetPrevNaksatra(GPGregorianTime startDate, out GPGregorianTime nextDate)
        {
            double          phi = 40.0 / 3.0;
            double          l1, l2;
            double          jday      = startDate.getJulianGreenwichTime();
            GPMoon          moon      = new GPMoon();
            GPGregorianTime d         = new GPGregorianTime(startDate);
            double          ayanamsa  = GPAyanamsa.GetAyanamsa(jday);
            double          scan_step = 0.5;
            int             prev_naks = 0;
            int             new_naks  = -1;

            double          xj;
            GPGregorianTime xd = new GPGregorianTime(startDate.getLocationProvider());

            moon.MoonCalc(jday);
            l1        = GPMath.putIn360(moon.longitude_deg - ayanamsa);
            prev_naks = Convert.ToInt32(Math.Floor(l1 / phi));

            int counter = 0;

            while (counter < 20)
            {
                xj = jday;
                xd.Copy(d);

                jday -= scan_step;
                d.setDayHours(d.getDayHours() - scan_step);
                if (d.getDayHours() < 0.0)
                {
                    d.setDayHours(d.getDayHours() + 1.0);
                    d.PreviousDay();
                }

                moon.MoonCalc(jday);
                l2       = GPMath.putIn360(moon.longitude_deg - ayanamsa);
                new_naks = Convert.ToInt32(Math.Floor(l2 / phi));

                if (prev_naks != new_naks)
                {
                    jday = xj;
                    d.Copy(xd);
                    scan_step *= 0.5;
                    counter++;
                    continue;
                }
                else
                {
                    l1 = l2;
                }
            }

            nextDate = d;
            return(new_naks);
        }
Exemplo n.º 3
0
        // return values
        // 0 - DST is off, yesterday was off
        // 1 - DST is on, yesterday was off
        // 2 - DST is on, yesterday was on
        // 3 - DST is off, yesterday was on
        public int GetDaylightChangeType(GPGregorianTime vcDay)
        {
            GPGregorianTime vcPrevDay = new GPGregorianTime(vcDay);

            vcPrevDay.PreviousDay();

            bool t1 = DaylightSavingInEFfect(vcDay);
            bool t2 = DaylightSavingInEFfect(vcPrevDay);

            return(t1 ? (t2 ? 2 : 1) : (t2 ? 3 : 0));
        }
Exemplo n.º 4
0
        public GPAppHelper()
        {
            GPLocationProvider loc = getMyLocation();

            TodayDate = new GPGregorianTime(loc);
            TodayDate.Today();
            YesterdayDate = new GPGregorianTime(loc);
            YesterdayDate.Today();
            YesterdayDate.PreviousDay();
            TomorrowDate = new GPGregorianTime(loc);
            TomorrowDate.Today();
            TomorrowDate.NextDay();
        }
Exemplo n.º 5
0
        /*********************************************************************/
        /*  Finds date of Pratipat, Krsna Paksa, Visnu Masa                  */
        /*                                                                   */
        /*  EARTHDATA earth - location                                       */
        /*  int nYear       - Gregorian year                                 */
        /*                                                                   */
        /*********************************************************************/

        public static GPGregorianTime getFirstDayOfYear(GPLocationProvider earth, int nYear)
        {
            int[]           a = new int[] { 2, 15, 3, 1, 3, 15, 4, 1, 4, 15 };
            GPGregorianTime d = new GPGregorianTime(earth);
            GPAstroData     day = new GPAstroData();
            int             gy, j, masa;
            int             step;
            uint            tmp;

            if (nYear >= 1950 && nYear < 2058)
            {
                tmp = gGaurBeg[(nYear - 1950) * 26 + 22];
                d.setDate(nYear, Convert.ToInt32(tmp & 0x3e0) >> 5, Convert.ToInt32(tmp & 0x1f));
                d.NextDay();
                a[0] = d.getMonth();
                a[1] = d.getDay();
            }

            for (int i = 0; i < 10; i += 2)
            {
                d.setDate(nYear, a[i], a[i + 1]);

                day.calculateDayData(d, earth);
                masa = day.determineMasa(d, out gy);

                if (masa == 11) // visnu masa
                {
                    do
                    {
                        // shifts date
                        step = day.nTithi / 2;
                        step = (step > 0) ? step : 1;
                        for (j = step; j > 0; j--)
                        {
                            d.PreviousDay();
                        }
                        // try new time
                        day.calculateDayData(d, earth);
                    }while (day.nTithi < 28);
                    d.NextDay();
                    d.setDayHours(day.sun.getSunriseDayHours());
                    return(d);
                }
            }

            d.Clear();
            d.setDayHours(day.sun.getSunriseDayHours());

            return(d);
        }
Exemplo n.º 6
0
        public static int GetPrevRasi(GPGregorianTime startDate, out GPGregorianTime nextDate)
        {
            double          jday      = startDate.getJulianGreenwichTime();
            GPMoon          moon      = new GPMoon();
            GPGregorianTime d         = new GPGregorianTime(startDate);
            double          ayanamsa  = GPAyanamsa.GetAyanamsa(jday);
            double          scan_step = 0.5;
            int             prev_naks = 0;
            int             new_naks  = -1;

            double          xj;
            GPGregorianTime xd = new GPGregorianTime(startDate.getLocationProvider());

            moon.MoonCalc(jday);
            prev_naks = GPEngine.GetRasi(moon.longitude_deg, ayanamsa);

            int counter = 0;

            while (counter < 20)
            {
                xj = jday;
                xd.Copy(d);

                jday -= scan_step;
                d.setDayHours(d.getDayHours() - scan_step);
                if (d.getDayHours() < 0.0)
                {
                    d.setDayHours(d.getDayHours() + 1.0);
                    d.PreviousDay();
                }

                moon.MoonCalc(jday);
                new_naks = GPEngine.GetRasi(moon.longitude_deg, ayanamsa);

                if (prev_naks != new_naks)
                {
                    jday = xj;
                    d.Copy(xd);
                    scan_step *= 0.5;
                    counter++;
                    continue;
                }
            }

            nextDate = d;
            return(new_naks);
        }
Exemplo n.º 7
0
        public static void FormatTodayInfoRtf(GPGregorianTime vc, GPLocationProvider loc, StringBuilder str)
        {
            string str2, str3 = string.Empty;

            GPCalendarResults db = new GPCalendarResults();

            GPGregorianTime vc2 = new GPGregorianTime(vc);

            vc2.PreviousDay();
            vc2.PreviousDay();
            vc2.PreviousDay();
            vc2.PreviousDay();
            db.CalculateCalendar(vc2, 9);

            int           i = db.FindDate(vc);
            GPCalendarDay p = db.get(i);

            if (p == null)
            {
                return;
            }

            str.Remove(0, str.Length);
            AppendRtfHeader(str);
            str2 = string.Format("\\f2\\fs{0} {1} ", g_HeaderSize, GPAppHelper.getDateText(vc));
            str.Append(str2);

            str.AppendFormat("\\par\\f2\\fs{0} {{\\fs{1} {2}}\\line {3} ({4}, {5}, {6}: {7})",
                             g_TextSize, g_TextSize + 4, getSharedStringRtf(p.date.getDayOfWeek()), loc.getFullName(), loc.getLocation(0).getLatitudeString(),
                             loc.getLocation(0).getLongitudeString(), getSharedStringRtf(12),
                             loc.getLocation(0).getTimeZoneName());
            str.AppendLine("\\par");
            str.AppendLine("\\par");
            str.AppendFormat("  {0}, {1}", p.getTithiName(), p.getPaksaName());
            str.AppendLine("\\par");
            str.AppendFormat("  {0}, {1}", p.getMasaLongName(), p.getGaurabdaYearLongString());
            str.AppendLine("\\par");
            str.AppendLine("\\par");


            // adding mahadvadasi
            // adding spec festivals

            foreach (GPCalendarDay.Festival fest in p.CompleteFestivalList(db.get(i - 1), db.get(i + 1)))
            {
                if (GPUserDefaults.BoolForKey(fest.ShowSettingItem, true))
                {
                    if (fest.ShowSettingItem == GPDisplays.Keys.CalendarSankranti)
                    {
                        str.AppendLine(fest.Text.PadLeft((80 + str2.Length) / 2, '-').PadRight(80, '-'));
                        str.AppendLine("\\par");
                    }
                    else
                    {
                        str.Append("\\tab");
                        str.Append(fest.Text);
                        str.AppendLine("\\par");
                    }
                }
            }

            str.AppendLine("\\par");


            if (GPDisplays.Today.BrahmaMuhurtaVisible())
            {
                str.AppendLine("\\par");
                str.AppendFormat("{0} {1}", getSharedStringRtf(988), p.astrodata.sun.arunodaya.getShortMuhurtaRange(0));
            }

            if (GPDisplays.Today.SunriseVisible())
            {
                str.AppendLine("\\par");
                str.AppendFormat("{0} {1} ", getSharedStringRtf(51), p.astrodata.sun.rise.getShortTimeString());
                if (GPDisplays.Today.SandhyaTimesVisible())
                {
                    str.AppendFormat(" {0} {1} ", getSharedStringRtf(989), p.astrodata.sun.rise.getShortSandhyaRange());
                }
                str.AppendFormat(" ({0})", GPAppHelper.GetDSTSignature(p.isDaylightInEffect()));
                str.AppendLine("\\par");
            }
            if (GPDisplays.Today.NoonVisible())
            {
                str2 = string.Format("{0} {1} ", getSharedStringRtf(857), p.astrodata.sun.noon.getShortTimeString());
                str.Append(str2);
                if (GPDisplays.Today.SandhyaTimesVisible())
                {
                    str.AppendFormat(" {0} {1} ", getSharedStringRtf(989), p.astrodata.sun.noon.getShortSandhyaRange());
                }
                str.AppendFormat(" ({0})", GPAppHelper.GetDSTSignature(p.isDaylightInEffect()));
                str.AppendLine("\\par");
            }
            if (GPDisplays.Today.SunsetVisible())
            {
                str.AppendFormat("{0}  {1} ", getSharedStringRtf(52), p.astrodata.sun.set.getShortTimeString());
                if (GPDisplays.Today.SandhyaTimesVisible())
                {
                    str.AppendFormat(" {0} {1} ", getSharedStringRtf(989), p.astrodata.sun.set.getShortSandhyaRange());
                }
                str.AppendFormat(" ({0})", GPAppHelper.GetDSTSignature(p.isDaylightInEffect()));
                str.AppendLine("\\par");
            }
            if (GPDisplays.Today.SunriseInfo())
            {
                str.AppendLine("\\par");
                str.Append(getSharedStringRtf(990));
                str.AppendLine("\\par");
                str.AppendFormat("   {1} {2}", GPNaksatra.getName(p.astrodata.nNaksatra), getSharedStringRtf(15));
                if (GPDisplays.Today.NaksatraPadaVisible())
                {
                    str.AppendFormat(", {0} {1} ({2})", p.astrodata.nNaksatraElapse, getSharedStringRtf(993), getSharedStringRtf(811 + p.getNaksatraPada()));
                }
                if (GPDisplays.Today.RasiOfMoonVisible())
                {
                    str.AppendFormat(", {0}: {1}", getSharedStringRtf(991), GPSankranti.getName(p.astrodata.nMoonRasi));
                }
                str.AppendFormat(", {0} {1}", GPYoga.getName(p.astrodata.nYoga), getSharedStringRtf(104));
                str.AppendLine("\\par");
                str.AppendFormat("  {0} {1}", getSharedStringRtf(992), GPSankranti.getName(p.astrodata.nSunRasi));
                str.AppendLine("\\par");
            }
            /* END GCAL 1.4.3 */

            AddNoteRtf(str);
        }
Exemplo n.º 8
0
        public static GPGregorianTime CalcTithiEndEx(GPGregorianTime vcStart, int GYear, int nMasa, int nPaksa, int nTithi, GPLocationProvider earth, out GPGregorianTime endTithi)
        {
            int             i, gy, nType;
            GPGregorianTime d     = new GPGregorianTime(earth);
            GPGregorianTime dtemp = new GPGregorianTime(earth);
            GPAstroData     day   = new GPAstroData();
            int             tithi;
            int             counter;
            GPGregorianTime start = new GPGregorianTime(earth), end = new GPGregorianTime(earth);
            //	SUNDATA sun;
            //	MOONDATA moon;
            double sunrise;

            start.setDayHours(-1.0);
            end.setDayHours(-1.0);
            start.Clear();
            end.Clear();

            /*	d = GetFirstDayOfYear(earth, nGYear + 1486);
             *  d.shour = 0.5;
             *  d.TimeZone = earth.tzone;
             */
            d.Copy(vcStart);

            i = 0;
            do
            {
                d.AddDays(13);
                day.calculateDayData(d, earth);
                day.nMasa         = day.determineMasa(d, out gy);
                day.nGaurabdaYear = gy;
                i++;
            }while (((day.nPaksa != nPaksa) || (day.nMasa != nMasa)) && (i <= 30));

            if (i >= 30)
            {
                d.Clear();
                endTithi = d;
                return(d);
            }

            // we found masa and paksa
            // now we have to find tithi
            tithi = nTithi + nPaksa * 15;

            if (day.nTithi == tithi)
            {
                // loc1
                // find tithi juncts in this day and according to that times,
                // look in previous or next day for end and start of this tithi
                nType = 1;
            }
            else
            {
                if (day.nTithi < tithi)
                {
                    // do increment of date until nTithi == tithi
                    //   but if nTithi > tithi
                    //       then do decrement of date
                    counter = 0;
                    while (counter < 30)
                    {
                        d.NextDay();
                        day.calculateDayData(d, earth);
                        if (day.nTithi == tithi)
                        {
                            goto cont_2;
                        }
                        if ((day.nTithi < tithi) && (day.nPaksa != nPaksa))
                        {
                            d.PreviousDay();
                            goto cont_2;
                        }
                        if (day.nTithi > tithi)
                        {
                            d.PreviousDay();
                            goto cont_2;
                        }
                        counter++;
                    }
                    // somewhere is error
                    d.Clear();
                    nType = 0;
                }
                else
                {
                    // do decrement of date until nTithi <= tithi
                    counter = 0;
                    while (counter < 30)
                    {
                        d.PreviousDay();
                        day.calculateDayData(d, earth);
                        if (day.nTithi == tithi)
                        {
                            goto cont_2;
                        }
                        if ((day.nTithi > tithi) && (day.nPaksa != nPaksa))
                        {
                            goto cont_2;
                        }
                        if (day.nTithi < tithi)
                        {
                            goto cont_2;
                        }
                        counter++;
                    }
                    // somewhere is error
                    d.Clear();
                    nType = 0;
                }
cont_2:
                if (day.nTithi == tithi)
                {
                    // do the same as in loc1
                    nType = 1;
                }
                else
                {
                    // nTithi != tithi and nTithi < tithi
                    // but on next day is nTithi > tithi
                    // that means we will find start and the end of tithi
                    // in this very day or on next day before sunrise
                    nType = 2;
                }
            }

            // now we know the type of day-accurancy
            // nType = 0 means, that we dont found a day
            // nType = 1 means, we find day, when tithi was present at sunrise
            // nType = 2 means, we found day, when tithi started after sunrise
            //                  but ended before next sunrise
            //
            sunrise = day.sun.getSunriseDayHours() / 360 + day.sun.rise.getLocation().getTimeZoneOffsetHours() / 24;

            if (nType == 1)
            {
                GPGregorianTime d1, d2;
                d.setDayHours(sunrise);
                GetPrevTithiStart(d, out d1);
                //d = d1;
                //d.shour += 0.02;
                GetNextTithiStart(d, out d2);

                endTithi = d2;
                return(d1);
            }
            else if (nType == 2)
            {
                GPGregorianTime d1, d2;
                d.setDayHours(sunrise);
                GetNextTithiStart(d, out d1);
                d.Copy(d1);
                d.addDayHours(0.1);
                GetNextTithiStart(d, out d2);

                endTithi = d2;
                return(d1);
            }

            // if nType == 0, then this algoritmus has some failure
            if (nType == 0)
            {
                d.Clear();
                d.setDayHours(0.0);
                endTithi = d;
            }
            else
            {
                d.Copy(start);
                endTithi = end;
            }

            return(d);
        }
Exemplo n.º 9
0
        /*********************************************************************/
        /*  Calculates Date of given Tithi                                   */
        /*********************************************************************/

        public static GPGregorianTime CalcTithiDate(int nGYear, int nMasa, int nPaksa, int nTithi, GPLocationProvider earth)
        {
            int             i = 0, gy = 0;
            GPGregorianTime d       = new GPGregorianTime(earth);
            GPAstroData     day     = new GPAstroData();
            int             tithi   = 0;
            int             counter = 0;
            uint            tmp     = 0;

            if (nGYear >= 464 && nGYear < 572)
            {
                tmp = GPGaurabdaYear.gGaurBeg[(nGYear - 464) * 26 + nMasa * 2 + nPaksa];
                d.setDate(Convert.ToInt32(tmp & 0xfffc00) >> 10,
                          Convert.ToInt32(tmp & 0x3e0) >> 5,
                          Convert.ToInt32(tmp & 0x1f));
                d.NextDay();

                day.calculateDayData(d, earth);
                day.nMasa         = day.determineMasa(d, out gy);
                day.nGaurabdaYear = gy;
            }
            else
            {
                //d = GetFirstDayOfYear(earth, nGYear + 1486);
                d.setDate(nGYear + 1486, 2 + nMasa, 15);
                if (d.getMonth() > 12)
                {
                    d.setDate(d.getYear() + 1, d.getMonth() - 12, 0);
                }
                d.setDayHours(0.5);

                i = 0;
                do
                {
                    d.AddDays(13);
                    day.calculateDayData(d, earth);
                    day.nMasa         = day.determineMasa(d, out gy);
                    day.nGaurabdaYear = gy;
                    i++;
                }while (((day.nPaksa != nPaksa) || (day.nMasa != nMasa)) && (i <= 30));
            }

            if (i >= 30)
            {
                d.Clear();
                return(d);
            }

            // we found masa and paksa
            // now we have to find tithi
            tithi = nTithi + nPaksa * 15;

            if (day.nTithi == tithi)
            {
                // loc1
                // find tithi juncts in this day and according to that times,
                // look in previous or next day for end and start of this tithi
                d.PreviousDay();
                day.calculateDayData(d, earth);
                if ((day.nTithi > tithi) && (day.nPaksa != nPaksa))
                {
                    d.NextDay();
                }
                return(d);
            }

            if (day.nTithi < tithi)
            {
                // do increment of date until nTithi == tithi
                //   but if nTithi > tithi
                //       then do decrement of date
                counter = 0;
                while (counter < 16)
                {
                    d.NextDay();
                    day.calculateDayData(d, earth);
                    if (day.nTithi == tithi)
                    {
                        return(d);
                    }
                    if ((day.nTithi < tithi) && (day.nPaksa != nPaksa))
                    {
                        return(d);
                    }
                    if (day.nTithi > tithi)
                    {
                        return(d);
                    }
                    counter++;
                }
                // somewhere is error
                d.Clear();
                return(d);
            }
            else
            {
                // do decrement of date until nTithi <= tithi
                counter = 0;
                while (counter < 16)
                {
                    d.PreviousDay();
                    day.calculateDayData(d, earth);
                    if (day.nTithi == tithi)
                    {
                        return(d);
                    }
                    if ((day.nTithi > tithi) && (day.nPaksa != nPaksa))
                    {
                        d.NextDay();
                        return(d);
                    }
                    if (day.nTithi < tithi)
                    {
                        d.NextDay();
                        return(d);
                    }
                    counter++;
                }
                // somewhere is error
                d.Clear();
                return(d);
            }

            // now we know the type of day-accurancy
            // nType = 0 means, that we dont found a day
            // nType = 1 means, we find day, when tithi was present at sunrise
            // nType = 2 means, we found day, when tithi started after sunrise
            //                  but ended before next sunrise
            //
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        public int CalcMasaList(GPLocationProvider loc, int nYear, int nCount)
        {
            GPMasaListResults mlist = this;
            GPAstroData       day   = new GPAstroData();
            GPGregorianTime   d     = new GPGregorianTime(loc);
            GPGregorianTime   de    = new GPGregorianTime(loc);
            GPGregorianTime   t     = new GPGregorianTime(loc);

            vc_end   = new GPGregorianTime(loc);
            vc_start = new GPGregorianTime(loc);
            int lm = -1;

            mlist.n_startYear  = nYear;
            mlist.n_countYears = nCount;
            d.Copy(GPGaurabdaYear.getFirstDayOfYear(loc, nYear));
            de.Copy(GPGaurabdaYear.getFirstDayOfYear(loc, nYear + nCount));
            mlist.vc_start.Copy(d);
            mlist.vc_end.Copy(de);
            mlist.m_location = loc;

            alloc(nCount);

            int i          = 0;
            int prev_paksa = -1;
            int current    = 0;


            while (d.IsBeforeThis(de))
            {
                day.calculateDayData(d, loc);
                if (prev_paksa != day.nPaksa)
                {
                    day.nMasa = day.determineMasa(d, out day.nGaurabdaYear);

                    if (lm != day.nMasa)
                    {
                        if (lm >= 0)
                        {
                            t.Copy(d);
                            t.PreviousDay();
                            mlist.arr[current].vc_end.Copy(t);
                            current++;
                        }
                        lm = day.nMasa;
                        mlist.arr[current].masa = day.nMasa;
                        mlist.arr[current].year = day.nGaurabdaYear;
                        mlist.arr[current].vc_start.Copy(d);
                    }
                }
                prev_paksa = day.nPaksa;
                d.NextDay();
                i++;
            }

            t.Copy(d);
            mlist.arr[current].vc_end.Copy(t);
            current++;
            mlist.n_countMasa = current;

            return(1);
        }
Exemplo n.º 12
0
        public static int WriteXML_GaurabdaNextTithi(StringBuilder doc, GPLocationProvider loc, GPGregorianTime vcStart, GPVedicTime vaStart)
        {
            int gmasa, gpaksa, gtithi;


            gmasa  = vaStart.masa;
            gpaksa = vaStart.tithi / 15;
            gtithi = vaStart.tithi % 15;

            doc.Append("<xml>\n");
            doc.Append("\t<request name=\"Tithi\" version=\"" + GPFileHelper.FileVersion + "\">\n");
            doc.Append("\t\t<arg name=\"longitude\" val=\"" + loc.GetLongitudeEastPositive() + "\" />\n");
            doc.Append("\t\t<arg name=\"latitude\" val=\"" + loc.GetLatitudeNorthPositive() + "\" />\n");
            doc.Append("\t\t<arg name=\"timezone\" val=\"" + loc.getTimeZone().OffsetSeconds / 60 + "\" />\n");
            doc.Append("\t\t<arg name=\"start date\" val=\"" + vcStart + "\" />\n");
            doc.Append("\t\t<arg name=\"masa\" val=\"" + gmasa + "\" />\n");
            doc.Append("\t\t<arg name=\"paksa\" val=\"" + gpaksa + "\" />\n");
            doc.Append("\t\t<arg name=\"tithi\" val=\"" + gtithi + "\" />\n");
            doc.Append("\t</request>\n");
            doc.Append("\t<result name=\"Tithi\">\n");

            GPGregorianTime vcs   = new GPGregorianTime(loc);
            GPGregorianTime vce   = new GPGregorianTime(loc);
            GPGregorianTime today = new GPGregorianTime(loc);
            GPSun           sun   = new GPSun();
            int             A;
            double          sunrise;
            GPAstroData     day = new GPAstroData();
            int             oTithi, oPaksa, oMasa, oYear;

            today.Copy(vcStart);
            today.PreviousDay();
            vcStart.SubDays(15);
            for (A = 0; A <= 3; A++)
            {
                vcs = GPTithi.CalcTithiEndEx(vcStart, 0, gmasa, gpaksa, gtithi, loc, out vce);
                if (!vcs.IsBeforeThis(today))
                {
                    oTithi = gpaksa * 15 + gtithi;
                    oMasa  = gmasa;
                    oPaksa = gpaksa;
                    oYear  = 0;
                    doc.Append("\t<celebration\n");
                    //		doc.Append( "\t\t<tithi\n");
                    doc.Append("\t\trtithi=\"" + GPTithi.getName(oTithi) + "\"\n");
                    doc.Append("\t\trmasa=\"" + GPMasa.GetName(oMasa) + "\"\n");
                    doc.Append("\t\trpaksa=\"" + GPPaksa.getName(oPaksa) + "\"\n");
                    // test ci je ksaya
                    today.Copy(vcs);
                    today.setDayHours(0.5);
                    sun.SunCalc(today, loc);
                    sunrise = sun.getSunriseDayHours();
                    if (sunrise < vcs.getDayHours())
                    {
                        today.Copy(vce);
                        sun.SunCalc(today, loc);
                        sunrise = sun.getSunriseDayHours();
                        if (sunrise < vce.getDayHours())
                        {
                            // normal type
                            vcs.NextDay();
                            doc.Append("\t\ttype=\"normal\"\n");
                        }
                        else
                        {
                            // ksaya
                            vcs.NextDay();
                            day.calculateDayData(vcs, loc);
                            oTithi = day.nTithi;
                            oPaksa = day.nPaksa;
                            oMasa  = day.determineMasa(vcs, out oYear);
                            doc.Append("\t\ttype=\"ksaya\"\n");
                        }
                    }
                    else
                    {
                        // normal, alebo prvy den vriddhi
                        today.Copy(vce);
                        sun.SunCalc(today, loc);
                        if (sun.getSunriseDayHours() < vce.getDayHours())
                        {
                            // first day of vriddhi type
                            doc.Append("\t\ttype=\"vriddhi\"\n");
                        }
                        else
                        {
                            // normal
                            doc.Append("\t\ttype=\"normal\"\n");
                        }
                    }
                    doc.Append("\t\tdate=\"" + vcs + "\"\n");
                    doc.Append("\t\totithi=\"" + GPTithi.getName(oTithi) + "\"\n");
                    doc.Append("\t\tomasa=\"" + GPMasa.GetName(oMasa) + "\"\n");
                    doc.Append("\t\topaksa=\"" + GPPaksa.getName(oPaksa) + "\"\n");
                    doc.Append("\t/>\n");
                    break;
                }
                else
                {
                    vcStart.Copy(vcs);
                    vcs.NextDay();
                }
            }

            doc.Append("\t</result>\n");
            doc.Append("</xml>\n");


            return(1);
        }