예제 #1
0
        public bool LoadFile(string filePath)
        {
            try
            {
                using (Stream s = File.OpenRead(filePath))
                {
                    using (BinaryReader br = new BinaryReader(s))
                    {
                        p_events.Clear();
                        byte b = br.ReadByte();
                        if (b == 1) // read version 1
                        {
                            b = br.ReadByte();
                            while (b != 0)
                            {
                                switch (b)
                                {
                                case 10:     // tag for year
                                    Year = br.ReadInt32();
                                    break;

                                case 60:     // tag for core event
                                    TCoreEvent ce = new TCoreEvent();
                                    ce.nType = br.ReadByte();
                                    ce.nData = br.ReadByte();
                                    ce.nDst  = br.ReadByte();
                                    ce.Time  = br.ReadInt64();
                                    p_events.Add(ce);
                                    break;

                                default:
                                    break;
                                }
                                b = br.ReadByte();
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                GCLog.Write("Error during loading CoreEvents file.");
                GCLog.Write(ex.Message);
                return(false);
            }
        }
예제 #2
0
        public bool SaveFile(string filePath)
        {
            try
            {
                using (Stream s = File.OpenWrite(filePath))
                {
                    using (BinaryWriter bw = new BinaryWriter(s))
                    {
                        // signature of version
                        bw.Write((byte)1);

                        // tag 10 for year
                        bw.Write((byte)10);
                        bw.Write((int)Year);

                        foreach (TCoreEvent ce in p_events)
                        {
                            // tag 60 for record of event
                            bw.Write((byte)60);
                            // write one day event
                            bw.Write(ce.nType);
                            bw.Write(ce.nData);
                            bw.Write(ce.nDst);
                            bw.Write(ce.Time);
                        }

                        // end tag
                        bw.Write((byte)0);
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                GCLog.Write("Error during saving CoreEvents file.");
                GCLog.Write(e.Message);
                return(false);
            }
        }
예제 #3
0
        /*
         * Function before is writen accoring this algorithms:
         *
         *
         *  1. Normal - fasting day has ekadasi at sunrise and dvadasi at next sunrise.
         *
         *  2. Viddha - fasting day has dvadasi at sunrise and trayodasi at next
         *  sunrise, and it is not a naksatra mahadvadasi
         *
         *  3. Unmilani - fasting day has ekadasi at both sunrises
         *
         *  4. Vyanjuli - fasting day has dvadasi at both sunrises, and it is not a
         *  naksatra mahadvadasi
         *
         *  5. Trisprsa - fasting day has ekadasi at sunrise and trayodasi at next
         *  sunrise.
         *
         *  6. Jayanti/Vijaya - fasting day has gaura dvadasi and specified naksatra at
         *  sunrise and same naksatra at next sunrise
         *
         *  7. Jaya/Papanasini - fasting day has gaura dvadasi and specified naksatra at
         *  sunrise and same naksatra at next sunrise
         *
         *  ==============================================
         *  Case 1 Normal (no change)
         *
         *  If dvadasi tithi ends before 1/3 of daylight
         *     then PARANA END = TIME OF END OF TITHI
         *  but if dvadasi TITHI ends after 1/3 of daylight
         *     then PARANA END = TIME OF 1/3 OF DAYLIGHT
         *
         *  if 1/4 of dvadasi tithi is before sunrise
         *     then PARANA BEGIN is sunrise time
         *  but if 1/4 of dvadasi tithi is after sunrise
         *     then PARANA BEGIN is time of 1/4 of dvadasi tithi
         *
         *  if PARANA BEGIN is before PARANA END
         *     then we will write "BREAK FAST FROM xx TO yy
         *  but if PARANA BEGIN is after PARANA END
         *     then we will write "BREAK FAST AFTER xx"
         *
         *  ==============================================
         *  Case 2 Viddha
         *
         *  If trayodasi tithi ends before 1/3 of daylight
         *     then PARANA END = TIME OF END OF TITHI
         *  but if trayodasi TITHI ends after 1/3 of daylight
         *     then PARANA END = TIME OF 1/3 OF DAYLIGHT
         *
         *  PARANA BEGIN is sunrise time
         *
         *  we will write "BREAK FAST FROM xx TO yy
         *
         *  ==============================================
         *  Case 3 Unmilani
         *
         *  PARANA END = TIME OF 1/3 OF DAYLIGHT
         *
         *  PARANA BEGIN is end of Ekadasi tithi
         *
         *  if PARANA BEGIN is before PARANA END
         *     then we will write "BREAK FAST FROM xx TO yy
         *  but if PARANA BEGIN is after PARANA END
         *     then we will write "BREAK FAST AFTER xx"
         *
         *  ==============================================
         *  Case 4 Vyanjuli
         *
         *  PARANA BEGIN = Sunrise
         *
         *  PARANA END is end of Dvadasi tithi
         *
         *  we will write "BREAK FAST FROM xx TO yy
         *
         *  ==============================================
         *  Case 5 Trisprsa
         *
         *  PARANA BEGIN = Sunrise
         *
         *  PARANA END = 1/3 of daylight hours
         *
         *  we will write "BREAK FAST FROM xx TO yy
         *
         *  ==============================================
         *  Case 6 Jayanti/Vijaya
         *
         *  PARANA BEGIN = Sunrise
         *
         *  PARANA END1 = end of dvadasi tithi or sunrise, whichever is later
         *  PARANA END2 = end of naksatra
         *
         *  PARANA END is earlier of END1 and END2
         *
         *  we will write "BREAK FAST FROM xx TO yy
         *
         *  ==============================================
         *  Case 7 Jaya/Papanasini
         *
         *  PARANA BEGIN = end of naksatra
         *
         *  PARANA END = 1/3 of Daylight hours
         *
         *  if PARANA BEGIN is before PARANA END
         *     then we will write "BREAK FAST FROM xx TO yy
         *  but if PARANA BEGIN is after PARANA END
         *     then we will write "BREAK FAST AFTER xx"
         *
         *
         * */
        public int CalculateEParana(GCEarthData earth)
        {
            VAISNAVADAY t = this;

            if (t.Previous == null)
            {
                return(0);
            }

            t.nMahadvadasiID = MahadvadasiType.EV_NULL;
            t.ekadasi_parana = true;
            t.nFastID        = FastType.FAST_NULL;

            TCoreEvent naksEnd;
            TCoreEvent parBeg     = null;
            TCoreEvent parEnd     = null;
            TCoreEvent tithiStart = null;
            TCoreEvent tithiEnd   = null;
            TCoreEvent sunRise    = t.FindCoreEvent(CoreEventType.CCTYPE_S_RISE);
            TCoreEvent sunSet     = t.FindCoreEvent(CoreEventType.CCTYPE_S_SET);

            if (sunRise == null || sunSet == null)
            {
                GCLog.Write("Cannot find sunrise of sunset for day " + t.date.ToString());
                return(0);
            }

            TCoreEvent third_day = new TCoreEvent()
            {
                nData = sunRise.nData,
                nType = CoreEventType.CCTYPE_THIRD_OF_DAY,
                nDst  = sunRise.nDst,
                Time  = (sunSet.Time - sunRise.Time) / 3 + sunRise.Time
            };

            List <CoreEventFindRec> tempTimes = GetRecentCoreTimes(CoreEventType.CCTYPE_S_RISE, CoreEventType.CCTYPE_TITHI, 1);

            if (tempTimes.Count != 1)
            {
                GCLog.Write("Start or End of tithi was not found for date " + t.ToString());
                return(0);
            }
            else
            {
                tithiStart = tempTimes[0].coreEvent;
            }

            tempTimes = GetNextCoreTimes(CoreEventType.CCTYPE_S_RISE, CoreEventType.CCTYPE_TITHI, 1);
            if (tempTimes.Count != 1)
            {
                GCLog.Write("End of tithi was not found for date " + t.ToString());
                tempTimes = GetNextCoreTimes(CoreEventType.CCTYPE_S_RISE, CoreEventType.CCTYPE_TITHI, 1);
                return(0);
            }
            else
            {
                tithiEnd = new TCoreEvent(tempTimes[0].coreEvent)
                {
                    nType = CoreEventType.CCTYPE_TITHI_END
                };
                tithiEnd.ApplyDstType(UtcDayStart, DstDayType);
            }

            if (Previous == null)
            {
                return(0);
            }

            tempTimes = Previous.GetNextCoreTimes(CoreEventType.CCTYPE_S_RISE, CoreEventType.CCTYPE_NAKS, 1);
            if (tempTimes.Count != 1)
            {
                GCLog.Write("End of naksatra was not found for date " + t.ToString());
                return(0);
            }
            else
            {
                naksEnd = new TCoreEvent(tempTimes[0].coreEvent)
                {
                    nType = CoreEventType.CCTYPE_NAKS_END
                };
                naksEnd.ApplyDstType(UtcDayStart, DstDayType);
            }

            TCoreEvent tithi_quart = new TCoreEvent()
            {
                nType = CoreEventType.CCTYPE_TITHI_QUARTER,
                nData = tithiStart.nData,
                Time  = (tithiEnd.Time - tithiStart.Time) / 4 + tithiStart.Time,
                nDst  = tithiStart.nDst
            };

            tithi_quart.ApplyDstType(UtcDayStart, DstDayType);


            switch (t.Previous.nMahadvadasiID)
            {
            case MahadvadasiType.EV_UNMILANI:
                parEnd = GCMath.Min(tithiEnd, third_day);
                parBeg = sunRise;
                break;

            case MahadvadasiType.EV_VYANJULI:
                parBeg = sunRise;
                parEnd = GCMath.Min(tithiEnd, third_day);
                break;

            case MahadvadasiType.EV_TRISPRSA:
                parBeg = sunRise;
                parEnd = third_day;
                break;

            case MahadvadasiType.EV_JAYANTI:
            case MahadvadasiType.EV_VIJAYA:
                if (GCTithi.TITHI_DVADASI(t.astrodata.sunRise.Tithi))
                {
                    if (naksEnd.Time < tithiEnd.Time)
                    {
                        if (naksEnd.Time < third_day.Time)
                        {
                            parBeg = naksEnd;
                            parEnd = GCMath.Min(tithiEnd, third_day);
                        }
                        else
                        {
                            parBeg = naksEnd;
                            parEnd = tithiEnd;
                        }
                    }
                    else
                    {
                        parBeg = sunRise;
                        parEnd = GCMath.Min(tithiEnd, third_day);
                    }
                }
                else
                {
                    parBeg = sunRise;
                    parEnd = GCMath.Min(naksEnd, third_day);
                }

                break;

            case MahadvadasiType.EV_JAYA:
            case MahadvadasiType.EV_PAPA_NASINI:
                if (GCTithi.TITHI_DVADASI(t.astrodata.sunRise.Tithi))
                {
                    if (naksEnd.Time < tithiEnd.Time)
                    {
                        if (naksEnd.Time < third_day.Time)
                        {
                            parBeg = naksEnd;
                            parEnd = GCMath.Min(tithiEnd, third_day);
                        }
                        else
                        {
                            parBeg = naksEnd;
                            parEnd = tithiEnd;
                        }
                    }
                    else
                    {
                        parBeg = sunRise;
                        parEnd = GCMath.Min(tithiEnd, third_day);
                    }
                }
                else
                {
                    if (naksEnd.Time < third_day.Time)
                    {
                        parBeg = naksEnd;
                        parEnd = third_day;
                    }
                    else
                    {
                        parBeg = naksEnd;
                        parEnd = null;
                    }
                }

                break;

            default:
                // first initial
                parEnd = GCMath.Min(tithiEnd, third_day);
                parBeg = GCMath.Max(sunRise, tithi_quart);
                if (GCTithi.TITHI_DVADASI(t.Previous.astrodata.sunRise.Tithi))
                {
                    parBeg = sunRise;
                }

                break;
            }

            if (parBeg.Time >= parEnd.Time)
            {
                parEnd = null;
            }

            t.eparana_time1 = parBeg;
            t.eparana_time2 = parEnd;

            return(1);
        }