Beispiel #1
0
        public static void FormatAppDayText(GPAppDayResults app, StringBuilder strResult)
        {
            GPAstroData     d = app.details;
            string          str;
            GPGregorianTime vc      = app.evente;
            StringBuilder   strText = strResult;

            int max = 0;

            foreach (GPStringPair rec in app.output)
            {
                if (!rec.Header)
                {
                    max = Math.Max(max, rec.Name.Length);
                }
            }
            max++;
            foreach (GPStringPair rec in app.output)
            {
                if (rec.Header)
                {
                    AddTextLine(strText, rec.Name);
                    AddTextLine(strText, string.Empty.PadLeft(rec.Name.Length, '-'));
                }
                else
                {
                    str = string.Format("{0} : {1}", rec.Name.PadLeft(max), rec.Value);
                    AddTextLine(strText, str);
                }
            }
        }
Beispiel #2
0
        public static void FormatAppDayRtf(GPAppDayResults app, StringBuilder strResult)
        {
            //MOONDATA moon;
            //SUNDATA sun;
            GPAstroData     d = app.details;
            string          str;
            GPGregorianTime vc      = app.evente;
            StringBuilder   strText = strResult;

            strText.Remove(0, strText.Length);
            AppendRtfHeader(strText);


            foreach (GPStringPair rec in app.output)
            {
                if (rec.Header)
                {
                    strText.AppendFormat("\\par\\pard{{\\f2\\fs{0} {1}}", g_HeaderSize, rec.Name);
                    strText.AppendFormat("\\par\\pard\\f2\\fs{0}\r\n", g_TextSize);
                }
                else
                {
                    str = string.Format("\\tab {0} : {{\\b {1}}", rec.Name, rec.Value);
                    AddTextLineRtf(strText, str);
                }
            }


            strText.Append("}");
        }
Beispiel #3
0
        //===========================================================================
        //
        //===========================================================================

        public static void VCTIMEtoVATIME(GPGregorianTime vc, out GPVedicTime va, GPLocationProvider earth)
        {
            GPAstroData day = new GPAstroData();

            va = new GPVedicTime();

            day.calculateDayData(vc, earth);
            va.masa  = day.determineMasa(vc, out va.gyear);
            va.tithi = day.nTithi;
        }
Beispiel #4
0
        public static int getGaurabdaYear(GPGregorianTime vc, GPLocationProvider earth)
        {
            GPAstroData day = new GPAstroData();
            int         n;

            day.calculateDayData(vc, earth);
            day.determineMasa(vc, out n);

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

        public int calculateDayData(GPGregorianTime aDate, GPLocationProvider earth)
        {
            double          d;
            GPAstroData     day  = this;
            GPGregorianTime date = new GPGregorianTime(aDate);

            //	SUNDATA sun;

            // sun position on sunrise on that day
            sun.SunCalc(date, earth);
            date.setDayHours(sun.getSunriseDayHours());

            // date.shour is [0..1] time of sunrise in local timezone time
            jdate = date.getJulianGreenwichTime();

            // moon position at sunrise on that day
            day.moon.MoonCalc(jdate);

            // correct_parallax(day.moon, jdate, earth.latitude_deg, earth.longitude_deg);

            day.msDistance = GPMath.putIn360(day.moon.longitude_deg - day.sun.eclipticalLongitude - 180.0);
            day.msAyanamsa = GPAyanamsa.GetAyanamsa(jdate);

            // tithi
            d                = day.msDistance / 12.0;
            day.nTithi       = Convert.ToInt32(Math.Floor(d));
            day.nTithiElapse = GPMath.frac(d) * 100.0;
            day.nPaksa       = (day.nTithi >= 15) ? 1 : 0;


            // naksatra
            d                   = GPMath.putIn360(day.moon.longitude_deg - day.msAyanamsa);
            d                   = (d * 3.0) / 40.0;
            day.nNaksatra       = Convert.ToInt32(Math.Floor(d) + 0.1);
            day.nNaksatraElapse = GPMath.frac(d) * 100.0;

            // yoga
            d               = GPMath.putIn360(day.moon.longitude_deg + day.sun.eclipticalLongitude - 2 * day.msAyanamsa);
            d               = (d * 3.0) / 40.0;
            day.nYoga       = Convert.ToInt32(Math.Floor(d));
            day.nYogaElapse = GPMath.frac(d) * 100.0;

            // masa
            day.nMasa = -1;

            // rasi
            day.nSunRasi  = GPEngine.GetRasi(day.sun.eclipticalLongitude, day.msAyanamsa);
            day.nMoonRasi = GPEngine.GetRasi(day.moon.longitude_deg, day.msAyanamsa);

            setDate(date);

            return(1);
        }
Beispiel #6
0
        /*********************************************************************/
        /*  Finds date of Pratipat, Krsna Paksa, Visnu Masa                  */
        /*                                                                   */
        /*  EARTHDATA earth - location                                       */
        /*  int nYear       - Gregorian year                                 */
        /*                                                                   */
        /*********************************************************************/

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

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

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

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

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

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

            return(d);
        }
