Beispiel #1
0
        public static int GetNextYogaStart(GCEarthData ed, GregorianDateTime startDate, out GregorianDateTime nextDate)
        {
            double            phi = 40.0 / 3.0;
            double            l1, l2, longitudeSun;
            double            jday = startDate.GetJulianComplete();
            double            xj;
            double            longitudeMoon;
            GregorianDateTime d = new GregorianDateTime();

            d.Set(startDate);
            GregorianDateTime xd        = new GregorianDateTime();
            double            scan_step = 0.5;
            int    prev_tit             = 0;
            int    new_tit   = -1;
            double ayanamsha = GCAyanamsha.GetAyanamsa(jday);

            longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, ed);
            longitudeSun  = GCCoreAstronomy.GetSunLongitude(d, ed);
            l1            = GCMath.putIn360(longitudeMoon + longitudeSun - 2 * ayanamsha);
            prev_tit      = Convert.ToInt32(Math.Floor(l1 / phi));

            int counter = 0;

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

                jday    += scan_step;
                d.shour += scan_step;
                if (d.shour > 1.0)
                {
                    d.shour -= 1.0;
                    d.NextDay();
                }

                longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, ed);
                longitudeSun  = GCCoreAstronomy.GetSunLongitude(d, ed);
                l2            = GCMath.putIn360(longitudeMoon + longitudeSun - 2 * ayanamsha);
                new_tit       = Convert.ToInt32(Math.Floor(l2 / phi));

                if (prev_tit != new_tit)
                {
                    jday = xj;
                    d.Set(xd);
                    scan_step *= 0.5;
                    counter++;
                    continue;
                }
                else
                {
                    l1 = l2;
                }
            }
            nextDate = d;

            return(new_tit);
        }
Beispiel #2
0
        /*********************************************************************/
        /*                                                                   */
        /*   finds previous time when starts next tithi                      */
        /*                                                                   */
        /*   timezone is not changed                                         */
        /*                                                                   */
        /*   return value: index of tithi 0..29                              */
        /*                 or -1 if failed                                   */
        /*********************************************************************/

        public static int GetPrevTithiStart(GCEarthData ed, GregorianDateTime startDate, out GregorianDateTime nextDate)
        {
            double            phi = 12.0;
            double            l1, l2, longitudeSun, longitudeMoon;
            double            jday = startDate.GetJulianComplete();
            double            xj;
            GregorianDateTime d = new GregorianDateTime();

            d.Set(startDate);
            GregorianDateTime xd        = new GregorianDateTime();
            double            scan_step = 0.5;
            int prev_tit = 0;
            int new_tit  = -1;

            longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, ed);
            longitudeSun  = GCCoreAstronomy.GetSunLongitude(d, ed);
            l1            = GCMath.putIn360(longitudeMoon - longitudeSun - 180.0);
            prev_tit      = GCMath.IntFloor(l1 / phi);

            int counter = 0;

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

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

                longitudeSun  = GCCoreAstronomy.GetSunLongitude(d, ed);
                longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, ed);
                l2            = GCMath.putIn360(longitudeMoon - longitudeSun - 180.0);
                new_tit       = GCMath.IntFloor(l2 / phi);

                if (prev_tit != new_tit)
                {
                    jday = xj;
                    d.Set(xd);
                    scan_step *= 0.5;
                    counter++;
                    continue;
                }
                else
                {
                    l1 = l2;
                }
            }
            nextDate = d;
            //	nextDate.shour += startDate.tzone / 24.0;
            //	nextDate.NormalizeValues();
            return(new_tit);
        }
Beispiel #3
0
        public static int GetNextMoonRasi(GCEarthData ed, GregorianDateTime startDate, out GregorianDateTime nextDate)
        {
            double            phi = 30.0;
            double            l1, l2, longitudeMoon;
            double            jday = startDate.GetJulianComplete();
            GregorianDateTime d    = new GregorianDateTime();

            d.Set(startDate);
            double ayanamsa  = GCAyanamsha.GetAyanamsa(jday);
            double scan_step = 0.5;
            int    prev_naks = 0;
            int    new_naks  = -1;

            double            xj;
            GregorianDateTime xd = new GregorianDateTime();

            longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, ed);
            l1            = GCMath.putIn360(longitudeMoon - ayanamsa);
            prev_naks     = GCMath.IntFloor(l1 / phi);

            int counter = 0;

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

                jday    += scan_step;
                d.shour += scan_step;
                if (d.shour > 1.0)
                {
                    d.shour -= 1.0;
                    d.NextDay();
                }

                longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, ed);
                l2            = GCMath.putIn360(longitudeMoon - ayanamsa);
                new_naks      = GCMath.IntFloor(l2 / phi);
                if (prev_naks != new_naks)
                {
                    jday = xj;
                    d.Set(xd);
                    scan_step *= 0.5;
                    counter++;
                    continue;
                }
                else
                {
                    l1 = l2;
                }
            }
            nextDate = new GregorianDateTime();
            nextDate.Set(d);
            return(new_naks);
        }
