Example #1
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 DstTypeChange DetermineDaylightChange(GregorianDateTime vc2)
        {
            int t2 = this.GetBiasMinutesForDay(vc2);
            GregorianDateTime vc3 = new GregorianDateTime();

            vc3.Set(vc2);
            vc3.PreviousDay();
            int t1 = this.GetBiasMinutesForDay(vc3);

            if (t1 != 0)
            {
                if (t2 != 0)
                {
                    return(DstTypeChange.DstOn);
                }
                else
                {
                    return(DstTypeChange.DstEnd);
                }
            }
            else if (t2 != 0)
            {
                return(DstTypeChange.DstStart);
            }
            else
            {
                return(DstTypeChange.DstOff);
            }
        }
Example #2
0
        /*********************************************************************/
        /*  Finds date of Pratipat, Krsna Paksa, Visnu Masa                  */
        /*                                                                   */
        /*  EARTHDATA earth - location                                       */
        /*  int nYear       - Gregorian year                                 */
        /*                                                                   */
        /*********************************************************************/

        public static GregorianDateTime GetFirstDayOfYear(GCEarthData earth, int nYear)
        {
            int[]             a = { 2, 15, 3, 1, 3, 15, 4, 1, 4, 15 };
            GregorianDateTime d = new GregorianDateTime();
            GCAstroData       day = new GCAstroData();
            int    gy, j, masa;
            int    step;
            UInt32 tmp;

            if (nYear >= 1950 && nYear < 2058)
            {
                tmp     = gGaurBeg[(nYear - 1950) * 26 + 22];
                d.month = (int)(tmp & 0x3e0) >> 5;
                d.day   = (int)(tmp & 0x1f);
                d.year  = nYear;
                d.NextDay();
                a[0] = d.month;
                a[1] = d.day;
            }

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

                day.DayCalc(d, earth);
                masa = day.MasaCalc(d, earth);
                gy   = day.GaurabdaYear;

                if (masa == 11) // visnu masa
                {
                    do
                    {
                        // shifts date
                        step = day.sunRise.Tithi / 2;
                        step = (step > 0) ? step : 1;
                        for (j = step; j > 0; j--)
                        {
                            d.PreviousDay();
                        }
                        // try new time
                        day.DayCalc(d, earth);
                    }while (day.sunRise.Tithi < 28);
                    d.NextDay();
                    d.TimezoneHours = earth.OffsetUtcHours;
                    d.shour         = day.sunRise.TotalDays;
                    return(d);
                }
            }

            d.year          = -1;
            d.month         = -1;
            d.day           = -1;
            d.TimezoneHours = earth.OffsetUtcHours;
            d.shour         = day.sunRise.TotalDays;

            return(d);
        }
Example #3
0
        public void Calculate(GregorianDateTime dateTime, GCLocation location)
        {
            GregorianDateTime vc2 = new GregorianDateTime();

            currentDay = new GregorianDateTime();
            currentDay.Set(dateTime);
            currentDay.InitWeekDay();
            vc2.Set(currentDay);

            vc2.TimezoneHours = location.OffsetUtcHours;
            vc2.PreviousDay();
            vc2.PreviousDay();
            vc2.PreviousDay();
            vc2.PreviousDay();
            calendar = new TResultCalendar();
            calendar.CalculateCalendar(location, vc2, 9);
        }
Example #4
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);
        }
Example #5
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(GCEarthData ed, GregorianDateTime startDate, out GregorianDateTime nextDate)
        {
            double            phi = 40.0 / 3.0;
            double            l1, l2, longitudeMoon;
            double            jday = startDate.GetJulianComplete();
            GregorianDateTime d    = new GregorianDateTime(startDate);
            double            xj;
            GregorianDateTime xd        = new GregorianDateTime();
            double            ayanamsa  = GCAyanamsha.GetAyanamsa(jday);
            double            scan_step = 0.5;
            int prev_naks = 0;
            int new_naks  = -1;


            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 < 0.0)
                {
                    d.shour += 1.0;
                    d.PreviousDay();
                }

                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 = d;
            return(new_naks);
        }
