YMD jd2ymd(JD jd) { YMD ymd; double j; double x; int y, m, d; j = jdGetDay(jd); j2gcal(&y, &m, &d, j); ymdSetYear(ymd, y); ymdSetMonth(ymd, m); ymdSetDay(ymd, (double)d); x = (j - floor(j)); /* ** we do this next step because the rounding of j in j2gcal() ** either credits or debits us with 12 hours */ if (x < 0.5) { x += 0.5; } else { x -= 0.5; } ymdIncDay(ymd, x); /* pick up the hours, minutes, and seconds */ ymd.hms = jd.hms; return(ymd); }
int main(){ JD jd; double t =0.0; #define L 2 double j[L][4] = { {2451545.0, 10.0, 0.0, 0.0}, {2433142.678, 10.123, -10.345, 1.04} }; for(int i=0; i < L; i++){ jdSetDay(jd, j[i][0]); jdSetHours(jd, j[i][1]); jdSetMinutes(jd, j[i][2]); jdSetSeconds(jd, j[i][3]); printf("%16.8f %8.4f %8.4f %8.4f\n", jdGetDay(jd), jdGetHours(jd), jdGetMinutes(jd), jdGetSeconds(jd)); t = jd2y(jd); printf("%16.8f\n\n", t); } return 0; }