subroutine get_dayofmonth(year, month, doy, dom) c----------------------------------------------------------------------------------- c Description: Calculatie day of month (1-31) given month (1-12). c c Input parameters: c year year (yyyy) c month month (1-12) c doy day of year (1-366) c c Output parameters: c dom day of month (1-31) c c Revision history: c 01/14 R. Frey Original version c c Calls c None c c----------------------------------------------------------------------------------- IMPLICIT NONE c----------------------------------------------------------------------------------- c Arguments. integer year, month, doy, dom character*160 errmsg integer bday(12), leap_bday(12), beg_day, il, im, j, status, level logical leap_year c----------------------------------------------------------------------------------- data bday /1, 32, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335/ data leap_bday /1, 32, 61, 92, 122, 153, 183, 214, 245, 275, 306, 336/ c----------------------------------------------------------------------------------- c Determine if leap year. il = mod(year, 4) if(il .eq. 0) then leap_year = .true. else leap_year = .false. end if c----------------------------------------------------------------------------------- c Check value of month ('month'). if(month .le. 0 .or. month .gt. 12) then level = 3 status = -1 write( errmsg,'(''Invalid month: '',i10)') month call message( 'get_dayofmonth', errmsg, & status, level ) end if c----------------------------------------------------------------------------------- c Check day of year ('doy') value. if(doy .le. 0 .or. ( (.not. leap_year) .and. doy .gt. 365) .or. * (leap_year .and. doy .gt. 366) ) then level = 3 status = -1 write( errmsg,'(''Invalid day of year: '',i10)') doy call message( 'get_month', errmsg, & status, level ) end if c----------------------------------------------------------------------------------- c Find day of month (1-31). if(leap_year) then beg_day = leap_bday(month) else beg_day = bday(month) end if dom = (doy - beg_day) + 1 c----------------------------------------------------------------------------------- return end c-----------------------------------------------------------------------------------