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

        public static int GetNextStart(GPGregorianTime startDate, out GPGregorianTime nextDate)
        {
            double          phi = 40 / 3.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 * 3 / 40.0));

            int counter = 0;

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

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

                moon.MoonCalc(jday);
                //SunPosition(d, ed, sun, d.shour - 0.5 + d.tzone/24.0);
                //l2 = put_in_360(moon.longitude_deg - sun.longitude_deg - 180.0);
                sunl = GPSun.GetSunLongitude(jday);
                l2   = GPMath.putIn360(moon.longitude_deg + sunl - 2 * ayanamsa);
                //Debugger.Log(0, "", "Current position: " + l2/12.0 + "   date: " + jday + "\n");
                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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 public void Copy(GPGregorianTime vc)
 {
     p_year  = vc.getYear();
     p_month = vc.getMonth();
     p_day   = vc.getDay();
     setDayHours(vc.getDayHours());
     setLocationProvider(vc.getLocationProvider());
     recalculateJulianGreenwichTime();
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public static int GetNextRasi(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);
            //l1 = GPMath.putIn360(moon.longitude_deg - ayanamsa);
            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() > 1.0)
                {
                    d.setDayHours(d.getDayHours() - 1.0);
                    d.NextDay();
                }

                moon.MoonCalc(jday);
                //l2 = GPMath.putIn360(moon.longitude_deg - ayanamsa);
                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);
        }
Ejemplo n.º 6
0
        public static int WriteXML_FirstDay_Year(StringBuilder doc, GPGregorianTime vcStart)
        {
            vcStart = GPGaurabdaYear.getFirstDayOfYear(vcStart.getLocationProvider(), vcStart.getYear());

            // write
            doc.Append("<xml>\n");
            doc.Append("\t\t<arg name=\"longitude\" val=\"" + vcStart.getLocation().GetLongitudeEastPositive() + "\" />\n");
            doc.Append("\t\t<arg name=\"latitude\" val=\"" + vcStart.getLocation().GetLatitudeNorthPositive() + "\" />\n");
            doc.Append("\t\t<arg name=\"year\" val=\"" + vcStart.getYear() + "\" />\n");
            doc.Append("\t</request>\n");
            doc.Append("\t<result name=\"FirstDay_of_GaurabdaYear\">\n");
            doc.Append("\t\t<firstday date=\"" + vcStart
                       + "\" dayweekid = \"" + vcStart.getDayOfWeek() + "\" dayweek=\"" + getSharedStringHtml(vcStart.getDayOfWeek()) + "\" />\n");
            doc.Append("\t</result>\n");
            doc.Append("</xml>\n");

            return(0);
        }