Beispiel #4
0
        /*********************************************************************/
        /*  Finds next time when rasi is changed                             */
        /*                                                                   */
        /*  startDate - starting date and time, timezone member must be valid */
        /*  zodiac [out] - found zodiac sign into which is changed           */
        /*                                                                   */
        /*********************************************************************/

        public static GregorianDateTime GetNextSankranti(GregorianDateTime startDate, GCEarthData earth, out int zodiac)
        {
            GregorianDateTime d = new GregorianDateTime();
            double            step = 1.0;
            int               count = 0;
            double            ld, prev;
            int               prev_rasi, new_rasi;
            GregorianDateTime prevday;

            d.Set(startDate);
            //d.ChangeTimeZone(0.0);
            //d.shour = 0.0;
            zodiac = 0;

            prev      = GCMath.putIn360(GCCoreAstronomy.GetSunLongitude(d, earth) - GCAyanamsha.GetAyanamsa(d.GetJulian()));
            prev_rasi = GCMath.IntFloor(prev / 30.0);

            while (count < 20)
            {
                prevday = new GregorianDateTime();
                prevday.Set(d);
                d.shour += step;
                if (d.shour > 1.0)
                {
                    d.shour -= 1.0;
                    d.NextDay();
                }

                ld       = GCMath.putIn360(GCCoreAstronomy.GetSunLongitude(d, earth) - GCAyanamsha.GetAyanamsa(d.GetJulian()));
                new_rasi = GCMath.IntFloor(ld / 30.0);

                if (prev_rasi != new_rasi)
                {
                    zodiac = new_rasi;
                    //v uplynulom dni je sankranti
                    step *= 0.5;
                    d.Set(prevday);
                    count++;
                    continue;
                }
            }

            return(d);
        }
Beispiel #5
0
        /*********************************************************************/
        /*                                                                   */
        /* Calculation of tithi, paksa, naksatra, yoga for given             */
        /*    Gregorian date                                                 */
        /*                                                                   */
        /*                                                                   */
        /*********************************************************************/

        public int DayCalc(GregorianDateTime date, GCEarthData earth)
        {
            double d;

            // sun position on sunrise on that day
            sunRise = GCSunData.CalcSunrise(date, earth);
            sunSet  = GCSunData.CalcSunset(date, earth);

            // arunodaya is 96 min before sunrise
            //  sunrise_deg is from range 0-360 so 96min=24deg
            sunArunodaya.TotalDays = sunRise.TotalDays - 96 / 1440.0;
            sunArunodaya.longitude = sunRise.longitude - (24.0 / 365.25);
            // noon
            sunNoon.TotalDays = (sunSet.TotalDays + sunRise.TotalDays) / 2;
            sunNoon.longitude = (sunRise.longitude + sunSet.longitude) / 2;

            date.shour = sunRise.TotalDays;

            // date.shour is [0..1] time of sunrise in local timezone time
            this.JulianDay = date.GetJulianDetailed();

            // moon position at sunrise on that day
            sunRise.longitudeMoon = GCCoreAstronomy.GetMoonLongitude(date, earth);

            this.Ayanamsa         = GCAyanamsha.GetAyanamsa(this.JulianDay);
            sunArunodaya.Ayanamsa = this.Ayanamsa;
            sunRise.Ayanamsa      = this.Ayanamsa;
            sunNoon.Ayanamsa      = this.Ayanamsa;
            sunSet.Ayanamsa       = this.Ayanamsa;

            // masa
            this.Masa = -1;

            date.shour           = sunSet.TotalDays;
            sunSet.longitudeMoon = GCCoreAstronomy.GetMoonLongitude(date, earth);


            date.shour = sunArunodaya.TotalDays;
            sunArunodaya.longitudeMoon = GCCoreAstronomy.GetMoonLongitude(date, earth);


            return(1);
        }
