!*************************************************** ! This program takes in the year month and day. It ! calculates the day of the year !*************************************************** !program julian_date subroutine julian_date(year,month,day,juldate) integer :: year,month,day,juldate integer :: leap_flag integer, dimension(12) :: num_days !year=2008 !month=4 !day=13 !****************************** ! Check if the year is a leap year !****************************** leap_flag=0 !not a leap year check4=mod(year,4) !years divisible by 4 are leap years, unless........... check100=mod(year,100) !years also divisible by 100 are not leap years, except....... check400=mod(year,400) !years divisible by 400 are leap years. if ( (check4 .eq. 0 .and. check100 .ne. 0) .or. (check400 .eq. 0) ) then leap_flag=1 !leap year endif !****************************** ! Make an array of the number of days !****************************** if (leap_flag .eq. 0) then ! J F M A M J J A S O N D num_days=(/31,28,31,30,31,30,31,31,30,31,30,31/) else if (leap_flag .eq. 1) then num_days=(/31,29,31,30,31,30,31,31,30,31,30,31/) endif !***************************** ! Sum up the months of days !***************************** if (month .ge. 2) then do i=1,month-1 juldate=juldate+num_days(i) enddo else juldate=0 endif ! Add on the extra days juldate=juldate+day !print*,year,month,day !print*,juldate !print*,'leap_flag',leap_flag !end program end subroutine julian_date