Ejemplo n.º 7
0
        public void CalculateEvents(GPLocationProvider loc, GPGregorianTime vcStart, GPGregorianTime vcEnd)
        {
            GPCoreEventResults inEvents = this;
            GPLocationProvider earth    = loc;
            GPGregorianTime    vc       = new GPGregorianTime(loc);
            GPSun sun = new GPSun();
            //int ndst = 0;
            int nData;

            inEvents.clear();
            inEvents.m_location = loc;
            inEvents.m_vcStart  = vcStart;
            inEvents.m_vcEnd    = vcEnd;

            GPGregorianTime vcAdd  = new GPGregorianTime(loc);
            GPGregorianTime vcTemp = null;
            GPGregorianTime vcNext = new GPGregorianTime(loc);

            vc.Copy(vcStart);

            if (GPDisplays.CoreEvents.Sunrise())
            {
                vcAdd.Copy(vc);
                while (vcAdd.IsBeforeThis(vcEnd))
                {
                    sun.SunCalc(vcAdd, earth);

                    vcTemp = new GPGregorianTime(sun.arunodaya);
                    inEvents.AddEvent(vcTemp, GPConstants.CCTYPE_S_ARUN, 0);

                    //GPJulianTime tr, tt, ts;
                    //GPAstroEngine.CalculateTimeSun(vcTemp, vcTemp.getLocation(), out tr, out tt, out ts);
                    vcTemp = new GPGregorianTime(sun.rise);
                    //vcTemp = new GPGregorianTime(vcTemp.getLocation(), tr);
                    inEvents.AddEvent(vcTemp, GPConstants.CCTYPE_S_RISE, 0);

                    vcTemp = new GPGregorianTime(sun.noon);
                    //vcTemp = new GPGregorianTime(vcTemp.getLocation(), tt);
                    inEvents.AddEvent(vcTemp, GPConstants.CCTYPE_S_NOON, 0);

                    vcTemp = new GPGregorianTime(sun.set);
                    //vcTemp = new GPGregorianTime(vcTemp.getLocation(), ts);
                    inEvents.AddEvent(vcTemp, GPConstants.CCTYPE_S_SET, 0);

                    vcAdd.NextDay();
                }
            }

            if (GPDisplays.CoreEvents.Tithi())
            {
                GPTithi te = new GPTithi();
                te.setStartDate(vc);
                vcAdd = te.getNext();
                while (vcAdd.IsBeforeThis(vcEnd))
                {
                    nData = te.getCurrentPosition();
                    //ndst = loc.getTimeZone().GetDaylightChangeType(vcNext);
                    inEvents.AddEvent(vcAdd, GPConstants.CCTYPE_TITHI, nData);
                    vcAdd = te.getNext();
                }
            }

            if (GPDisplays.CoreEvents.Naksatra())
            {
                GPNaksatra te = new GPNaksatra();
                te.setStartDate(vc);
                vcAdd = te.getNext();
                while (vcAdd.IsBeforeThis(vcEnd))
                {
                    nData = te.getCurrentNaksatra();
                    //ndst = loc.getTimeZone().GetDaylightChangeType(vcNext);
                    inEvents.AddEvent(vcAdd, GPConstants.CCTYPE_NAKS, nData);
                    vcAdd = te.getNext();
                }
            }

            if (GPDisplays.CoreEvents.Sankranti())
            {
                GPSankranti te = new GPSankranti();
                te.setStartDate(vc);
                vcAdd = te.getNext();
                while (vcAdd.IsBeforeThis(vcEnd))
                {
                    nData = te.getCurrentPosition();
                    //ndst = loc.getTimeZone().GetDaylightChangeType(vcNext);
                    inEvents.AddEvent(vcAdd, GPConstants.CCTYPE_SANK, nData);
                    vcAdd = te.getNext();
                }
            }

            if (GPDisplays.CoreEvents.Conjunction())
            {
                double[]      times = null;
                GPConjunction te    = new GPConjunction();
                te.setStartDate(vc);
                vcAdd = te.getNext();
                while (vcAdd.IsBeforeThis(vcEnd))
                {
                    nData = te.getCurrentPosition();
                    //ndst = loc.getTimeZone().GetDaylightChangeType(vcNext);
                    inEvents.AddEvent(vcAdd, GPConstants.CCTYPE_CONJ, nData);

                    if (GPDisplays.CoreEvents.SunEclipse())
                    {
                        GPAstroEngine.CalculateTimesSunEclipse(vcAdd.getJulianGreenwichTime(), vcAdd.getLocation(), out times);
                        if (times != null && times[2] > 0)
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                if (times[i] > 0)
                                {
                                    GPGregorianTime gt = new GPGregorianTime(vcAdd.getLocation());
                                    gt.setJulianGreenwichTime(new GPJulianTime(times[i], 0.0));
                                    inEvents.AddEvent(gt, GPConstants.SUNECLIPSE_CONSTS[i], 0);
                                }
                            }
                        }
                    }

                    vcAdd = te.getNext();
                }
            }


            // moon eclipses
            if (GPDisplays.CoreEvents.MoonEclipse())
            {
                double[]      times = null;
                GPConjunction te    = new GPConjunction();
                te.setOpositeConjunction(true);
                te.setStartDate(vc);
                vcAdd = te.getNext();
                while (vcAdd.IsBeforeThis(vcEnd))
                {
                    GPAstroEngine.CalculateTimesMoonEclipse(vcAdd.getJulianGreenwichTime(), vcAdd.getLocation(), out times);
                    if (times != null && times[4] > 0)
                    {
                        for (int i = 0; i < 9; i++)
                        {
                            if (times[i] > 0 && GPConstants.MOONECLIPSE_CONSTS[i] > 0)
                            {
                                GPGregorianTime gt = new GPGregorianTime(vcAdd.getLocation());
                                gt.setJulianGreenwichTime(new GPJulianTime(times[i], 0.0));
                                inEvents.AddEvent(gt, GPConstants.MOONECLIPSE_CONSTS[i], 0);
                            }
                        }
                    }

                    vcAdd = te.getNext();
                }
            }

            // rise and set of the moon
            if (GPDisplays.CoreEvents.Moonrise())
            {
                GPJulianTime julian    = vc.getJulian();
                GPJulianTime julianEnd = vcEnd.getJulian();
                GPJulianTime nextJulian;
                TRiseSet     kind;

                while (julian.getGreenwichJulianDay() < julianEnd.getGreenwichJulianDay())
                {
                    nextJulian = GPAstroEngine.GetNextMoonEvent(julian, vc.getLocationProvider(), out kind);
                    if (kind == TRiseSet.RISE)
                    {
                        inEvents.AddEvent(new GPGregorianTime(loc, nextJulian), GPConstants.CoreEventMoonRise, 0);
                    }
                    else if (kind == TRiseSet.SET)
                    {
                        inEvents.AddEvent(new GPGregorianTime(loc, nextJulian), GPConstants.CoreEventMoonSet, 0);
                    }
                    julian.setGreenwichJulianDay(nextJulian.getGreenwichJulianDay() + 10.0 / 1440.0);
                }
            }

            // travellings
            {
                GPJulianTime julian = vc.getJulian();
                GPJulianTime julianEnd = vcEnd.getJulian();
                double       start, end;

                start = julian.getGreenwichJulianDay();
                end   = julianEnd.getGreenwichJulianDay();

                for (int i = 0; i < loc.getChangeCount(); i++)
                {
                    GPLocationChange chn = loc.getChangeAtIndex(i);
                    if ((chn.julianStart >= start && chn.julianStart <= end) ||
                        (chn.julianStart >= start && chn.julianEnd <= end))
                    {
                        GPGregorianTime startTime = new GPGregorianTime(chn.LocationA);
                        startTime.setJulianGreenwichTime(new GPJulianTime(chn.julianStart, 0));
                        GPGregorianTime endTime = new GPGregorianTime(chn.LocationB);
                        endTime.setJulianGreenwichTime(new GPJulianTime(chn.julianEnd, 0));
                        inEvents.AddEvent(startTime, GPConstants.CCTYPE_TRAVELLING_START, 0);
                        inEvents.AddEvent(endTime, GPConstants.CCTYPE_TRAVELLING_END, 0);
                    }
                }
            }

            // eventual sorting
            inEvents.Sort(GPDisplays.CoreEvents.Sort());
        }