Ejemplo n.º 1
0
        public static int writeFirstDayXml(string fileName, GCLocation loc, GregorianDateTime vcStart)
        {
            using (StreamWriter xml = new StreamWriter(fileName))
            {
                vcStart.Set(GCAstroData.GetFirstDayOfYear(loc.GetEarthData(), vcStart.year));
                vcStart.InitWeekDay();

                // write
                xml.Write("<xml>\n");
                xml.Write("\t<request name=\"FirstDay\" version=\"");
                xml.Write(GCStrings.RawVersionNumber);
                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=\"year\" val=\"");
                xml.Write(vcStart.year);
                xml.Write("\" />\n");
                xml.Write("\t</request>\n");
                xml.Write("\t<result name=\"FirstDay_of_GaurabdaYear\">\n");
                xml.Write("\t\t<firstday date=\"");
                xml.Write(vcStart);
                xml.Write("\" dayweekid = \"");
                xml.Write(vcStart.dayOfWeek);
                xml.Write("\" dayweek=\"");
                xml.Write(GCCalendar.GetWeekdayName(vcStart.dayOfWeek));
                xml.Write("\" />\n");
                xml.Write("\t</result>\n");
                xml.Write("</xml>\n");
            }
            return(0);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public static int GetGaurabdaYear(GregorianDateTime vc, GCEarthData earth)
        {
            GCAstroData day = new GCAstroData();

            day.DayCalc(vc, earth);
            day.MasaCalc(vc, earth);

            return(day.GaurabdaYear);
        }
Ejemplo n.º 4
0
        /*********************************************************************/
        /* Finds starting and ending time for given tithi                    */
        /*                                                                   */
        /* tithi is specified by Gaurabda year, masa, paksa and tithi number */
        /*      nGYear - 0..9999                                             */
        /*       nMasa - 0..12, 0-Madhusudana, 1-Trivikrama, 2-Vamana        */
        /*                      3-Sridhara, 4-Hrsikesa, 5-Padmanabha         */
        /*                      6-Damodara, 7-Kesava, 8-narayana, 9-Madhava  */
        /*                      10-Govinda, 11-Visnu, 12-PurusottamaAdhika   */
        /*       nPaksa -       0-Krsna, 1-Gaura                             */
        /*       nTithi - 0..14                                              */
        /*       earth  - used timezone                                      */
        /*                                                                   */
        /*********************************************************************/

        public static GregorianDateTime CalcTithiEnd(int nGYear, int nMasa, int nPaksa, int nTithi, GCEarthData earth, out GregorianDateTime endTithi)
        {
            GregorianDateTime d = new GregorianDateTime();

            d.Set(GCAstroData.GetFirstDayOfYear(earth, nGYear + 1486));
            d.shour         = 0.5;
            d.TimezoneHours = earth.OffsetUtcHours;

            return(CalcTithiEndEx(d, nGYear, nMasa, nPaksa, nTithi, earth, out endTithi));
        }
