/// <summary> /// this will move date to the nearest conjunction /// whether it is in future or in the past /// </summary> /// <returns></returns> protected GPGregorianTime movePosition() { double position = 0; double diff; double seconds = 0.5 / 86400.0; double prevSeconds = -1; for (int i = 0; i < 10; i++) { position = calculatePosition() / 360; if (Math.Abs(pJulianDate - prevSeconds) < seconds) { break; } prevSeconds = pJulianDate; diff = position * 30; pJulianDate -= diff; pStartDate.addDayHours(diff); } GPGregorianTime nt = new GPGregorianTime(pStartDate.getLocation()); nt.setJulianGreenwichTime(new GPJulianTime(GPAstroEngine.ConvertDynamicToUniversal(pJulianDate), 0.0)); return(nt); }
public static int WriteXML_FirstDay_Year(StringBuilder doc, GPGregorianTime vcStart) { vcStart = GPGaurabdaYear.getFirstDayOfYear(vcStart.getLocationProvider(), vcStart.getYear()); // write doc.Append("<xml>\n"); doc.Append("\t\t<arg name=\"longitude\" val=\"" + vcStart.getLocation().GetLongitudeEastPositive() + "\" />\n"); doc.Append("\t\t<arg name=\"latitude\" val=\"" + vcStart.getLocation().GetLatitudeNorthPositive() + "\" />\n"); doc.Append("\t\t<arg name=\"year\" val=\"" + vcStart.getYear() + "\" />\n"); doc.Append("\t</request>\n"); doc.Append("\t<result name=\"FirstDay_of_GaurabdaYear\">\n"); doc.Append("\t\t<firstday date=\"" + vcStart + "\" dayweekid = \"" + vcStart.getDayOfWeek() + "\" dayweek=\"" + getSharedStringHtml(vcStart.getDayOfWeek()) + "\" />\n"); doc.Append("\t</result>\n"); doc.Append("</xml>\n"); return(0); }
public GPGregorianTime movePosition(int dir) { double unitLength = getUnitAverageLength(); int unitCount = getUnitCount(); double lowerLimit = 0.5; double upperLimit = unitCount - 0.5; double position = 0; bool over = false; bool under = false; double nextTithi = getCurrentPosition() + dir; double diff; double seconds = 0.5 / 86400.0; double prevSeconds = -1; if (dir > 0) { over = (nextTithi > upperLimit); under = (currentPosition < lowerLimit); } else { over = (currentPosition > upperLimit); under = (nextTithi < lowerLimit); } for (int i = 0; i < 10; i++) { position = calculatePosition(); //seconds = Convert.ToInt32((pJulianDate - Math.Floor(pJulianDate)) * 86400); if (Math.Abs(pJulianDate - prevSeconds) < seconds) { break; } if (over && position < lowerLimit) { position += unitCount; } else if (under && position > upperLimit) { position -= unitCount; } prevSeconds = pJulianDate; diff = (nextTithi - position) * unitLength; pJulianDate += diff; pStartDate.addDayHours(diff); } currentPosition = Convert.ToInt32(nextTithi) % unitCount; GPGregorianTime nt = new GPGregorianTime(pStartDate.getLocation()); nt.setJulianGreenwichTime(new GPJulianTime(GPAstroEngine.ConvertDynamicToUniversal(pJulianDate), 0.0)); return(nt); }
public static int WriteXML_Tithi(StringBuilder doc, GPLocationProvider loc, GPGregorianTime vc) { doc.Append("<xml>\n"); doc.Append("\t<request name=\"Tithi\" version=\"" + GPFileHelper.FileVersion + "\">\n"); doc.Append("\t\t<arg name=\"longitude\" val=\"" + vc.getLocation().GetLongitudeEastPositive() + "\" />\n"); doc.Append("\t\t<arg name=\"latitude\" val=\"" + vc.getLocation().GetLatitudeNorthPositive() + "\" />\n"); doc.Append("\t\t<arg name=\"timezone\" val=\"" + vc.getLocation().getTimeZone().OffsetSeconds / 60 + "\" />\n"); doc.Append("\t\t<arg name=\"startdate\" val=\"" + vc + "\" />\n"); doc.Append("\t</request>\n"); doc.Append("\t<result name=\"Tithi\">\n"); GPGregorianTime d = new GPGregorianTime(vc); GPGregorianTime d1 = new GPGregorianTime(loc); GPGregorianTime d2 = new GPGregorianTime(loc); GPAstroData day = new GPAstroData(); day.calculateDayData(vc, loc); d.setDayHours(day.sun.getSunriseDayHours()); GPTithi.GetPrevTithiStart(d, out d1); GPTithi.GetNextTithiStart(d, out d2); //dt.SetDegTime(d1.getDayHours() * 360); // start tithi at t[0] doc.Append("\t\t<tithi\n\t\t\tid=\"" + day.nTithi + "\"\n"); doc.Append("\t\t\tname=\"" + GPTithi.getName(day.nTithi) + "\"\n"); doc.Append("\t\t\tstartdate=\"" + d1.getShortDateString() + "\"\n"); doc.Append("\t\t\tstarttime=\"" + d1.getShortTimeString() + "\"\n"); //dt.SetDegTime(d2.getDayHours() * 360); doc.Append("\t\t\tenddate=\"" + d2.getShortDateString() + "\"\n"); doc.Append("\t\t\tendtime=\"" + d2.getShortTimeString() + "\"\n />"); doc.Append("\t</result>\n"); doc.Append("</xml>\n"); return(1); }
/*********************************************************************/ /* Finds next time when rasi is changed */ /* */ /* startDate - starting date and time, timezone member must be valid */ /* zodiac [out] - found zodiac sign into which is changed */ /* */ /*********************************************************************/ public static GPGregorianTime GetNextSankranti(GPGregorianTime startDate, out int zodiac) { GPGregorianTime d; double step = 1.0; int count = 0; double ld, prev; int prev_rasi, new_rasi; GPGregorianTime prevday = new GPGregorianTime(startDate.getLocation()); zodiac = 0; d = new GPGregorianTime(startDate); double jdate = d.getJulianGreenwichTime(); prev = GPMath.putIn360(GPSun.GetSunLongitude(jdate) - GPAyanamsa.GetAyanamsa(jdate)); prev_rasi = Convert.ToInt32(Math.Floor(prev / 30.0)); while (count < 20) { prevday.Copy(d); d.setDayHours(d.getDayHours() + step); if (d.getDayHours() > 1.0) { d.setDayHours(d.getDayHours() - 1.0); d.NextDay(); } jdate = d.getJulianGreenwichTime(); ld = GPMath.putIn360(GPSun.GetSunLongitude(jdate) - GPAyanamsa.GetAyanamsa(jdate)); new_rasi = Convert.ToInt32(Math.Floor(ld / 30.0)); if (prev_rasi != new_rasi) { zodiac = new_rasi; //v uplynulom dni je sankranti step *= 0.5; d.Copy(prevday); count++; continue; } } return(d); }
public void calculateAppearanceDayData(GPLocationProvider aLocation, GPGregorianTime aEvente) { //MOONDATA moon; //SUNDATA sun; location = aLocation; evente = new GPGregorianTime(aEvente); double dd; GPAstroData d = details; GPGregorianTime vc = evente; GPGregorianTime vcsun = evente; b_adhika = false; d.calculateDayData(aEvente, aLocation); //d.nTithi = GetPrevTithiStart(m_earth, vc, dprev); //GetNextTithiStart(m_earth, vc, dnext); //vcsun.setDayHours(vcsun.getDayHours() - vcsun.getTimeZoneOffsetHours() / 24.0); vcsun.normalizeValues(); d.sun.calculateCoordinatesMethodC(vcsun, -1); d.moon.MoonCalc(vcsun.getJulianGreenwichTime()); d.msDistance = GPMath.putIn360(d.moon.longitude_deg - d.sun.eclipticalLongitude - 180.0); d.msAyanamsa = GPAyanamsa.GetAyanamsa(vc.getJulianGreenwichTime()); // tithi dd = d.msDistance / 12.0; d.nTithi = Convert.ToInt32(Math.Floor(dd)); d.nTithiElapse = GPMath.frac(dd) * 100.0; d.nPaksa = (d.nTithi >= 15) ? 1 : 0; // naksatra dd = GPMath.putIn360(d.moon.longitude_deg - d.msAyanamsa); dd = (dd * 3.0) / 40.0; d.nNaksatra = Convert.ToInt32(Math.Floor(dd)); d.nNaksatraElapse = GPMath.frac(dd) * 100.0; d.nMasa = d.determineMasa(vc, out d.nGaurabdaYear); d.nMoonRasi = GPEngine.GetRasi(d.moon.longitude_deg, d.msAyanamsa); d.nSunRasi = GPEngine.GetRasi(d.sun.eclipticalLongitude, d.msAyanamsa); if (d.nMasa == GPMasa.ADHIKA_MASA) { d.nMasa = GPEngine.GetRasi(d.sun.eclipticalLongitude, d.msAyanamsa); b_adhika = true; } string dstApplicable = ""; //List<string> gstr = GPStrings.getSharedStrings().gstr; output.Add(new GPStringPair(GPStrings.getString(25), "", true)); output.Add(new GPStringPair(GPStrings.getString(7), vc.ToString())); output.Add(new GPStringPair(GPStrings.getString(8), vc.getShortTimeString(true, ref dstApplicable))); output.Add(new GPStringPair(GPStrings.getString(9), vc.getLocation().getFullName())); //output.Add(new GPStringPair(gstr[10], vc.getLocation().getLatitudeString())); //output.Add(new GPStringPair(gstr[11], vc.getLocation().getLongitudeString())); //output.Add(new GPStringPair(gstr[12], vc.getLocation().getTimeZoneName())); //output.Add(new GPStringPair(gstr[1001], dstApplicable)); output.Add(new GPStringPair(GPStrings.getString(13), GPTithi.getName(d.nTithi))); output.Add(new GPStringPair(GPStrings.getString(14), string.Format("{0:0.###} %", d.nTithiElapse))); output.Add(new GPStringPair(GPStrings.getString(15), GPNaksatra.getName(d.nNaksatra))); output.Add(new GPStringPair(GPStrings.getString(16), string.Format("{0:0.###} % ({1})", d.nNaksatraElapse, GPStrings.getString(811 + Convert.ToInt32(d.nNaksatraElapse / 25.0))))); output.Add(new GPStringPair(GPStrings.getString(991), GPSankranti.getName(d.nMoonRasi))); output.Add(new GPStringPair(GPStrings.getString(992), GPSankranti.getName(d.nSunRasi))); output.Add(new GPStringPair(GPStrings.getString(20), GPPaksa.getName(d.nPaksa))); if (b_adhika == true) { output.Add(new GPStringPair(GPStrings.getString(22), string.Format("{0} {1}", GPMasa.GetName(d.nMasa), GPStrings.getString(21)))); } else { output.Add(new GPStringPair(GPStrings.getString(22), GPMasa.GetName(d.nMasa))); } output.Add(new GPStringPair(GPStrings.getString(23), d.nGaurabdaYear.ToString())); if (GPDisplays.AppDay.childNameSuggestions()) { output.Add(new GPStringPair()); output.Add(new GPStringPair(GPStrings.getString(17), "", true)); output.Add(new GPStringPair()); output.Add(new GPStringPair(GPStrings.getString(18), string.Format("{0}...", GPAppHelper.GetNaksatraChildSylable(d.nNaksatra, Convert.ToInt32(d.nNaksatraElapse / 25.0))))); output.Add(new GPStringPair(GPStrings.getString(19), string.Format("{0}...", GPAppHelper.GetRasiChildSylable(d.nMoonRasi)))); } vc.Today(); GPVedicTime va = new GPVedicTime(); GPGregorianTime vctemp; va.tithi = d.nTithi; va.masa = d.nMasa; va.gyear = GPGaurabdaYear.getGaurabdaYear(vc, location); if (va.gyear < d.nGaurabdaYear) { va.gyear = d.nGaurabdaYear; } int countC = GPUserDefaults.IntForKey("appday.celebs", 3); if (countC > 0) { output.Add(new GPStringPair()); output.Add(new GPStringPair(GPStrings.getString(24), "", true)); output.Add(new GPStringPair()); } int m = 0; for (int i = 0; i < 6; i++) { GPEngine.VATIMEtoVCTIME(va, out vctemp, location); if (va.gyear > d.nGaurabdaYear) { if (m < countC) { output.Add(new GPStringPair(string.Format("{0} {1}", GPStrings.getString(994), va.gyear), vctemp.ToString())); m++; } } va.gyear++; } }
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()); }