Exemple #1
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);
        }
Exemple #2
0
        public static int GetGaurabdaYear(GregorianDateTime vc, GCEarthData earth)
        {
            GCAstroData day = new GCAstroData();

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

            return(day.GaurabdaYear);
        }
Exemple #3
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;
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
Exemple #8
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);
        }
        /// <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);
        }