Ejemplo n.º 5
0
        //===========================================================================
        //
        //===========================================================================

        public static void VCTIMEtoVATIME(GregorianDateTime vc, out GaurabdaDate va, GCEarthData earth)
        {
            GCAstroData day = new GCAstroData();

            day.DayCalc(vc, earth);
            va       = new GaurabdaDate();
            va.masa  = day.MasaCalc(vc, earth);
            va.tithi = day.sunRise.Tithi;
            va.gyear = day.GaurabdaYear;
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public static int writeGaurabdaTithiXml(string fileName, GCLocation loc, GaurabdaDate vaStart, GaurabdaDate 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;
            }

            using (StreamWriter xml = new StreamWriter(fileName))
            {
                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");
                if (gyearA > 1500)
                {
                    xml.Write("\t\t<arg name=\"year-start\" val=\"");
                    xml.Write(gyearA);
                    xml.Write("\" />\n");
                    xml.Write("\t\t<arg name=\"year-end\" val=\"");
                    xml.Write(gyearB);
                    xml.Write("\" />\n");
                }
                else
                {
                    xml.Write("\t\t<arg name=\"gaurabdayear-start\" val=\"");
                    xml.Write(gyearA);
                    xml.Write("\" />\n");
                    xml.Write("\t\t<arg name=\"gaurabdayear-end\" val=\"");
                    xml.Write(gyearB);
                    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();
                GCHourTime        sun = new GCHourTime();
                int         A, B;
                double      sunrise;
                GCAstroData day = new GCAstroData();
                int         oTithi, oPaksa, oMasa, oYear;

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

                for (; A <= B; A++)
                {
                    vcs.Set(GCTithi.CalcTithiEnd(A, gmasa, gpaksa, gtithi, earth, out vce));
                    if (gyearA > 1500)
                    {
                        if ((vcs.year < gyearA) || (vcs.year > gyearB))
                        {
                            continue;
                        }
                    }
                    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;
                    sun         = GCSunData.CalcSunrise(today, earth);
                    sunrise     = sun.TotalDays;
                    if (sunrise < vcs.shour)
                    {
                        today.Set(vce);
                        sun     = GCSunData.CalcSunrise(today, earth);
                        sunrise = sun.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);
                        sun = GCSunData.CalcSunrise(today, earth);
                        if (sun.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");
                }

                xml.Write("\t</result>\n");
                xml.Write("</xml>\n");
            }
            return(1);
        }
Ejemplo n.º 8
0
        public static int writeXml(string fileName, GCLocation loc, GregorianDateTime vc)
        {
            String            str;
            GregorianDateTime date;

            using (StreamWriter xml = new StreamWriter(fileName))
            {
                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=\"startdate\" val=\"");
                xml.Write(vc);
                xml.Write("\" />\n");
                xml.Write("\t</request>\n");
                xml.Write("\t<result name=\"Tithi\">\n");

                GregorianDateTime d = new GregorianDateTime();
                d.Set(vc);
                GregorianDateTime d1, d2;
                d.TimezoneHours = loc.OffsetUtcHours;
                GregorianDateTime dn;
                GCHourTime        dt    = new GCHourTime();
                GCEarthData       earth = loc.GetEarthData();


                GCAstroData day = new GCAstroData();

                day.DayCalc(vc, earth);

                d.shour = day.sunRise.TotalDays;

                GCTithi.GetPrevTithiStart(earth, d, out d1);
                GCTithi.GetNextTithiStart(earth, d, out d2);

                {
                    dt.SetDegTime(d1.shour * 360);
                    // start tithi at t[0]
                    xml.Write("\t\t<tithi\n\t\t\tid=\"");
                    xml.Write(day.sunRise.Tithi);
                    xml.Write("\"\n");
                    xml.Write("\t\t\tname=\"");
                    xml.Write(GCTithi.GetName(day.sunRise.Tithi));
                    xml.Write("\"\n");
                    xml.Write("\t\t\tstartdate=\"");
                    xml.Write(d1);
                    xml.Write("\"\n");
                    xml.Write("\t\t\tstarttime=\"");
                    xml.Write(dt);
                    xml.Write("\"\n");

                    dt.SetDegTime(d2.shour * 360);
                    xml.Write("\t\t\tenddate=\"");
                    xml.Write(d2);
                    xml.Write("\"\n");
                    xml.Write("\t\t\tendtime=\"");
                    xml.Write(dt);
                    xml.Write("\"\n />");
                }

                xml.Write("\t</result>\n");
                xml.Write("</xml>\n");
            }
            return(1);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        public void calculateAppDay(GCLocation location, GregorianDateTime eventDate)
        {
            //MOONDATA moon;
            //SUNDATA sun;
            GCAstroData       d       = this.details = new GCAstroData();
            GregorianDateTime vc      = new GregorianDateTime();
            GregorianDateTime vcsun   = new GregorianDateTime();
            GCEarthData       m_earth = location.GetEarthData();

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

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

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

            // tithi


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

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

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

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

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

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

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

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


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

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