Example #6
0
 public int GetDaylightTimeStartDate(int nYear, ref GregorianDateTime vcStart)
 {
     vcStart.day   = 1;
     vcStart.month = Convert.ToInt32(StartDst.Month);
     vcStart.year  = nYear;
     if (StartDst.Type == 1)
     {
         vcStart.day = StartDst.Day;
     }
     else
     {
         if (StartDst.Month == 5)
         {
             vcStart.day = GregorianDateTime.GetMonthMaxDays(nYear, StartDst.Month);
             vcStart.InitWeekDay();
             while (vcStart.dayOfWeek != StartDst.Day)
             {
                 vcStart.PreviousDay();
                 vcStart.dayOfWeek = (vcStart.dayOfWeek + 6) % 7;
             }
         }
         else
         {
             vcStart.day = 1;
             vcStart.InitWeekDay();
             while (vcStart.dayOfWeek != StartDst.Day)
             {
                 vcStart.NextDay();
                 vcStart.dayOfWeek = (vcStart.dayOfWeek + 1) % 7;
             }
             vcStart.day += StartDst.Week * 7;
         }
     }
     vcStart.shour = 1 / 24.0;
     return(0);
 }
Example #7
0
        public static int writeGaurabdaNextTithiXml(string fileName, GCLocation loc, GregorianDateTime vcStart, GaurabdaDate vaStart)
        {
            int        gmasa, gpaksa, gtithi;
            GCHourTime sunRise;

            using (StreamWriter xml = new StreamWriter(fileName))
            {
                gmasa  = vaStart.masa;
                gpaksa = vaStart.tithi / 15;
                gtithi = vaStart.tithi % 15;

                xml.Write("<xml>\n");
                xml.Write("\t<request name=\"Tithi\" version=\"");
                xml.Write(GCStrings.getString(130));
                xml.Write("\">\n");
                xml.Write("\t\t<arg name=\"longitude\" val=\"");
                xml.Write(loc.Longitude);
                xml.Write("\" />\n");
                xml.Write("\t\t<arg name=\"latitude\" val=\"");
                xml.Write(loc.Latitude);
                xml.Write("\" />\n");
                xml.Write("\t\t<arg name=\"timezone\" val=\"");
                xml.Write(loc.OffsetUtcHours);
                xml.Write("\" />\n");
                xml.Write("\t\t<arg name=\"start date\" val=\"");
                xml.Write(vcStart);
                xml.Write("\" />\n");
                xml.Write("\t\t<arg name=\"masa\" val=\"");
                xml.Write(gmasa);
                xml.Write("\" />\n");
                xml.Write("\t\t<arg name=\"paksa\" val=\"");
                xml.Write(gpaksa);
                xml.Write("\" />\n");
                xml.Write("\t\t<arg name=\"tithi\" val=\"");
                xml.Write(gtithi);
                xml.Write("\" />\n");
                xml.Write("\t</request>\n");
                xml.Write("\t<result name=\"Tithi\">\n");

                GCEarthData       earth = loc.GetEarthData();
                GregorianDateTime vcs = new GregorianDateTime(), vce = new GregorianDateTime(), today = new GregorianDateTime();
                //GCSunData sun = new GCSunData();
                int         A;
                double      sunrise;
                GCAstroData day = new GCAstroData();
                int         oTithi, oPaksa, oMasa, oYear;

                today.Set(vcStart);
                today.PreviousDay();
                vcStart.SubtractDays(15);
                for (A = 0; A <= 3; A++)
                {
                    vcs.Set(GCTithi.CalcTithiEndEx(vcStart, 0, gmasa, gpaksa, gtithi, earth, out vce));
                    if (!vcs.IsBeforeThis(today))
                    {
                        oTithi = gpaksa * 15 + gtithi;
                        oMasa  = gmasa;
                        oPaksa = gpaksa;
                        oYear  = 0;
                        xml.Write("\t<celebration\n");
                        //		xml.Write("\t\t<tithi\n";
                        xml.Write("\t\trtithi=\"");
                        xml.Write(GCTithi.GetName(oTithi));
                        xml.Write("\"\n");
                        xml.Write("\t\trmasa=\"");
                        xml.Write(GCMasa.GetName(oMasa));
                        xml.Write("\"\n");
                        xml.Write("\t\trpaksa=\"");
                        xml.Write((oPaksa != 0 ? "Gaura" : "Krsna"));
                        xml.Write("\"\n");
                        // test ci je ksaya
                        today.Set(vcs);
                        today.shour = 0.5;
                        sunRise     = GCSunData.CalcSunrise(today, earth);
                        sunrise     = sunRise.TotalDays;
                        if (sunrise < vcs.shour)
                        {
                            today.Set(vce);
                            sunRise = GCSunData.CalcSunrise(today, earth);
                            sunrise = sunRise.TotalDays;
                            if (sunrise < vce.shour)
                            {
                                // normal type
                                vcs.NextDay();
                                xml.Write("\t\ttype=\"normal\"\n");
                            }
                            else
                            {
                                // ksaya
                                vcs.NextDay();
                                day.DayCalc(vcs, earth);
                                oTithi = day.sunRise.Tithi;
                                oPaksa = day.sunRise.Paksa;
                                oMasa  = day.MasaCalc(vcs, earth);
                                oYear  = day.GaurabdaYear;
                                xml.Write("\t\ttype=\"ksaya\"\n");
                            }
                        }
                        else
                        {
                            // normal, alebo prvy den vriddhi
                            today.Set(vce);
                            sunRise = GCSunData.CalcSunrise(today, earth);
                            if (sunRise.TotalDays < vce.shour)
                            {
                                // first day of vriddhi type
                                xml.Write("\t\ttype=\"vriddhi\"\n");
                            }
                            else
                            {
                                // normal
                                xml.Write("\t\ttype=\"normal\"\n");
                            }
                        }
                        xml.Write("\t\tdate=\"");
                        xml.Write(vcs);
                        xml.Write("\"\n");
                        xml.Write("\t\totithi=\"");
                        xml.Write(GCTithi.GetName(oTithi));
                        xml.Write("\"\n");
                        xml.Write("\t\tomasa=\"");
                        xml.Write(GCMasa.GetName(oMasa));
                        xml.Write("\"\n");
                        xml.Write("\t\topaksa=\"");
                        xml.Write(GCPaksa.GetName(oPaksa));
                        xml.Write("\"\n");
                        xml.Write("\t/>\n");
                        break;
                    }
                    else
                    {
                        vcStart.Set(vcs);
                        vcs.NextDay();
                    }
                }

                xml.Write("\t</result>\n");
                xml.Write("</xml>\n");
            }

            return(1);
        }
