C Date conversion routines C Doug Neuhauser, doug@perry.berkeley.edu block data date_data implicit none include 'dateconv.h' C Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec data dpm / 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 / data mdoy / 31, 59, 90,120,151,181,212,243,273,304,334,365 / data mon / 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 1 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' / end C Compute # days through specified month, including leap year. integer function ldoy(y,m) implicit none integer y, m include 'dateconv.h' logical is_leap ldoy = 0 if (m .ge. 1) ldoy = mdoy(m) if (is_leap(y) .and. m .ge. 2) ldoy = ldoy + 1 return end C Boolean function to determine whether year is a leap year. logical function is_leap(yr) implicit none integer yr is_leap = ((mod(yr,400) .eq. 0) .or. 1 ((mod(yr,4) .eq. 0) .and. (mod(yr,100) .ne. 0))) return end C Convert day_of_year,year to year,month,day subroutine dy_to_mdy (doy, year, month, day) implicit none integer doy integer year integer month integer day include 'dateconv.h' integer ldoy month=1 day = doy do while (doy .gt. ldoy(year,month)) month = month + 1 end do day = doy - ldoy(year,month-1) return end C Convert month,day,year to year,day_of_year subroutine mdy_to_dy (month, day, year, doy) implicit none integer month integer day integer year integer doy include 'dateconv.h' integer ldoy doy = ldoy(year,month-1)+day return end