Beispiel #7
0
        public static int WriteXML_Tithi(StringBuilder doc, GPLocationProvider loc, GPGregorianTime vc)
        {
            doc.Append("<xml>\n");
            doc.Append("\t<request name=\"Tithi\" version=\"" + GPFileHelper.FileVersion + "\">\n");
            doc.Append("\t\t<arg name=\"longitude\" val=\"" + vc.getLocation().GetLongitudeEastPositive() + "\" />\n");
            doc.Append("\t\t<arg name=\"latitude\" val=\"" + vc.getLocation().GetLatitudeNorthPositive() + "\" />\n");
            doc.Append("\t\t<arg name=\"timezone\" val=\"" + vc.getLocation().getTimeZone().OffsetSeconds / 60 + "\" />\n");
            doc.Append("\t\t<arg name=\"startdate\" val=\"" + vc + "\" />\n");
            doc.Append("\t</request>\n");
            doc.Append("\t<result name=\"Tithi\">\n");

            GPGregorianTime d  = new GPGregorianTime(vc);
            GPGregorianTime d1 = new GPGregorianTime(loc);
            GPGregorianTime d2 = new GPGregorianTime(loc);


            GPAstroData day = new GPAstroData();

            day.calculateDayData(vc, loc);

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

            GPTithi.GetPrevTithiStart(d, out d1);
            GPTithi.GetNextTithiStart(d, out d2);


            //dt.SetDegTime(d1.getDayHours() * 360);
            // start tithi at t[0]
            doc.Append("\t\t<tithi\n\t\t\tid=\"" + day.nTithi + "\"\n");
            doc.Append("\t\t\tname=\"" + GPTithi.getName(day.nTithi) + "\"\n");
            doc.Append("\t\t\tstartdate=\"" + d1.getShortDateString() + "\"\n");
            doc.Append("\t\t\tstarttime=\"" + d1.getShortTimeString() + "\"\n");

            //dt.SetDegTime(d2.getDayHours() * 360);
            doc.Append("\t\t\tenddate=\"" + d2.getShortDateString() + "\"\n");
            doc.Append("\t\t\tendtime=\"" + d2.getShortTimeString() + "\"\n />");


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

            return(1);
        }
Beispiel #8
0
 public void Copy(GPAstroData dt)
 {
     this.setLocation(dt.getLocation());
     this.setDate(dt.getDate());
     this.jdate           = dt.jdate;
     this.moon            = new GPMoon(dt.moon);
     this.msAyanamsa      = dt.msAyanamsa;
     this.msDistance      = dt.msDistance;
     this.nGaurabdaYear   = dt.nGaurabdaYear;
     this.nMasa           = dt.nMasa;
     this.nMoonRasi       = dt.nMoonRasi;
     this.nNaksatra       = dt.nNaksatra;
     this.nNaksatraElapse = dt.nNaksatraElapse;
     this.nPaksa          = dt.nPaksa;
     this.nSunRasi        = dt.nSunRasi;
     this.nTithi          = dt.nTithi;
     this.nTithiElapse    = dt.nTithiElapse;
     this.nYoga           = dt.nYoga;
     this.nYogaElapse     = dt.nYogaElapse;
     this.sun             = new GPSun(dt.sun);
 }