Example #8
0
        /*********************************************************************/
        /*  Calculates Date of given Tithi                                   */
        /*********************************************************************/

        public static GregorianDateTime CalcTithiDate(int nGYear, int nMasa, int nPaksa, int nTithi, GCEarthData earth)
        {
            int i = 0, gy = 0;
            GregorianDateTime d   = new GregorianDateTime();
            GCAstroData       day = new GCAstroData();
            int    tithi          = 0;
            int    counter        = 0;
            UInt32 tmp            = 0;

            if (nGYear >= 464 && nGYear < 572)
            {
                tmp             = GCAstroData.gGaurBeg[(nGYear - 464) * 26 + nMasa * 2 + nPaksa];
                d.month         = Convert.ToInt32((tmp & 0x3e0) >> 5);
                d.day           = Convert.ToInt32(tmp & 0x1f);
                d.year          = Convert.ToInt32(tmp & 0xfffc00) >> 10;
                d.TimezoneHours = earth.OffsetUtcHours;
                d.NextDay();

                day.DayCalc(d, earth);
                day.Masa = day.MasaCalc(d, earth);
                gy       = day.GaurabdaYear;
            }
            else
            {
                //d = GetFirstDayOfYear(earth, nGYear + 1486);
                d.day   = 15;
                d.month = 2 + nMasa;
                d.year  = nGYear + 1486;
                if (d.month > 12)
                {
                    d.month -= 12;
                    d.year++;
                }
                d.shour         = 0.5;
                d.TimezoneHours = earth.OffsetUtcHours;

                i = 0;
                do
                {
                    d.AddDays(13);
                    day.DayCalc(d, earth);
                    day.Masa = day.MasaCalc(d, earth);
                    gy       = day.GaurabdaYear;
                    i++;
                }while (((day.sunRise.Paksa != nPaksa) || (day.Masa != nMasa)) && (i <= 30));
            }

            if (i >= 30)
            {
                d.year = d.month = d.day = -1;
                return(d);
            }

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

            if (day.sunRise.Tithi == 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.DayCalc(d, earth);
                if ((day.sunRise.Tithi > tithi) && (day.sunRise.Paksa != nPaksa))
                {
                    d.NextDay();
                }
                return(d);
            }

            if (day.sunRise.Tithi < 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.DayCalc(d, earth);
                    if (day.sunRise.Tithi == tithi)
                    {
                        return(d);
                    }
                    if ((day.sunRise.Tithi < tithi) && (day.sunRise.Paksa != nPaksa))
                    {
                        return(d);
                    }
                    if (day.sunRise.Tithi > tithi)
                    {
                        return(d);
                    }
                    counter++;
                }
                // somewhere is error
                d.year = d.month = d.day = 0;
                return(d);
            }
            else
            {
                // do decrement of date until nTithi <= tithi
                counter = 0;
                while (counter < 16)
                {
                    d.PreviousDay();
                    day.DayCalc(d, earth);
                    if (day.sunRise.Tithi == tithi)
                    {
                        return(d);
                    }
                    if ((day.sunRise.Tithi > tithi) && (day.sunRise.Paksa != nPaksa))
                    {
                        d.NextDay();
                        return(d);
                    }
                    if (day.sunRise.Tithi < tithi)
                    {
                        d.NextDay();
                        return(d);
                    }
                    counter++;
                }
                // somewhere is error
                d.year = d.month = d.day = 0;
                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
            //

            return(d);
        }