Beispiel #6
0
        //==================================================================================
        //
        //==================================================================================

        public static GregorianDateTime GetNextRise(GCEarthData e, GregorianDateTime vc, bool bRise)
        {
            double a, b;

            double[] h         = new double[3];
            double   hour      = 1 / 24.0;
            double   startHour = vc.shour;

            GregorianDateTime track = new GregorianDateTime();

            track.Set(vc);
            track.NormalizeValues();

            // inicializacia prvej hodnoty ELEVATION
            h[0]         = GCCoreAstronomy.GetMoonElevation(e, track);
            track.shour += hour;
            h[1]         = GCCoreAstronomy.GetMoonElevation(e, track);
            track.shour += hour;
            h[2]         = GCCoreAstronomy.GetMoonElevation(e, track);

            for (int c = 0; c < 24; c++)
            {
                if ((bRise ? (h[1] < 0.0 && h[2] > 0.0) : (h[1] > 0.0 && h[2] < 0.0)))
                {
                    a           = (h[2] - h[1]) / hour;
                    b           = h[2] - a * track.shour;
                    track.shour = -b / a;
                    track.NormalizeValues();
                    return(track);
                }

                h[0]         = h[1];
                h[1]         = h[2];
                track.shour += hour;
                h[2]         = GCCoreAstronomy.GetMoonElevation(e, track);
            }

            return(track);
        }