Beispiel #9
0
        public static GPGregorianTime CalcTithiEndEx(GPGregorianTime vcStart, int GYear, int nMasa, int nPaksa, int nTithi, GPLocationProvider earth, out GPGregorianTime endTithi)
        {
            int             i, gy, nType;
            GPGregorianTime d     = new GPGregorianTime(earth);
            GPGregorianTime dtemp = new GPGregorianTime(earth);
            GPAstroData     day   = new GPAstroData();
            int             tithi;
            int             counter;
            GPGregorianTime start = new GPGregorianTime(earth), end = new GPGregorianTime(earth);
            //	SUNDATA sun;
            //	MOONDATA moon;
            double sunrise;

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

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

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

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

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

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

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

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

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

                endTithi = d2;
                return(d1);
            }

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

            return(d);
        }
Beispiel #10
0
        public static void FormatAppDayXML(GPAppDayResults app, StringBuilder strResult)
        {
            GPAstroData     d = app.details;
            string          str;
            GPGregorianTime vc      = app.evente;
            StringBuilder   strText = strResult;
            int             npada;
            bool            bDuringAdhika = false;

            strText.AppendFormat(
                "<xml>\n" +
                "\t<request name=\"AppDay\" version=\"{0}\">\n" +
                "\t\t<arg name=\"longitude\" value=\"{1}\" />\n" +
                "\t\t<arg name=\"latitude\" value=\"{2}\" />\n" +
                "\t\t<arg name=\"timezone\" value=\"{3}\" />\n" +
                "\t\t<arg name=\"year\" value=\"{4}\" />\n" +
                "\t\t<arg name=\"month\" value=\"{5}\" />\n" +
                "\t\t<arg name=\"day\" value=\"{6}\" />\n" +
                "\t\t<arg name=\"hour\" value=\"{7}\" />\n" +
                "\t\t<arg name=\"minute\" value=\"{8}\" />\n" +
                "\t</request>\n", GPFileHelper.FileVersion,
                app.evente.getLocation().GetLongitudeEastPositive(), app.evente.getLocation().GetLatitudeNorthPositive(),
                app.evente.getLocation().getTimeZoneName(),
                app.evente.getYear(), app.evente.getMonth(), app.evente.getDay(), app.evente.getHour(), app.evente.getMinuteRound()
                );


            npada = Convert.ToInt32(d.nNaksatraElapse / 25.0) + 1;
            if (npada > 4)
            {
                npada = 4;
            }

            str = string.Format("\t<result name=\"AppDay\" >\n" +
                                "\t\t<tithi name=\"{0}\" elapse=\"{1}\" />\n" +
                                "\t\t<naksatra name=\"{2}\" elapse=\"{3}\" pada=\"{4}\"/>\n" +
                                "\t\t<paksa name=\"{5}\" />\n" +
                                "\t\t<masa name=\"{6}\" adhikamasa=\"{7}\"/>\n" +
                                "\t\t<gaurabda value=\"{8}\" />\n"

                                , GPTithi.getName(d.nTithi), d.nTithiElapse
                                , GPNaksatra.getName(d.nNaksatra), d.nNaksatraElapse, npada
                                , GPPaksa.getName(d.nPaksa)
                                , GPMasa.GetName(d.nMasa), (bDuringAdhika ? "yes" : "no")
                                , d.nGaurabdaYear
                                );

            strText.Append(str);;
            string prefix = string.Format("{0} ", getSharedStringHtml(994));

            strText.Append("\t\t<celebrations>\n");
            foreach (GPStringPair rec in app.output)
            {
                if (rec.Name.StartsWith(prefix))
                {
                    str = string.Format("\t\t\t<celebration gaurabda=\"{0}\" date=\"{1}\" />\n", rec.Name, rec.Value);
                    strText.Append(str);
                }
            }

            strText.Append("\t\t</celebrations>\n\t</result>\n</xml>\n");
        }
