calendar_date_to_et Function

public function calendar_date_to_et(year, month, day, hour, minute, second) result(et)

Uses

  • proc~~calendar_date_to_et~~UsesGraph proc~calendar_date_to_et calendar_date_to_et module~conversion_module conversion_module proc~calendar_date_to_et->module~conversion_module module~kind_module kind_module module~conversion_module->module~kind_module module~numbers_module numbers_module module~conversion_module->module~numbers_module iso_fortran_env iso_fortran_env module~kind_module->iso_fortran_env module~numbers_module->module~kind_module

Directly converts a calendar date to seconds since the J2000 epoch.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: year
integer, intent(in) :: month
integer, intent(in) :: day
integer, intent(in) :: hour
integer, intent(in) :: minute
real(kind=wp), intent(in) :: second

Return Value real(kind=wp)


Calls

proc~~calendar_date_to_et~~CallsGraph proc~calendar_date_to_et calendar_date_to_et proc~is_leap_year is_leap_year proc~calendar_date_to_et->proc~is_leap_year

Called by

proc~~calendar_date_to_et~~CalledByGraph proc~calendar_date_to_et calendar_date_to_et proc~time_module_test time_module_test proc~time_module_test->proc~calendar_date_to_et

Source Code

    function calendar_date_to_et(year, month, day, hour, minute, second) result(et)

    use conversion_module, only: hr2sec, min2sec, day2sec

    integer, intent(in) :: year, month, day, hour, minute
    real(wp), intent(in) :: second
    real(wp) :: et

    ! Constants for the J2000 epoch: January 1, 2000, 12:00:00
    integer, parameter :: j2000_year = 2000
    integer, parameter :: j2000_month = 1
    integer, parameter :: j2000_day = 1
    integer, parameter :: j2000_hour = 12
    integer, parameter :: j2000_minute = 0
    real(wp), parameter :: j2000_second = 0.0_wp

    ! Days in each month (non-leap year)
    integer, dimension(12), parameter :: days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

    integer :: y, m
    integer :: total_days

    ! first do time of day:
    et = real(hour - j2000_hour, wp) * hr2sec + &
         real(minute - j2000_minute, wp) * min2sec + &
         (second - j2000_second)

    ! now, calculate the total number of days from J2000 to the given date
    total_days = 0
    do y = j2000_year, year - 1
        total_days = total_days + 365 + merge(1, 0, is_leap_year(y))
    end do
    do m = 1, month - 1
        if (m == 2) then
            total_days = total_days + days_in_month(m) + merge(1, 0, is_leap_year(year))
        else
            total_days = total_days + days_in_month(m)
        end if
    end do

    ! add days:
    et = et + real(total_days + (day - j2000_day), wp) * day2sec

    end function calendar_date_to_et