!$Author$ !$Date$ !$Revision$ !$HeadURL$ subroutine caldat (julian, dd, mm, yyyy) ! + + + PURPOSE + + + ! Inverse of the function JULDAY. Here 'julian' is input as a Julian Day ! Number, and the routine outputs the dd, mm, and yyyy on which the ! specified Julian Day started at noon. ! Based on info from http://en.wikipedia.org/wiki/Julian_day, which references ! http://www.astro.uu.nl/~strous/AA/en/reken/juliaansedag.html, the code ! was revised to use the Astronomical Gregorian calendar, which takes the ! present pattern of leap years back into the past. This is ideal for ! our purposes with no year getting short changed. Integer math method ! is taken from Wikipedia article. ! + + + ARGUMENT DECLARATIONS + + + integer, intent(in) :: julian ! Julian Day Number integer, intent(out) :: dd ! day of month in the range 1-31 integer, intent(out) :: mm ! month of year in the range 1-12 integer, intent(out) :: yyyy ! year (positive A.D., negative B.C.) ! + + + PARAMETERS + + + ! Gregorian Calendar was adopted on Oct. 15, 1582. ! parameter (igreg=2299161) ! + + + LOCAL VARIABLES + + + integer s1, s2, s3, s4, n_n, i_i, q_q ! + + + END SPECIFICATIONS + + + s1 = julian + 68569 n_n = floor(4*s1/146097.0) s2 = s1 - floor((146097*n_n + 3)/4.0) i_i = floor(4000*(s2 + 1)/1461001.0) s3 = s2 - floor(1461*i_i/4.0) + 31 q_q = floor(80*s3/2447.0) s4 = floor(q_q/11.0) dd = s3 - floor(2447*q_q/80.0) mm = q_q + 2 - 12*s4 yyyy = 100*(n_n - 49) + i_i + s4 end subroutine caldat