Beispiel #11
0
        public static int WriteXML_GaurabdaNextTithi(StringBuilder doc, GPLocationProvider loc, GPGregorianTime vcStart, GPVedicTime vaStart)
        {
            int gmasa, gpaksa, gtithi;


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

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

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

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

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


            return(1);
        }
Beispiel #12
0
 public GPAstroData(GPAstroData dt)
 {
     Copy(dt);
 }
Beispiel #13
0
        /*********************************************************************/
        /*                                                                   */
        /*                                                                   */
        /*                                                                   */
        /*                                                                   */
        /*                                                                   */
        /*********************************************************************/

        public int determineMasa(GPGregorianTime aDate, out int nGaurabdaYear)
        {
            GPAstroData     day         = this;
            GPGregorianTime date        = new GPGregorianTime(aDate);
            const int       PREV_MONTHS = 6;

            double[]          L = new double[8];
            GPGregorianTime[] C = new GPGregorianTime[8];
            int[]             R = new int[8];
            int n, rasi;
            int masa       = 0;
            int ksaya_from = -1;
            int ksaya_to   = -1;

            date.setDayHours(day.sun.getSunriseDayHours());

            // STEP 1: calculate position of the sun and moon
            // it is done by previous call of DayCalc
            // and results are in argument DAYDATA day
            // *DayCalc(date, earth, day, moon, sun);*

            GPConjunction cit = new GPConjunction();

            cit.setStartDate(date);
            for (n = 1; n >= 0; n--)
            {
                cit.getNext();
                R[n] = cit.getCurrentPosition();
            }
            //L[1] = /*Long[0] =*/ GPConjunction.GetNextConjunction(date, ref C[1], false, earth);
            //L[0] = /*LongA   =*/ GPConjunction.GetNextConjunction(C[1], ref C[0], true, earth);

            cit = new GPConjunction();
            cit.setStartDate(date);
            for (n = 2; n < 8; n++)
            {
                cit.getPrev();
                R[n] = cit.getCurrentPosition();
            }
            // on Pratipat (nTithi == 15) we need to look for previous conjunction
            // but this conjunction can occur on this date before sunrise
            // so we need to include this very date into looking for conjunction
            // on other days we cannot include it
            // and exclude it from looking for next because otherwise that will cause
            // incorrect detection of Purusottama adhika masa

            /*L[2] = GPConjunction.GetPrevConjunction(date, ref C[2], false, earth);
             *
             * for (n = 3; n < PREV_MONTHS; n++)
             *  L[n] = GPConjunction.GetPrevConjunction(C[n - 1], ref C[n], true, earth);
             *
             * for (n = 0; n < PREV_MONTHS; n++)
             * {
             *  int nr = GPEngine.GetRasi(L[n], GPAyanamsa.GetAyanamsa(C[n].getJulianLocalNoon()));
             *  //if (nr != R[n])
             *  //    Debugger.Log(0, "", String.Format("Different rasi {0} <=> {1}  for input date: {2}", nr, R[n], date));
             *  R[n] = nr;
             * }*/

            /*	TRACE("TEST Date: %d %d %d\n", date.day, date.month, date.year);
             *  TRACE("FOUND CONJ Date: %d %d %d rasi: %d\n", C[1].day, C[1].month, C[1].year, R[1]);
             *  TRACE("FOUND CONJ Date: %d %d %d rasi: %d\n", C[2].day, C[2].month, C[2].year, R[2]);
             *  TRACE("FOUND CONJ Date: %d %d %d rasi: %d\n", C[3].day, C[3].month, C[3].year, R[3]);
             *  TRACE("FOUND CONJ Date: %d %d %d rasi: %d\n", C[4].day, C[4].month, C[4].year, R[4]);
             *  TRACE("---\n");
             */
            // test for Adhika-Ksaya sequence
            // this is like 1-2-2-4-5...
            // second (2) is replaced by rasi(3)

            /*	if ( ((Sank[1] + 2) % 12 == SankA) && ((Sank[1] == Sank[0]) || (Sank[0] == SankA)))
             *  {
             *      Sank[0] = (Sank[1] + 1) % 12;
             *  }
             *
             *  if ( ((Sank[2] + 2) % 12 == Sank[0]) && ((Sank[2] == Sank[1]) || (Sank[1] == Sank[0])))
             *  {
             *      Sank[1] = (Sank[2] + 1) % 12;
             *  }*/

            // look for ksaya month
            ksaya_from = -1;
            for (n = PREV_MONTHS - 2; n >= 0; n--)
            {
                if ((R[n + 1] + 2) % 12 == R[n])
                {
                    ksaya_from = n;
                    break;
                }
            }

            if (ksaya_from >= 0)
            {
                for (n = ksaya_from; n > 0; n--)
                {
                    if (R[n] == R[n - 1])
                    {
                        ksaya_to = n;
                        break;
                    }
                }

                if (ksaya_to >= 0)
                {
                    // adhika masa found
                    // now correct succession of rasis
                }
                else
                {
                    // adhika masa not found
                    // there will be some break in masa queue
                    ksaya_to = 0;
                }

                int current_rasi = R[ksaya_from + 1] + 1;
                for (n = ksaya_from; n >= ksaya_to; n--)
                {
                    R[n]         = current_rasi;
                    current_rasi = (current_rasi + 1) % 12;
                }
            }

            // STEP 3: test for adhika masa
            // test for adhika masa
            if (R[1] == R[2])
            {
                // it is adhika masa
                masa = 12;
                rasi = R[1];
            }
            else
            {
                // STEP 2. select nearest Conjunction
                if (day.nPaksa == 0)
                {
                    masa = R[1];
                }
                else if (day.nPaksa == 1)
                {
                    masa = R[2];
                }
                rasi = masa;
            }

            // calculation of Gaurabda year
            nGaurabdaYear = date.getYear() - 1486;

            if ((rasi > 7) && (rasi < 11)) // Visnu
            {
                if (date.getMonth() < 6)
                {
                    nGaurabdaYear--;
                }
            }


            return(masa);
        }
