public static void findNextMoonPhase(DateTime t, out TTG.NavalWar.NWComms.GameConstants.TideEventType tideEvent_out) { TTG.NavalWar.NWComms.GameConstants.TideEventType phase; double jd = t.DtToJulianDay(); // find_next_moon_phase(ref jd, out phase); //tideEvent_out.eventTime = jd; tideEvent_out = phase; //switch (phase) //{ //case 0: // tideEvent_out = TideEventType.newmoon; // break; //case 1: // tideEvent_out = TideEventType.firstquarter; // break; //case 2: // tideEvent_out = TideEventType.fullmoon; // break; //case 3: // tideEvent_out = TideEventType.lastquarter; // break; //default: // tideEvent_out = TideEventType.newmoon; //to avoid error // Debug.Assert (false); // break; //} }
public static void find_next_moon_phase(ref double jd, out TTG.NavalWar.NWComms.GameConstants.TideEventType phase) { double newjd, lastnewjd, nextjd; short kount = 0; // Originally, there was no problem with getting snagged, but since // I introduced the roundoff error going back and forth with Timestamp, // now it's a problem. // Move ahead by 1 second to avoid snagging. jd += 1.0 / SEC_IN_DAY; // Find current lunation. I doubled the safety margin since it // seemed biased for forwards search. Backwards search has since // been deleted, but little reason to mess with it. int nlast = (int)((jd - 2415020.5) / 29.5307 - 2); flmoon(nlast, 0, out lastnewjd); flmoon(++nlast, 0, out newjd); while (newjd <= jd) { lastnewjd = newjd; flmoon(++nlast, 0, out newjd); if (kount++ > 5) { break; } ; // Original limit was 35 (!) //hmmm } // We might save some work here by estimating, i.e.: // x = jd - lastnewjd; // noctiles = (int)(x / 3.69134); /* 3.69134 = 1/8 month; truncate. */ // However.... Debug.Assert(lastnewjd <= jd && newjd > jd); phase = (TTG.NavalWar.NWComms.GameConstants.TideEventType) 1; // Lunation is lastnewjd's lunation flmoon(--nlast, (int)phase, out nextjd); // Phase = 1 if (nextjd <= jd) { flmoon(nlast, (int)++phase, out nextjd); // Phase = 2 if (nextjd <= jd) { flmoon(nlast, (int)++phase, out nextjd); // Phase = 3 if (nextjd <= jd) { phase = TTG.NavalWar.NWComms.GameConstants.TideEventType.NewMoon; nextjd = newjd; } } } jd = nextjd; }