/* julday.c * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Returns the Julian Day Number that begins at noon of the calendar date * specified by month imonth, day iday, and year iyear, all integer variables. * Positive year signifies A.D. Negative year signifies B.C. * Remember that the year after 1 B.C. was 1 A.D. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * From "Numerical Recipes in C" by William H. Press, Brian P. Flannery, * Saul A. Teukolsky, and WIlliam T. Vetterling. Cambridge University Press, * 1988 (second printing). * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Andrew L. Stanger HAO/NCAR 25 March 1999 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include #include double julday (int iyear, int imonth, int iday, int ihour, int iminute, int isecond) { double jul ; long lgreg ; /* Gregorian Calendar adopted 15 October 1582. */ long ja ; long jy ; long jm ; long lyear, lmonth, lday ; long lhour, lminute, lsecond ; lyear = (long) iyear ; lmonth = (long) imonth ; lday = (long) iday ; lhour = (long) ihour ; lminute = (long) iminute ; lsecond = (long) isecond ; lgreg = 15L + 31L * (10L + 12L * 1582L) ; jy = iyear ; if (jy == 0) { fprintf (stderr, "julday: there is no year zero.") ; return (0.0) ; } if (lyear < 0) lyear = lyear + 1 ; /* 1 B.C. precedes 1 A.D. */ if (lmonth > 2) { jy = lyear ; jm = lmonth + 1 ; } else { jy = lyear - 1 ; jm = lmonth + 13 ; } jul = (long) (365.25 * jy) + (long) (30.6001 * jm) + lday + 1720995 ; /*** Test whether to change to Gregorian Calendar. ***/ if ((lday + 31L * (lmonth + 12L * lyear)) >= lgreg) { ja = (long) (0.01 * jy) ; jul += 2 - ja + (long) (0.25 * ja) ; } jul += (lhour / 24.0 - 0.5) + (lminute / 1440.0) + (lsecond / 86400.0) ; return (jul) ; }