Beispiel #14
0
        public int CalcMasaList(GPLocationProvider loc, int nYear, int nCount)
        {
            GPMasaListResults mlist = this;
            GPAstroData       day   = new GPAstroData();
            GPGregorianTime   d     = new GPGregorianTime(loc);
            GPGregorianTime   de    = new GPGregorianTime(loc);
            GPGregorianTime   t     = new GPGregorianTime(loc);

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

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

            alloc(nCount);

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


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

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

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

            return(1);
        }
Beispiel #15
0
        public void calculateAppearanceDayData(GPLocationProvider aLocation, GPGregorianTime aEvente)
        {
            //MOONDATA moon;
            //SUNDATA sun;
            location = aLocation;
            evente   = new GPGregorianTime(aEvente);
            double          dd;
            GPAstroData     d     = details;
            GPGregorianTime vc    = evente;
            GPGregorianTime vcsun = evente;

            b_adhika = false;

            d.calculateDayData(aEvente, aLocation);
            //d.nTithi = GetPrevTithiStart(m_earth, vc, dprev);
            //GetNextTithiStart(m_earth, vc, dnext);
            //vcsun.setDayHours(vcsun.getDayHours() - vcsun.getTimeZoneOffsetHours() / 24.0);
            vcsun.normalizeValues();
            d.sun.calculateCoordinatesMethodC(vcsun, -1);
            d.moon.MoonCalc(vcsun.getJulianGreenwichTime());
            d.msDistance = GPMath.putIn360(d.moon.longitude_deg - d.sun.eclipticalLongitude - 180.0);
            d.msAyanamsa = GPAyanamsa.GetAyanamsa(vc.getJulianGreenwichTime());

            // tithi
            dd             = d.msDistance / 12.0;
            d.nTithi       = Convert.ToInt32(Math.Floor(dd));
            d.nTithiElapse = GPMath.frac(dd) * 100.0;
            d.nPaksa       = (d.nTithi >= 15) ? 1 : 0;


            // naksatra
            dd                = GPMath.putIn360(d.moon.longitude_deg - d.msAyanamsa);
            dd                = (dd * 3.0) / 40.0;
            d.nNaksatra       = Convert.ToInt32(Math.Floor(dd));
            d.nNaksatraElapse = GPMath.frac(dd) * 100.0;
            d.nMasa           = d.determineMasa(vc, out d.nGaurabdaYear);
            d.nMoonRasi       = GPEngine.GetRasi(d.moon.longitude_deg, d.msAyanamsa);
            d.nSunRasi        = GPEngine.GetRasi(d.sun.eclipticalLongitude, d.msAyanamsa);

            if (d.nMasa == GPMasa.ADHIKA_MASA)
            {
                d.nMasa  = GPEngine.GetRasi(d.sun.eclipticalLongitude, d.msAyanamsa);
                b_adhika = true;
            }
            string dstApplicable = "";

            //List<string> gstr = GPStrings.getSharedStrings().gstr;
            output.Add(new GPStringPair(GPStrings.getString(25), "", true));
            output.Add(new GPStringPair(GPStrings.getString(7), vc.ToString()));
            output.Add(new GPStringPair(GPStrings.getString(8), vc.getShortTimeString(true, ref dstApplicable)));
            output.Add(new GPStringPair(GPStrings.getString(9), vc.getLocation().getFullName()));
            //output.Add(new GPStringPair(gstr[10], vc.getLocation().getLatitudeString()));
            //output.Add(new GPStringPair(gstr[11], vc.getLocation().getLongitudeString()));
            //output.Add(new GPStringPair(gstr[12], vc.getLocation().getTimeZoneName()));
            //output.Add(new GPStringPair(gstr[1001], dstApplicable));
            output.Add(new GPStringPair(GPStrings.getString(13), GPTithi.getName(d.nTithi)));
            output.Add(new GPStringPair(GPStrings.getString(14), string.Format("{0:0.###} %", d.nTithiElapse)));
            output.Add(new GPStringPair(GPStrings.getString(15), GPNaksatra.getName(d.nNaksatra)));
            output.Add(new GPStringPair(GPStrings.getString(16), string.Format("{0:0.###} % ({1})", d.nNaksatraElapse, GPStrings.getString(811 + Convert.ToInt32(d.nNaksatraElapse / 25.0)))));
            output.Add(new GPStringPair(GPStrings.getString(991), GPSankranti.getName(d.nMoonRasi)));
            output.Add(new GPStringPair(GPStrings.getString(992), GPSankranti.getName(d.nSunRasi)));
            output.Add(new GPStringPair(GPStrings.getString(20), GPPaksa.getName(d.nPaksa)));
            if (b_adhika == true)
            {
                output.Add(new GPStringPair(GPStrings.getString(22), string.Format("{0} {1}", GPMasa.GetName(d.nMasa), GPStrings.getString(21))));
            }
            else
            {
                output.Add(new GPStringPair(GPStrings.getString(22), GPMasa.GetName(d.nMasa)));
            }
            output.Add(new GPStringPair(GPStrings.getString(23), d.nGaurabdaYear.ToString()));

            if (GPDisplays.AppDay.childNameSuggestions())
            {
                output.Add(new GPStringPair());
                output.Add(new GPStringPair(GPStrings.getString(17), "", true));
                output.Add(new GPStringPair());
                output.Add(new GPStringPair(GPStrings.getString(18), string.Format("{0}...", GPAppHelper.GetNaksatraChildSylable(d.nNaksatra, Convert.ToInt32(d.nNaksatraElapse / 25.0)))));
                output.Add(new GPStringPair(GPStrings.getString(19), string.Format("{0}...", GPAppHelper.GetRasiChildSylable(d.nMoonRasi))));
            }

            vc.Today();
            GPVedicTime     va = new GPVedicTime();
            GPGregorianTime vctemp;

            va.tithi = d.nTithi;
            va.masa  = d.nMasa;
            va.gyear = GPGaurabdaYear.getGaurabdaYear(vc, location);
            if (va.gyear < d.nGaurabdaYear)
            {
                va.gyear = d.nGaurabdaYear;
            }


            int countC = GPUserDefaults.IntForKey("appday.celebs", 3);

            if (countC > 0)
            {
                output.Add(new GPStringPair());
                output.Add(new GPStringPair(GPStrings.getString(24), "", true));
                output.Add(new GPStringPair());
            }

            int m = 0;

            for (int i = 0; i < 6; i++)
            {
                GPEngine.VATIMEtoVCTIME(va, out vctemp, location);
                if (va.gyear > d.nGaurabdaYear)
                {
                    if (m < countC)
                    {
                        output.Add(new GPStringPair(string.Format("{0} {1}", GPStrings.getString(994), va.gyear), vctemp.ToString()));
                        m++;
                    }
                }
                va.gyear++;
            }
        }