Example #9
0
        public static GregorianDateTime CalcTithiEndEx(GregorianDateTime vcStart, int GYear, int nMasa, int nPaksa, int nTithi, GCEarthData earth, out GregorianDateTime endTithi)
        {
            int i, gy, nType;
            GregorianDateTime d   = new GregorianDateTime();
            GCAstroData       day = new GCAstroData();
            int tithi;
            int counter;
            GregorianDateTime start = new GregorianDateTime(), end = new GregorianDateTime();
            //	SUNDATA sun;
            //	MOONDATA moon;
            double sunrise;

            start.shour = -1.0;
            end.shour   = -1.0;
            start.day   = start.month = start.year = -1;
            end.day     = end.month = end.year = -1;

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

            i = 0;
            do
            {
                d.AddDays(13);
                day.DayCalc(d, earth);
                day.Masa = day.MasaCalc(d, earth);
                gy       = day.GaurabdaYear;
                i++;
            }while (((day.sunRise.Paksa != nPaksa) || (day.Masa != nMasa)) && (i <= 30));

            if (i >= 30)
            {
                d.year   = d.month = d.day = -1;
                endTithi = null;
                return(d);
            }

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

            if (day.sunRise.Tithi == 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.sunRise.Tithi < 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.DayCalc(d, earth);
                        if (day.sunRise.Tithi == tithi)
                        {
                            goto cont_2;
                        }
                        if ((day.sunRise.Tithi < tithi) && (day.sunRise.Paksa != nPaksa))
                        {
                            d.PreviousDay();
                            goto cont_2;
                        }
                        if (day.sunRise.Tithi > tithi)
                        {
                            d.PreviousDay();
                            goto cont_2;
                        }
                        counter++;
                    }
                    // somewhere is error
                    d.year = d.month = d.day = 0;
                    nType  = 0;
                }
                else
                {
                    // do decrement of date until nTithi <= tithi
                    counter = 0;
                    while (counter < 30)
                    {
                        d.PreviousDay();
                        day.DayCalc(d, earth);
                        if (day.sunRise.Tithi == tithi)
                        {
                            goto cont_2;
                        }
                        if ((day.sunRise.Tithi > tithi) && (day.sunRise.Paksa != nPaksa))
                        {
                            goto cont_2;
                        }
                        if (day.sunRise.Tithi < tithi)
                        {
                            goto cont_2;
                        }
                        counter++;
                    }
                    // somewhere is error
                    d.year = d.month = d.day = 0;
                    nType  = 0;
                }
