day_of_year Function

public pure function day_of_year(dt) result(doy)

Return the ordinal day of the year (1-366).

Arguments

Type IntentOptional Attributes Name
type(datetime_type), intent(in) :: dt

Return Value integer


Source Code

    pure function day_of_year(dt) result(doy)
        !! version: experimental
        !!
        !! Return the ordinal day of the year (1-366).
        type(datetime_type), intent(in) :: dt
        integer :: doy
        integer, parameter :: cum(12) = &
            [0,31,59,90,120,151,181,212,243,273,304,334]
        ! Guard against invalid month values
        if (dt%month < 1 .or. dt%month > 12) then
            doy = 0
            return
        end if
        doy = cum(dt%month) + dt%day
        if (dt%month > 2 .and. is_leap_year_int(dt%year))&
            doy = doy + 1
    end function day_of_year