public static void Report(GPLocationProvider loc, string prefix) { GPGregorianTime start = new GPGregorianTime(loc); GPGregorianTime end = new GPGregorianTime(loc); start.setDate(2010, 1, 1); end.setDate(2015, 1, 1); GPCalendarResults calendar = new GPCalendarResults(); calendar.CalculateCalendar(start, Convert.ToInt32(end.getJulianLocalNoon() - start.getJulianLocalNoon())); GPCoreEventResults coreEvents = new GPCoreEventResults(); coreEvents.Sort(false); coreEvents.CalculateEvents(loc, start, end); string path = "d:\\gcal\\reports\\"; if (Directory.Exists(path)) { File.WriteAllText(Path.Combine(path, prefix + "-cal-" + loc.getCity() + ".txt"), FormaterInternal.getInternalDalendarData(calendar)); File.WriteAllText(Path.Combine(path, prefix + "-eve-" + loc.getCity() + ".txt"), FormaterInternal.getInternalEventsText(coreEvents)); } }
public void CalculateEvents(GPLocationProvider loc, GPGregorianTime vcStart, GPGregorianTime vcEnd) { GPCoreEventResults inEvents = this; GPLocationProvider earth = loc; GPGregorianTime vc = new GPGregorianTime(loc); GPSun sun = new GPSun(); //int ndst = 0; int nData; inEvents.clear(); inEvents.m_location = loc; inEvents.m_vcStart = vcStart; inEvents.m_vcEnd = vcEnd; GPGregorianTime vcAdd = new GPGregorianTime(loc); GPGregorianTime vcTemp = null; GPGregorianTime vcNext = new GPGregorianTime(loc); vc.Copy(vcStart); if (GPDisplays.CoreEvents.Sunrise()) { vcAdd.Copy(vc); while (vcAdd.IsBeforeThis(vcEnd)) { sun.SunCalc(vcAdd, earth); vcTemp = new GPGregorianTime(sun.arunodaya); inEvents.AddEvent(vcTemp, GPConstants.CCTYPE_S_ARUN, 0); //GPJulianTime tr, tt, ts; //GPAstroEngine.CalculateTimeSun(vcTemp, vcTemp.getLocation(), out tr, out tt, out ts); vcTemp = new GPGregorianTime(sun.rise); //vcTemp = new GPGregorianTime(vcTemp.getLocation(), tr); inEvents.AddEvent(vcTemp, GPConstants.CCTYPE_S_RISE, 0); vcTemp = new GPGregorianTime(sun.noon); //vcTemp = new GPGregorianTime(vcTemp.getLocation(), tt); inEvents.AddEvent(vcTemp, GPConstants.CCTYPE_S_NOON, 0); vcTemp = new GPGregorianTime(sun.set); //vcTemp = new GPGregorianTime(vcTemp.getLocation(), ts); inEvents.AddEvent(vcTemp, GPConstants.CCTYPE_S_SET, 0); vcAdd.NextDay(); } } if (GPDisplays.CoreEvents.Tithi()) { GPTithi te = new GPTithi(); te.setStartDate(vc); vcAdd = te.getNext(); while (vcAdd.IsBeforeThis(vcEnd)) { nData = te.getCurrentPosition(); //ndst = loc.getTimeZone().GetDaylightChangeType(vcNext); inEvents.AddEvent(vcAdd, GPConstants.CCTYPE_TITHI, nData); vcAdd = te.getNext(); } } if (GPDisplays.CoreEvents.Naksatra()) { GPNaksatra te = new GPNaksatra(); te.setStartDate(vc); vcAdd = te.getNext(); while (vcAdd.IsBeforeThis(vcEnd)) { nData = te.getCurrentNaksatra(); //ndst = loc.getTimeZone().GetDaylightChangeType(vcNext); inEvents.AddEvent(vcAdd, GPConstants.CCTYPE_NAKS, nData); vcAdd = te.getNext(); } } if (GPDisplays.CoreEvents.Sankranti()) { GPSankranti te = new GPSankranti(); te.setStartDate(vc); vcAdd = te.getNext(); while (vcAdd.IsBeforeThis(vcEnd)) { nData = te.getCurrentPosition(); //ndst = loc.getTimeZone().GetDaylightChangeType(vcNext); inEvents.AddEvent(vcAdd, GPConstants.CCTYPE_SANK, nData); vcAdd = te.getNext(); } } if (GPDisplays.CoreEvents.Conjunction()) { double[] times = null; GPConjunction te = new GPConjunction(); te.setStartDate(vc); vcAdd = te.getNext(); while (vcAdd.IsBeforeThis(vcEnd)) { nData = te.getCurrentPosition(); //ndst = loc.getTimeZone().GetDaylightChangeType(vcNext); inEvents.AddEvent(vcAdd, GPConstants.CCTYPE_CONJ, nData); if (GPDisplays.CoreEvents.SunEclipse()) { GPAstroEngine.CalculateTimesSunEclipse(vcAdd.getJulianGreenwichTime(), vcAdd.getLocation(), out times); if (times != null && times[2] > 0) { for (int i = 0; i < 5; i++) { if (times[i] > 0) { GPGregorianTime gt = new GPGregorianTime(vcAdd.getLocation()); gt.setJulianGreenwichTime(new GPJulianTime(times[i], 0.0)); inEvents.AddEvent(gt, GPConstants.SUNECLIPSE_CONSTS[i], 0); } } } } vcAdd = te.getNext(); } } // moon eclipses if (GPDisplays.CoreEvents.MoonEclipse()) { double[] times = null; GPConjunction te = new GPConjunction(); te.setOpositeConjunction(true); te.setStartDate(vc); vcAdd = te.getNext(); while (vcAdd.IsBeforeThis(vcEnd)) { GPAstroEngine.CalculateTimesMoonEclipse(vcAdd.getJulianGreenwichTime(), vcAdd.getLocation(), out times); if (times != null && times[4] > 0) { for (int i = 0; i < 9; i++) { if (times[i] > 0 && GPConstants.MOONECLIPSE_CONSTS[i] > 0) { GPGregorianTime gt = new GPGregorianTime(vcAdd.getLocation()); gt.setJulianGreenwichTime(new GPJulianTime(times[i], 0.0)); inEvents.AddEvent(gt, GPConstants.MOONECLIPSE_CONSTS[i], 0); } } } vcAdd = te.getNext(); } } // rise and set of the moon if (GPDisplays.CoreEvents.Moonrise()) { GPJulianTime julian = vc.getJulian(); GPJulianTime julianEnd = vcEnd.getJulian(); GPJulianTime nextJulian; TRiseSet kind; while (julian.getGreenwichJulianDay() < julianEnd.getGreenwichJulianDay()) { nextJulian = GPAstroEngine.GetNextMoonEvent(julian, vc.getLocationProvider(), out kind); if (kind == TRiseSet.RISE) { inEvents.AddEvent(new GPGregorianTime(loc, nextJulian), GPConstants.CoreEventMoonRise, 0); } else if (kind == TRiseSet.SET) { inEvents.AddEvent(new GPGregorianTime(loc, nextJulian), GPConstants.CoreEventMoonSet, 0); } julian.setGreenwichJulianDay(nextJulian.getGreenwichJulianDay() + 10.0 / 1440.0); } } // travellings { GPJulianTime julian = vc.getJulian(); GPJulianTime julianEnd = vcEnd.getJulian(); double start, end; start = julian.getGreenwichJulianDay(); end = julianEnd.getGreenwichJulianDay(); for (int i = 0; i < loc.getChangeCount(); i++) { GPLocationChange chn = loc.getChangeAtIndex(i); if ((chn.julianStart >= start && chn.julianStart <= end) || (chn.julianStart >= start && chn.julianEnd <= end)) { GPGregorianTime startTime = new GPGregorianTime(chn.LocationA); startTime.setJulianGreenwichTime(new GPJulianTime(chn.julianStart, 0)); GPGregorianTime endTime = new GPGregorianTime(chn.LocationB); endTime.setJulianGreenwichTime(new GPJulianTime(chn.julianEnd, 0)); inEvents.AddEvent(startTime, GPConstants.CCTYPE_TRAVELLING_START, 0); inEvents.AddEvent(endTime, GPConstants.CCTYPE_TRAVELLING_END, 0); } } } // eventual sorting inEvents.Sort(GPDisplays.CoreEvents.Sort()); }
public static int FormatCalendarPlusCorePlain(GPCalendarPlusEventsResults calev, StringBuilder fout) { GPCalendarResults daybuff = calev.theCalendar; GPCoreEventResults events = calev.theEvents; //List<string> gstr = GPStrings.getSharedStrings().gstr; int k; string str; GPGregorianTime date = new GPGregorianTime(daybuff.CurrentLocation); GPCalendarDay pvd; GPCalendarDay prevd; GPCalendarDay nextd; int nPrevMasa = -1; int nPrevMonth = -1; if (events.b_sorted == false) { events.Sort(true); } StringBuilder lineA = new StringBuilder(); StringBuilder lineB = new StringBuilder(); for (k = 0; k < daybuff.getCount(); k++) { prevd = daybuff.get(k - 1); pvd = daybuff.get(k); nextd = daybuff.get(k + 1); if (pvd != null) { bool writeHeaders = false; if (nPrevMasa != pvd.astrodata.nMasa && GPDisplays.Calendar.MasaHeader()) { str = string.Format("{0} {1}", pvd.getMasaLongName(), ((nPrevMasa == GPMasa.ADHIKA_MASA) ? GPStrings.getString(109) : "")); fout.AppendLine(GPAppHelper.CenterString(str, 80)); fout.AppendLine(GPAppHelper.CenterString(pvd.getGaurabdaYearLongString(), 80)); fout.AppendLine(GPAppHelper.CenterString(pvd.date.getLocation().getFullName(), 80)); fout.AppendLine(GPAppHelper.CenterString(string.Format("{0}: {1}", GPStrings.getString(12), pvd.date.getLocation().getTimeZone().getFullName()), 80)); fout.AppendLine(); nPrevMasa = pvd.astrodata.nMasa; writeHeaders = true; } else if (nPrevMonth != pvd.date.getMonth() && GPDisplays.Calendar.MonthHeader()) { fout.AppendLine(GPAppHelper.CenterString(string.Format("{0} {1}", GPStrings.getString(759 + pvd.date.getMonth()), pvd.date.getYear()), 80)); fout.AppendLine(GPAppHelper.CenterString(pvd.date.getLocation().getFullName(), 80)); fout.AppendLine(GPAppHelper.CenterString(string.Format("{0}: {1}", GPStrings.getString(12), pvd.date.getLocation().getTimeZone().getFullName()), 80)); fout.AppendLine(); nPrevMonth = pvd.date.getMonth(); writeHeaders = true; } if (writeHeaders) { int len = fout.Length; fout.Append(" "); fout.Append(GPStrings.getString(985).PadRight(16)); fout.Append(GPStrings.getString(986).ToUpper().PadRight(30)); if (GPDisplays.Calendar.PaksaInfoVisible()) { fout.Append(GPStrings.getString(20).ToUpper().PadRight(6)); } else { fout.Append(string.Empty.PadRight(6)); } if (GPDisplays.Calendar.YogaVisible()) { fout.Append(GPStrings.getString(104).ToUpper().PadRight(10)); } if (GPDisplays.Calendar.NaksatraVisible()) { fout.Append(GPStrings.getString(15).ToUpper().PadRight(15)); } if (GPDisplays.Calendar.FastingFlagVisible()) { fout.Append(GPStrings.getString(987).ToUpper().PadRight(5)); } if (GPDisplays.Calendar.RasiVisible()) { fout.Append(GPStrings.getString(105).ToUpper().PadRight(15)); } fout.AppendLine(); len = fout.Length - len; fout.AppendLine(string.Empty.PadLeft(len, '-')); } AvcGetOldCalendarDayText(pvd, fout, prevd, nextd); fout.AppendLine(); lineA.Remove(0, lineA.Length); lineB.Remove(0, lineB.Length); List <GPStringPair> recs = events.ExtractRecordsForDate(pvd.date); foreach (GPStringPair rec in recs) { lineA.Append(rec.Name); lineB.Append(rec.Value); int tosize = Math.Max(lineA.Length, lineB.Length) + 2; while (lineA.Length < tosize) { lineA.Append(' '); } while (lineB.Length < tosize) { lineB.Append(' '); } } fout.Append(string.Empty.PadLeft(17, ' ')); fout.AppendLine(lineA.ToString()); fout.Append(string.Empty.PadLeft(17, ' ')); fout.AppendLine(lineB.ToString()); fout.AppendLine(); } date.setDayHours(0.0); date.NextDay(); } return(1); }