cont_2:
                if (day.sunRise.Tithi == 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.sunRise.TotalDays;
            endTithi = new GregorianDateTime();
            if (nType == 1)
            {
                GregorianDateTime d1, d2;
                d.shour = sunrise;
                GCTithi.GetPrevTithiStart(earth, d, out d1);
                //d = d1;
                //d.shour += 0.02;
                GCTithi.GetNextTithiStart(earth, d, out d2);
                endTithi.Set(d2);
                return(d1);
            }
            else if (nType == 2)
            {
                GregorianDateTime d1, d2;
                d.shour = sunrise;
                GCTithi.GetNextTithiStart(earth, d, out d1);
                d.Set(d1);
                d.shour += 0.1;
                d.NormalizeValues();
                GCTithi.GetNextTithiStart(earth, d, out d2);

                endTithi.Set(d2);
                return(d1);
            }

            // if nType == 0, then this algoritmus has some failure
            if (nType == 0)
            {
                d.year  = 0;
                d.month = 0;
                d.day   = 0;
                d.shour = 0.0;
                endTithi.Set(d);
            }
            else
            {
                d.Set(start);
                endTithi.Set(end);
            }
            return(d);
        }
Example #10
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);
        }
Example #11
0
        /*********************************************************************/
        /*                                                                   */
        /*                                                                   */
        /*                                                                   */
        /*                                                                   */
        /*                                                                   */
        /*********************************************************************/

        public static double GetPrevConjunction(GregorianDateTime test_date, out GregorianDateTime found, bool this_conj, GCEarthData earth)
        {
            double phi = 12.0;
            double l1, l2, sunl, 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);
            sunl          = GCSunData.GetSunLongitude(d);
            l1            = GCMath.putIn180(longitudeMoon - sunl);
            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();
                }

                longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, earth);
                sunl          = GCSunData.GetSunLongitude(d);
                l2            = GCMath.putIn180(longitudeMoon - sunl);
                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(sunl);
        }
Example #12
0
        /// <summary>
        /// Calculation of Masa List
        /// </summary>
        /// <param name="loc">Location</param>
        /// <param name="nYear">Starting year</param>
        /// <param name="nCount">Number of years</param>
        /// <returns></returns>
        public int CalculateMasaList(GCLocation loc, int nYear, int nCount)
        {
            GCAstroData       day = new GCAstroData();
            GregorianDateTime d = new GregorianDateTime(), de = new GregorianDateTime(), t = new GregorianDateTime();
            int             lm    = -1;
            TResultMasaList mlist = this;
            GCEarthData     earth = loc.GetEarthData();

            mlist.n_startYear  = nYear;
            mlist.n_countYears = nCount;
            mlist.vc_start     = new GregorianDateTime();
            mlist.vc_end       = new GregorianDateTime();
            mlist.vc_start.Set(GCAstroData.GetFirstDayOfYear(earth, nYear));
            mlist.vc_end.Set(GCAstroData.GetFirstDayOfYear(earth, nYear + nCount));
            mlist.m_location = loc;

            d.Set(mlist.vc_start);
            de.Set(mlist.vc_end);

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


            while (d.IsBeforeThis(de))
            {
                day.DayCalc(d, earth);
                if (prev_paksa != day.sunRise.Paksa)
                {
                    day.Masa = day.MasaCalc(d, earth);

                    if (lm != day.Masa)
                    {
                        if (lm >= 0)
                        {
                            t.Set(d);
                            t.PreviousDay();
                            if (mlist.arr.Count <= current)
                            {
                                mlist.arr.Add(new TResultMasa());
                            }
                            mlist.arr[current].vc_end = new GregorianDateTime(t);
                            current++;
                        }
                        lm = day.Masa;
                        if (mlist.arr.Count <= current)
                        {
                            mlist.arr.Add(new TResultMasa());
                        }
                        mlist.arr[current].masa     = day.Masa;
                        mlist.arr[current].year     = day.GaurabdaYear;
                        mlist.arr[current].vc_start = new GregorianDateTime(d);
                    }
                }
                prev_paksa = day.sunRise.Paksa;
                d.NextDay();
                i++;
            }

            mlist.arr[current].vc_end = new GregorianDateTime(d);
            current++;
            mlist.n_countMasa = current;

            return(1);
        }