Beispiel #7
0
        /// <summary>
        /// Main function for CALENDAR calculations
        /// </summary>
        /// <param name="loc"></param>
        /// <param name="begDate"></param>
        /// <param name="iCount"></param>
        /// <returns></returns>
        public int CalculateCalendar(GCLocation loc, GregorianDateTime begDate, int iCount)
        {
            int i, weekday;
            int nTotalCount = BEFORE_DAYS + iCount + BEFORE_DAYS;
            GregorianDateTime date;
            GCEarthData       earth;
            int    lastMasa  = 0;
            int    lastGYear = 0;
            String tempStr;
            bool   bCalcMoon = (GCDisplaySettings.Current.getValue(4) > 0 || GCDisplaySettings.Current.getValue(5) > 0);

            m_nCount   = 0;
            m_Location = loc;
            m_vcStart  = new GregorianDateTime(begDate);
            m_vcCount  = iCount;
            earth      = loc.GetEarthData();

            // alokacia pola
            m_pData = new VAISNAVADAY[nTotalCount];

            // inicializacia poctovych premennych
            m_nCount    = nTotalCount;
            m_PureCount = iCount;

            date = new GregorianDateTime();
            date.Set(begDate);
            date.shour         = 0.0;
            date.TimezoneHours = loc.OffsetUtcHours;
            date.SubtractDays(BEFORE_DAYS);
            date.InitWeekDay();

            weekday = date.dayOfWeek;

            GCFestivalSpecialExecutor exec = new GCFestivalSpecialExecutor(this);

            long utcDayStart = -1;
            long utcDayEnd   = -1;

            // 1
            // initialization of days
            for (i = 0; i < nTotalCount; i++)
            {
                m_pData[i]                = new VAISNAVADAY();
                m_pData[i].date           = new GregorianDateTime(date);
                m_pData[i].date.dayOfWeek = weekday;
                date.NextDay();
                weekday = (weekday + 1) % 7;
                m_pData[i].moonrise.SetValue(-1);
                m_pData[i].moonset.SetValue(-1);

                if (utcDayStart < 0)
                {
                    utcDayStart = Convert.ToInt64(m_pData[i].date.GetJulianComplete() * 86400);
                }
                m_pData[i].UtcDayStart = utcDayStart;
                utcDayStart           += 86400;
            }

            for (i = 0; i < nTotalCount; i++)
            {
                m_pData[i].Previous = i > 0 ? m_pData[i - 1] : null;
                m_pData[i].Next     = i < nTotalCount - 1 ? m_pData[i + 1] : null;
            }

            TResultCoreEvents recentEvents = null;

            // 2
            // calculating DST data and core events
            foreach (VAISNAVADAY t in m_pData)
            {
                t.BiasMinutes = loc.TimeZone.GetBiasMinutesForDay(t.date);
                if (t.Previous != null)
                {
                    t.DstDayType = (t.BiasMinutes == 0
                        ? (t.Previous.BiasMinutes == 0 ? DstTypeChange.DstOff : DstTypeChange.DstEnd)
                        : (t.Previous.BiasMinutes == 0 ? DstTypeChange.DstStart : DstTypeChange.DstOn));
                }

                utcDayStart = t.UtcDayStart - (t.Previous != null ? t.Previous.BiasMinutes * 60 : 0);
                utcDayEnd   = t.UtcDayStart + 86400 - t.BiasMinutes * 60;

                if (recentEvents == null || recentEvents.p_events.Count == 0 || recentEvents.Year != t.date.year)
                {
                    recentEvents = GCCoreAstronomy.GetCoreEventsYear(loc, t.date.year);
                }
                recentEvents.GetCoreEvents(t.coreEvents, utcDayStart, utcDayEnd);


                utcDayStart = utcDayEnd;
            }

            // 3
            if (bCalcMoon)
            {
                foreach (VAISNAVADAY t in m_pData)
                {
                    GCMoonData.CalcMoonTimes(earth, t.date, Convert.ToDouble(t.BiasMinutes / 60.0), out t.moonrise, out t.moonset);

                    if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_MOON_RISE) != 0 && t.moonrise.hour >= 0)
                    {
                        tempStr = t.Format(GCStrings.Localized("Moonrise {moonRiseTime} ({dstSig})"));
                        t.AddEvent(DisplayPriorities.PRIO_MOON, GCDS.CAL_MOON_RISE, tempStr);
                    }

                    if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_MOON_SET) != 0 && t.moonset.hour >= 0)
                    {
                        tempStr = t.Format(GCStrings.Localized("Moonset {moonSetTime} ({dstSig})"));
                        t.AddEvent(DisplayPriorities.PRIO_MOON, GCDS.CAL_MOON_SET, tempStr);
                    }
                }
            }

            // 4
            // init of astro data
            foreach (VAISNAVADAY t in m_pData)
            {
                t.astrodata = new GCAstroData();
                t.astrodata.DayCalc(t.date, earth);

                t.coreEvents.InsertByTime(new TCoreEvent()
                {
                    Time  = t.UtcDayStart + (long)t.astrodata.sunArunodaya.TotalSeconds,
                    nType = CoreEventType.CCTYPE_S_ARUN
                });
                t.coreEvents.InsertByTime(new TCoreEvent()
                {
                    Time  = t.UtcDayStart + (long)t.astrodata.sunRise.TotalSeconds,
                    nType = CoreEventType.CCTYPE_S_RISE
                });
                t.coreEvents.InsertByTime(new TCoreEvent()
                {
                    Time  = t.UtcDayStart + (long)t.astrodata.sunNoon.TotalSeconds,
                    nType = CoreEventType.CCTYPE_S_NOON
                });
                t.coreEvents.InsertByTime(new TCoreEvent()
                {
                    Time  = t.UtcDayStart + (long)t.astrodata.sunSet.TotalSeconds,
                    nType = CoreEventType.CCTYPE_S_SET
                });
            }

            // 5
            // init of masa
            foreach (VAISNAVADAY t in m_pData)
            {
                if (t.Previous == null ||
                    t.astrodata.sunRise.Paksa != t.Previous.astrodata.sunRise.Paksa)
                {
                    t.astrodata.MasaCalc(t.date, earth);
                    lastMasa  = t.astrodata.Masa;
                    lastGYear = t.astrodata.GaurabdaYear;
                }
                t.astrodata.Masa         = lastMasa;
                t.astrodata.GaurabdaYear = lastGYear;

                if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_SUN_LONG) != 0)
                {
                    tempStr = string.Format("{0}: {1} (*)", GCStrings.Localized("Sun Longitude")
                                            , t.astrodata.sunRise.longitude);
                    t.AddEvent(DisplayPriorities.PRIO_ASTRO, GCDS.CAL_SUN_LONG, tempStr);
                }

                if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_MOON_LONG) != 0)
                {
                    tempStr = string.Format("{0}: {1} (*)", GCStrings.Localized("Moon Longitude")
                                            , t.astrodata.sunRise.longitudeMoon);
                    t.AddEvent(DisplayPriorities.PRIO_ASTRO, GCDS.CAL_MOON_LONG, tempStr);
                }

                if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_AYANAMSHA) != 0)
                {
                    tempStr = string.Format("{0} {1} ({2}) (*)", GCStrings.Localized("Ayanamsha")
                                            , t.astrodata.Ayanamsa
                                            , GCAyanamsha.GetAyanamsaName(GCAyanamsha.GetAyanamsaType()));
                    t.AddEvent(DisplayPriorities.PRIO_ASTRO, GCDS.CAL_AYANAMSHA, tempStr);
                }

                if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_JULIAN) != 0)
                {
                    tempStr = string.Format("{0} {1} (*)", GCStrings.Localized("Julian Time")
                                            , t.astrodata.JulianDay);
                    t.AddEvent(DisplayPriorities.PRIO_ASTRO, GCDS.CAL_JULIAN, tempStr);
                }
            }


            if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_MASA_CHANGE) != 0)
            {
                String str;

                foreach (VAISNAVADAY t in m_pData)
                {
                    if (t.Previous != null && t.Previous.astrodata.Masa != t.astrodata.Masa)
                    {
                        str = t.Format(GCStrings.Localized("First day of {masaName} Masa"));
                        t.AddEvent(DisplayPriorities.PRIO_MASA_CHANGE, GCDS.CAL_MASA_CHANGE, str);
                    }

                    if (t.Next != null && t.Next.astrodata.Masa != t.astrodata.Masa)
                    {
                        str = t.Format(GCStrings.Localized("Last day of {masaName} Masa"));
                        t.AddEvent(DisplayPriorities.PRIO_MASA_CHANGE, GCDS.CAL_MASA_CHANGE, str);
                    }
                }
            }

            if (!EkadasiOnly && GCDisplaySettings.Current.getValue(GCDS.CAL_DST_CHANGE) != 0)
            {
                foreach (VAISNAVADAY t in m_pData)
                {
                    if (t.Previous != null && t.Previous.BiasMinutes == 0 && t.BiasMinutes != 0)
                    {
                        t.AddEvent(DisplayPriorities.PRIO_DST_CHANGE, GCDS.CAL_DST_CHANGE, GCStrings.Localized("First day of Daylight Saving Time"));
                    }
                    else if (t.Next != null && t.BiasMinutes != 0 && t.Next.BiasMinutes == 0)
                    {
                        t.AddEvent(DisplayPriorities.PRIO_DST_CHANGE, GCDS.CAL_DST_CHANGE, GCStrings.Localized("Last day of Daylight Saving Time"));
                    }
                }
            }

            // 6
            // init of mahadvadasis
            foreach (VAISNAVADAY t in m_pData)
            {
                t.MahadvadasiCalc(earth);
            }

            //
            // init for Ekadasis
            foreach (VAISNAVADAY t in m_pData)
            {
                if (t.Previous == null)
                {
                    continue;
                }
                t.EkadasiCalc(earth);
                if (t.Previous.nFastID == FastType.FAST_EKADASI)
                {
                    t.CalculateEParana(earth);
                }
            }

            if (EkadasiOnly)
            {
                return(1);
            }

            // init ksaya data
            // init of second day of vriddhi
            CalculateKsayaVriddhiTithis();

            //
            // calculate sankrantis
            CalculateSankrantis();

            // 7
            // init of festivals
            AddMatchedFestivals(exec);

            //
            // apply daylight saving time
            ApplyDaylightSavingHours();

            //
            // resolve festivals fasting
            for (i = BEFORE_DAYS; i < m_PureCount + BEFORE_DAYS; i++)
            {
                ResolveFestivalsFasting(i);

                if (GCDisplaySettings.Current.getValue(GCDS.CAL_SUN_RISE) != 0)
                {
                    tempStr = string.Format("{0}-{1}-{2}  {3} - {4} - {5} ({6})",
                                            GCStrings.Localized("Sunrise"),
                                            GCStrings.Localized("Noon"),
                                            GCStrings.Localized("Sunset"),
                                            m_pData[i].astrodata.sunRise.ToShortTimeString(),
                                            m_pData[i].astrodata.sunNoon.ToShortTimeString(),
                                            m_pData[i].astrodata.sunSet.ToShortTimeString(),
                                            GCStrings.GetDSTSignature(m_pData[i].BiasMinutes));
                    m_pData[i].AddEvent(DisplayPriorities.PRIO_SUN, GCDS.CAL_SUN_RISE, tempStr);
                }

                if (GCDisplaySettings.Current.getValue(GCDS.CAL_SUN_SANDHYA) != 0)
                {
                    tempStr = string.Format("{0}: {1} | {2} | {3}   ({4})",
                                            GCStrings.Localized("Sandhyas"),
                                            m_pData[i].astrodata.sunRise.ShortSandhyaString(),
                                            m_pData[i].astrodata.sunNoon.ShortSandhyaString(),
                                            m_pData[i].astrodata.sunSet.ShortSandhyaString(),
                                            GCStrings.GetDSTSignature(m_pData[i].BiasMinutes));
                    m_pData[i].AddEvent(DisplayPriorities.PRIO_SUN, GCDS.CAL_SUN_SANDHYA, tempStr);
                }

                if (GCDisplaySettings.Current.getValue(GCDS.CAL_BRAHMA_MUHURTA) != 0)
                {
                    tempStr = string.Format("{0}: {1}   ({2})",
                                            GCStrings.Localized("Brahma Muhurta"),
                                            m_pData[i].astrodata.sunRise.ShortMuhurtaString(-2),
                                            GCStrings.GetDSTSignature(m_pData[i].BiasMinutes));
                    m_pData[i].AddEvent(DisplayPriorities.PRIO_SUN, GCDS.CAL_BRAHMA_MUHURTA, tempStr);
                }
            }

            if (GCDisplaySettings.Current.getValue(GCDS.CAL_COREEVENTS) != 0)
            {
                int number = 1;
                foreach (VAISNAVADAY today in m_pData)
                {
                    foreach (TCoreEvent tde in today.coreEvents)
                    {
                        m_pData[i].AddEvent(DisplayPriorities.PRIO_ASTRO + number, GCDS.CAL_COREEVENTS,
                                            tde.TypeString + "   " + today.GetCoreEventTime(tde));
                        number++;
                    }
                }
            }


            // sorting day events according priority
            VAISNAVAEVENTComparer vec = new VAISNAVAEVENTComparer();

            foreach (VAISNAVADAY t in m_pData)
            {
                t.dayEvents.Sort(vec);
            }


            return(1);
        }
