functionday_of_yearpureprivate
pure integer function day_of_year(y, m, d)
Day of the year of a date, from 1.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| y | integer | in | the year | |
| m | integer | in | the month, from 1 | |
| d | integer | in | the day of the month |
Result
| Name | Type | Attributes | Description |
|---|---|---|---|
| day_of_year | integer |
Source
Show the code
pure integer function day_of_year(y, m, d)
integer, intent(in) :: y !! the year
integer, intent(in) :: m !! the month, from 1
integer, intent(in) :: d !! the day of the month
integer, parameter :: BEFORE(12) = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
logical :: leap
leap = mod(y, 4) == 0 .and. (mod(y, 100) /= 0 .or. mod(y, 400) == 0)
day_of_year = BEFORE(m) + d + merge(1, 0, leap .and. m > 2)
end function day_of_year