date_to_number Function

public function date_to_number(date_array, ref_year) result(res)

Returns a date number from an array with date and time

Note: Some wrong dates (e.g., 2023-02-29) will still return a number which will be wrong!

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: date_array(6)

Datetime [y,m,d,h,m,s]

integer, intent(in) :: ref_year

Reference year

Return Value real(kind=dp)

Date number in seconds since ref_year


Calls

proc~~date_to_number~~CallsGraph proc~date_to_number date_to_number sngl sngl proc~date_to_number->sngl

Called by

proc~~date_to_number~~CalledByGraph proc~date_to_number date_to_number proc~date_to_julian date_to_julian proc~date_to_julian->proc~date_to_number proc~summer_time_europe summer_time_europe proc~summer_time_europe->proc~date_to_number proc~uemep_calculate_emissions_for_emep uEMEP_calculate_emissions_for_EMEP proc~uemep_calculate_emissions_for_emep->proc~date_to_number proc~uemep_read_meteo_nc uEMEP_read_meteo_nc proc~uemep_calculate_emissions_for_emep->proc~uemep_read_meteo_nc proc~uemep_read_roadlink_emission_data uEMEP_read_roadlink_emission_data proc~uemep_calculate_emissions_for_emep->proc~uemep_read_roadlink_emission_data proc~uemep_read_weekly_shipping_asi_data uEMEP_read_weekly_shipping_asi_data proc~uemep_calculate_emissions_for_emep->proc~uemep_read_weekly_shipping_asi_data proc~uemep_read_time_profiles uEMEP_read_time_profiles proc~uemep_calculate_emissions_for_emep->proc~uemep_read_time_profiles proc~uemep_read_config uEMEP_read_config proc~uemep_read_config->proc~date_to_number proc~uemep_read_emep uEMEP_read_EMEP proc~uemep_read_emep->proc~date_to_number proc~uemep_read_meteo_nc->proc~date_to_number proc~uemep_read_roadlink_emission_data->proc~date_to_number proc~uemep_read_weekly_shipping_asi_data->proc~date_to_number proc~get_sun_angles get_sun_angles proc~get_sun_angles->proc~date_to_julian proc~uemep_read_time_profiles->proc~summer_time_europe program~uemep uEMEP program~uemep->proc~uemep_calculate_emissions_for_emep program~uemep->proc~uemep_read_config program~uemep->proc~uemep_read_emep program~uemep->proc~uemep_read_meteo_nc program~uemep->proc~uemep_read_roadlink_emission_data program~uemep->proc~uemep_read_weekly_shipping_asi_data program~uemep->proc~uemep_read_time_profiles proc~correct_annual_mean_chemistry correct_annual_mean_chemistry program~uemep->proc~correct_annual_mean_chemistry proc~uemep_annual_mean_pdf_correction_no2_o3 uEMEP_annual_mean_pdf_correction_NO2_O3 proc~uemep_annual_mean_pdf_correction_no2_o3->proc~get_sun_angles proc~correct_annual_mean_chemistry->proc~uemep_annual_mean_pdf_correction_no2_o3

Source Code

    function date_to_number(date_array, ref_year) result(res)
        !! Returns a date number from an array with date and time
        !!
        !! Note: Some wrong dates (e.g., 2023-02-29) will still return a number which will be wrong!
        integer, intent(in) :: date_array(6) !! Datetime [y,m,d,h,m,s]
        integer, intent(in) :: ref_year !! Reference year
        real(dp) :: res !! Date number in seconds since ref_year

        ! Local variables
        integer :: y, m
        integer :: daysinmonth(12) = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

        res = 0.0
        if (date_array(1) .gt. ref_year) then
            ! Add up days in the year
            do y = ref_year, date_array(1) - 1
                if (((mod(y,4) .eq. 0) .and. (mod(y,100) .ne. 0)) .or. (mod(y,400) .eq. 0)) then
                    daysinmonth(2) = 29
                else
                    daysinmonth(2) = 28
                end if
                do m = 1, 12
                    res = res + sngl(real(daysinmonth(m)))
                end do
            end do
        end if

        ! Add up days in the remaining months
        if (((mod(date_array(1),4) .eq. 0) .and. (mod(date_array(1),100) .ne. 0)) .or. (mod(date_array(1),400) .eq. 0)) then
            daysinmonth(2) = 29
        else
            daysinmonth(2) = 28
        end if
        if (date_array(2) .gt. 1) then
            do m = 1, date_array(2) - 1
                res = res + sngl(real(daysinmonth(m)))
            end do
        end if

        res = res + sngl(real(date_array(3))) - 1.0
        res = res + sngl(real(date_array(4)))/24.0 ! starts at 0
        res = res + sngl(real(date_array(5)))/24.0/60.0 ! starts at 0
        res = res + sngl(real(date_array(6)))/24.0/60.0/60.0 ! starts at 0
    end function date_to_number