Beispiel #8
0
        //==================================================================================
        //
        //==================================================================================

        public static void CalcMoonTimes(GCEarthData e, GregorianDateTime vc, double biasHours, out GCHourTime rise, out GCHourTime set)
        {
            double UT;
            int    i;
            double prev_elev;
            int    nType, nFound = 0;
            double a, ae, b, be, c = 0, ce = 0, elev;

            rise = new GCHourTime();
            set  = new GCHourTime();

            rise.SetValue(-1);
            set.SetValue(-1);

            // inicializacia prvej hodnoty ELEVATION
            vc.shour  = (-biasHours - 1.0) / 24.0;
            prev_elev = GCCoreAstronomy.GetMoonElevation(e, vc);

            // prechod cez vsetky hodiny
            for (UT = (-0.1 - biasHours); UT <= (24.1 - biasHours); UT += 1.0)
            {
                vc.shour = UT / 24.0;
                elev     = GCCoreAstronomy.GetMoonElevation(e, vc);

                if (prev_elev * elev <= 0.0)
                {
                    if (prev_elev <= 0.0)
                    {
                        nType = 0x1;
                    }
                    else
                    {
                        nType = 0x2;
                    }

                    a  = UT - 1.0;
                    ae = prev_elev;
                    b  = UT;
                    be = elev;
                    for (i = 0; i < 20; i++)
                    {
                        c        = (a + b) / 2.0;
                        vc.shour = c / 24.0;
                        ce       = GCCoreAstronomy.GetMoonElevation(e, vc);
                        if (ae * ce <= 0.0)
                        {
                            be = ce;
                            b  = c;
                        }
                        else
                        {
                            ae = ce;
                            a  = c;
                        }
                    }

                    if (nType == 1)
                    {
                        rise.SetDayTime((c + biasHours) / 24.0);
                    }
                    else
                    {
                        set.SetDayTime((c + biasHours) / 24.0);
                    }

                    nFound |= nType;

                    if (nFound == 0x3)
                    {
                        break;
                    }
                }

                prev_elev = elev;
            }
        }
