static void phasehunt( double sdate, double phases[5] ) { double adate, k1, k2, nt1, nt2; int cnt = 0; adate = sdate - 45.0; nt1 = meanphase(adate, 0.0, &k1, &cnt); while (TRUE) { adate += synmonth; nt2 = meanphase(adate, 0.0, &k2, &cnt); if ((nt1 <= sdate) && (nt2 > sdate)) break; nt1 = nt2; k1 = k2; } if (k2 - k1 >= 2.0) k2 = k1 + 1.0; phases[0] = truephase(k1, 0.0); phases[1] = truephase(k1, 0.25); phases[2] = truephase(k1, 0.5); phases[3] = truephase(k1, 0.75); phases[4] = truephase(k2, 0.0); }
void HuntPhase(int startdate, int starttim, int phas, int *date, int *time) { int utcd, utct; int y, m, d; int h, min, s; int d1, t1; double k1, k2, jd, jdorig; double nt1, nt2; /* Convert from local to UTC */ LocalToUTC(startdate, starttim, &utcd, &utct); /* Convert from Remind representation to year/mon/day */ FromJulian(utcd, &y, &m, &d); /* Convert to a true Julian date -- sorry for the name clashes! */ jdorig = jtime(y, m, d, (utct / 60), (utct % 60), 0); jd = jdorig - 45.0; nt1 = meanphase(jd, 0.0, &k1); while(1) { jd += synmonth; nt2 = meanphase(jd, 0.0, &k2); if (nt1 <= jdorig && nt2 > jdorig) break; nt1 = nt2; k1 = k2; } jd = truephase(k1, phas/4.0); if (jd < jdorig) jd = truephase(k2, phas/4.0); /* Convert back to Remind format */ jyear(jd, &y, &m, &d); jhms(jd, &h, &min, &s); d1 = Julian(y, m, d); t1 = h*60 + min; UTCToLocal(d1, t1, date, time); }