Beispiel #16
0
        public static int WriteXML_GaurabdaTithi(StringBuilder doc, GPLocationProvider loc, GPVedicTime vaStart, GPVedicTime vaEnd)
        {
            int gyearA = vaStart.gyear;
            int gyearB = vaEnd.gyear;
            int gmasa  = vaStart.masa;
            int gpaksa = vaStart.tithi / 15;
            int gtithi = vaStart.tithi % 15;

            if (gyearB < gyearA)
            {
                gyearB = gyearA;
            }



            doc.Append("<xml>\n");
            doc.Append("\t<request name=\"Tithi\" version=\"" + GPFileHelper.FileVersion + "\">\n");
            doc.Append("\t\t<arg name=\"longitude\" val=\"" + loc.getLocation(0).GetLongitudeEastPositive() + "\" />\n");
            doc.Append("\t\t<arg name=\"latitude\" val=\"" + loc.getLocation(0).GetLatitudeNorthPositive() + "\" />\n");
            doc.Append("\t\t<arg name=\"timezone\" val=\"" + loc.getLocation(0).getTimeZone().OffsetSeconds / 60 + "\" />\n");
            if (gyearA > 1500)
            {
                doc.Append("\t\t<arg name=\"year-start\" val=\"" + gyearA + "\" />\n");
                doc.Append("\t\t<arg name=\"year-end\" val=\"" + gyearB + "\" />\n");
            }
            else
            {
                doc.Append("\t\t<arg name=\"gaurabdayear-start\" val=\"" + gyearA + "\" />\n");
                doc.Append("\t\t<arg name=\"gaurabdayear-end\" val=\"" + gyearB + "\" />\n");
            }
            doc.Append("\t\t<arg name=\"masa\" val=\"" + gmasa + "\" />\n");
            doc.Append("\t\t<arg name=\"paksa\" val=\"" + gpaksa + "\" />\n");
            doc.Append("\t\t<arg name=\"tithi\" val=\"" + gtithi + "\" />\n");
            doc.Append("\t</request>\n");
            doc.Append("\t<result name=\"Tithi\">\n");


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

            if (gyearA > 1500)
            {
                A = gyearA - 1487;
                B = gyearB - 1485;
            }
            else
            {
                A = gyearA;
                B = gyearB;
            }

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


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

            return(1);
        }
Beispiel #17
0
        /*********************************************************************/
        /*  Calculates Date of given Tithi                                   */
        /*********************************************************************/

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

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

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

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

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

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

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

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

            // now we know the type of day-accurancy
            // nType = 0 means, that we dont found a day
            // nType = 1 means, we find day, when tithi was present at sunrise
            // nType = 2 means, we found day, when tithi started after sunrise
            //                  but ended before next sunrise
            //
        }