Beispiel #9
0
        ///////////////////////////////////////////////////////////////////////
        // GET PREVIOUS CONJUNCTION OF THE SUN AND MOON
        //
        // THIS IS HELP FUNCTION FOR GetPrevConjunction(VCTIME test_date,
        //                                         VCTIME &found, bool this_day, EARTHDATA earth)
        //
        // looking for previous sun-moon conjunction
        // it starts from input day from 12:00 AM (noon) UTC
        // so output can be the same day
        // if output is the same day, then conjunction occurs between 00:00 AM and noon of this day
        //
        // date - input / output
        // earth - input
        // return value - sun longitude in degs
        //
        // error is when return value is greater than 999.0 deg

        public static double GetPrevConjunction(ref GregorianDateTime date, GCEarthData earth)
        {
            int    bCont = 32;
            double prevSun = 0.0, prevMoon = 0.0, prevDiff = 0.0;
            double nowSun = 0.0, nowMoon = 0.0, nowDiff = 0.0;
            //	SUNDATA sun;
            double            jd, longitudeMoon;
            GregorianDateTime d = new GregorianDateTime();

            d.Set(date);
            d.shour         = 0.5;
            d.TimezoneHours = 0.0;
            jd = d.GetJulian();//GetJulianDay(d.year, d.month, d.day);

            // set initial data for input day
            // NOTE: for grenwich
            //SunPosition(d, earth, sun);
            longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, earth);
            prevSun       = GCSunData.GetSunLongitude(d);
            prevMoon      = longitudeMoon;
            prevDiff      = GCMath.putIn180(prevSun - prevMoon);

            do
            {
                // shift to day before
                d.PreviousDay();
                jd -= 1.0;
                // calculation
                //SunPosition(d, earth, sun);
                longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, earth);
                nowSun        = GCSunData.GetSunLongitude(d);
                nowMoon       = longitudeMoon;
                nowDiff       = GCMath.putIn180(nowSun - nowMoon);
                // if difference of previous has another sign than now calculated
                // then it is the case that moon was faster than sun and he
                //printf("        prevsun=%f\nprevmoon=%f\nnowsun=%f\nnowmoon=%f\n", prevSun, prevMoon, nowSun, nowMoon);


                if (IsConjunction(nowMoon, nowSun, prevSun, prevMoon))
                {
                    // now it calculates actual time and zodiac of conjunction
                    double x;
                    if (prevDiff == nowDiff)
                    {
                        return(0);
                    }
                    x = Math.Abs(nowDiff) / Math.Abs(prevDiff - nowDiff);
                    if (x < 0.5)
                    {
                        d.shour = x + 0.5;
                    }
                    else
                    {
                        d.NextDay();
                        d.shour = x - 0.5;
                    }
                    date.Set(d);
                    double other = GCSunData.GetSunLongitude(d);
                    //			double other2 = nowSun + (prevSun - nowSun)*x;
                    GCMath.putIn360(prevSun);
                    GCMath.putIn360(nowSun);
                    if (Math.Abs(prevSun - nowSun) > 10.0)
                    {
                        return(GCMath.putIn180(nowSun) + (GCMath.putIn180(prevSun) - GCMath.putIn180(nowSun)) * x);
                    }
                    else
                    {
                        return(nowSun + (prevSun - nowSun) * x);
                    }
                    //			return other2;
                }
                prevSun  = nowSun;
                prevMoon = nowMoon;
                prevDiff = nowDiff;
                bCont--;
            }while (bCont >= 0);

            return(1000.0);
        }
Beispiel #10
0
        /*********************************************************************/
        /*                                                                   */
        /*                                                                   */
        /*                                                                   */
        /*                                                                   */
        /*                                                                   */
        /*********************************************************************/

        public static double GetNextConjunction(GregorianDateTime test_date, out GregorianDateTime found, bool this_conj, GCEarthData earth)
        {
            double phi = 12.0;
            double l1, l2, longitudeSun, longitudeMoon;

            if (this_conj)
            {
                test_date.shour += 0.2;
                test_date.NormalizeValues();
            }


            double            jday = test_date.GetJulianComplete();
            double            xj;
            GregorianDateTime d = new GregorianDateTime();

            d.Set(test_date);
            GregorianDateTime xd        = new GregorianDateTime();
            double            scan_step = 1.0;
            int prev_tit = 0;
            int new_tit  = -1;

            longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, earth);
            longitudeSun  = GCSunData.GetSunLongitude(d);
            l1            = GCMath.putIn180(longitudeMoon - longitudeSun);
            prev_tit      = GCMath.IntFloor(l1 / phi);

            int counter = 0;

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

                jday    += scan_step;
                d.shour += scan_step;
                if (d.shour > 1.0)
                {
                    d.shour -= 1.0;
                    d.NextDay();
                }

                longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, earth);
                longitudeSun  = GCSunData.GetSunLongitude(d);
                l2            = GCMath.putIn180(longitudeMoon - longitudeSun);
                new_tit       = GCMath.IntFloor(l2 / phi);

                if (prev_tit < 0 && new_tit >= 0)
                {
                    jday = xj;
                    d.Set(xd);
                    scan_step *= 0.5;
                    counter++;
                    continue;
                }
                else
                {
                    l1 = l2;
                }

                prev_tit = new_tit;
            }
            found = new GregorianDateTime();
            found.Set(d);
            return(longitudeSun);
        }
Beispiel #11
0
        public void calculateAppDay(GCLocation location, GregorianDateTime eventDate)
        {
            //MOONDATA moon;
            //SUNDATA sun;
            GCAstroData       d       = this.details = new GCAstroData();
            GregorianDateTime vc      = new GregorianDateTime();
            GregorianDateTime vcsun   = new GregorianDateTime();
            GCEarthData       m_earth = location.GetEarthData();

            vc.Set(eventDate);
            vcsun.Set(eventDate);

            this.b_adhika  = false;
            this.eventTime = new GregorianDateTime(eventDate);
            Location       = location;

            //d.nTithi = GetPrevTithiStart(m_earth, vc, dprev);
            //GetNextTithiStart(m_earth, vc, dnext);
            vcsun.shour -= vcsun.TimezoneHours / 24.0;
            vcsun.NormalizeValues();
            vcsun.TimezoneHours     = 0.0;
            d.sunRise               = new GCHourTime();
            d.sunRise.TotalDays     = vc.shour;
            d.sunRise.longitude     = GCCoreAstronomy.GetSunLongitude(vcsun, m_earth);
            d.sunRise.longitudeMoon = GCCoreAstronomy.GetMoonLongitude(vcsun, m_earth);
            d.Ayanamsa              = GCAyanamsha.GetAyanamsa(vc.GetJulianComplete());
            d.sunRise.Ayanamsa      = d.Ayanamsa;

            // tithi


            d.Masa = d.MasaCalc(vc, m_earth);
            if (d.Masa == (int)MasaId.ADHIKA_MASA)
            {
                d.Masa        = d.sunRise.RasiOfSun;
                this.b_adhika = true;
            }

            vc.Today();
            vc.TimezoneHours = m_earth.OffsetUtcHours;
            int               m  = 0;
            GaurabdaDate      va = new GaurabdaDate();
            GregorianDateTime vctemp;

            va.tithi = d.sunRise.Tithi;
            va.masa  = d.Masa;
            va.gyear = GCCalendar.GetGaurabdaYear(vc, m_earth);
            if (va.gyear < d.GaurabdaYear)
            {
                va.gyear = d.GaurabdaYear;
            }

            MainInfo.Add(new AppDayInfo(GCStrings.getString(7), eventDate.ToString()));
            MainInfo.Add(new AppDayBase());
            MainInfo.Add(new AppDayInfo(GCStrings.getString(8), eventDate.ShortTimeString()));
            MainInfo.Add(new AppDayBase());
            MainInfo.Add(new AppDayBase());
            MainInfo.Add(new AppDayInfo(GCStrings.getString(9), location.Title));
            MainInfo.Add(new AppDayInfo(GCStrings.getString(10), location.GetLatitudeString()));
            MainInfo.Add(new AppDayInfo(GCStrings.getString(11), location.GetLongitudeString()));
            MainInfo.Add(new AppDayInfo(GCStrings.Localized("Timezone"), location.TimeZoneName));
            MainInfo.Add(new AppDayInfo("DST", "N/A"));
            MainInfo.Add(new AppDayBase());
            MainInfo.Add(new AppDayInfo(GCStrings.getString(13), GCTithi.GetName(d.sunRise.Tithi)));
            MainInfo.Add(new AppDayInfo(GCStrings.getString(14), string.Format("{0:00.000}%", d.sunRise.TithiElapse)));
            MainInfo.Add(new AppDayInfo(GCStrings.getString(15), GCNaksatra.GetName(d.sunRise.Naksatra)));
            MainInfo.Add(new AppDayInfo(GCStrings.getString(16), string.Format("{0:00.000}% ({1} pada)", d.sunRise.NaksatraElapse, GCStrings.getString(811 + d.sunRise.NaksatraPada))));
            MainInfo.Add(new AppDayInfo(GCStrings.Localized("Moon Rasi"), GCRasi.GetName(d.sunRise.RasiOfMoon)));
            MainInfo.Add(new AppDayInfo(GCStrings.Localized("Sun Rasi"), GCRasi.GetName(d.sunRise.RasiOfSun)));
            MainInfo.Add(new AppDayInfo(GCStrings.getString(20), GCPaksa.GetName(d.sunRise.Paksa)));

            if (b_adhika == true)
            {
                MainInfo.Add(new AppDayInfo(GCStrings.getString(22), string.Format("{0} {1}", GCMasa.GetName(d.Masa), GCStrings.getString(21))));
            }
            else
            {
                MainInfo.Add(new AppDayInfo(GCStrings.getString(22), GCMasa.GetName(d.Masa)));
            }
            MainInfo.Add(new AppDayInfo(GCStrings.getString(23), d.GaurabdaYear.ToString()));

            if (GCDisplaySettings.Current.getValue(48) == 1)
            {
                MainInfo.Add(new AppDayBase(GCDS.APP_CHILDNAMES));
                MainInfo.Add(new AppDaySeparator(GCStrings.getString(17)));
                MainInfo.Add(new AppDayBase(GCDS.APP_CHILDNAMES));

                MainInfo.Add(new AppDayInfo(GCDS.APP_CHILDNAMES, GCStrings.getString(18), GCStrings.GetNaksatraChildSylable(d.sunRise.Naksatra, d.sunRise.NaksatraPada) + "..."));
                MainInfo.Add(new AppDayInfo(GCDS.APP_CHILDNAMES, GCStrings.getString(19), GCStrings.GetRasiChildSylable(d.sunRise.RasiOfMoon) + "..."));
            }

            MainInfo.Add(new AppDayBase());
            MainInfo.Add(new AppDaySeparator(GCStrings.getString(24)));
            MainInfo.Add(new AppDayBase());


            celeb_date = new GregorianDateTime[TRESULT_APP_CELEBS];
            celeb_gy   = new int[TRESULT_APP_CELEBS];

            for (int i = 0; i < TRESULT_APP_CELEBS + 3; i++)
            {
                GCCalendar.VATIMEtoVCTIME(va, out vctemp, m_earth);
                if (va.gyear > d.GaurabdaYear)
                {
                    if (m < TRESULT_APP_CELEBS)
                    {
                        MainInfo.Add(new AppDayInfo(string.Format("Gaurabda {0}", va.gyear), vctemp.ToString()));
                        this.celeb_date[m] = new GregorianDateTime(vctemp);
                        this.celeb_gy[m]   = va.gyear;
                        m++;
                    }
                }
                va.gyear++;
            }
        }