datestr_to_date Subroutine

public subroutine datestr_to_date(date_str, format_str, date_array)

Converts date string to a date array based on the format string

Example: call datestr_to_date("20190429123005", "yyyymmdd", date_array_out) Returns: date_arrat_out = [2019, 4, 29, 0, 0, 0]

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: date_str

Date string [yyyymmddHHMMSS]

character(len=*), intent(in) :: format_str

Format string

integer, intent(out) :: date_array(6)

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


Called by

proc~~datestr_to_date~~CalledByGraph proc~datestr_to_date datestr_to_date proc~uemep_calculate_emissions_for_emep uEMEP_calculate_emissions_for_EMEP proc~uemep_calculate_emissions_for_emep->proc~datestr_to_date proc~uemep_read_meteo_nc uEMEP_read_meteo_nc proc~uemep_calculate_emissions_for_emep->proc~uemep_read_meteo_nc proc~uemep_read_monthly_and_daily_shipping_asi_data uEMEP_read_monthly_and_daily_shipping_asi_data proc~uemep_calculate_emissions_for_emep->proc~uemep_read_monthly_and_daily_shipping_asi_data 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_config uEMEP_read_config proc~uemep_read_config->proc~datestr_to_date proc~uemep_read_meteo_nc->proc~datestr_to_date proc~uemep_read_monthly_and_daily_shipping_asi_data->proc~datestr_to_date proc~uemep_read_roadlink_emission_data->proc~datestr_to_date proc~uemep_read_weekly_shipping_asi_data->proc~datestr_to_date program~uemep uEMEP program~uemep->proc~uemep_calculate_emissions_for_emep program~uemep->proc~uemep_read_config program~uemep->proc~uemep_read_meteo_nc program~uemep->proc~uemep_read_monthly_and_daily_shipping_asi_data program~uemep->proc~uemep_read_roadlink_emission_data program~uemep->proc~uemep_read_weekly_shipping_asi_data

Source Code

    subroutine datestr_to_date(date_str, format_str, date_array)
        !! Converts date string to a date array based on the format string
        !! 
        !! Example:
        !!     call datestr_to_date("20190429123005", "yyyymmdd", date_array_out)
        !! Returns:
        !!     date_arrat_out = [2019, 4, 29, 0, 0, 0]
        character(*), intent(in) :: date_str !! Date string [yyyymmddHHMMSS]
        character(*), intent(in) :: format_str !! Format string
        integer, intent(out) :: date_array(6) !! Datetime [y,m,d,h,m,s]
        
        ! Local variables
        integer :: pos

        ! Extract elements of the date string
        pos = index(format_str, 'yyyy')
        if (pos .gt. 0) then
            read(date_str(pos:pos+3),*) date_array(1)
        else
            date_array(1) = 0
        end if
        pos = index(format_str, 'mm')
        if (pos .gt. 0) then
            read(date_str(pos:pos+1),*) date_array(2)
        else
            date_array(2) = 0
        end if
        pos = index(format_str, 'dd')
        if (pos .gt. 0) then
            read(date_str(pos:pos+1),*) date_array(3)
        else
            date_array(3) = 0
        end if
        pos = index(format_str, 'HH')
        if (pos .gt. 0) then
            read(date_str(pos:pos+1),*) date_array(4)
        else
            date_array(4) = 0
        end if
        pos = index(format_str, 'MM')
        if (pos .gt. 0) then
            read(date_str(pos:pos+1),*) date_array(5)
        else
            date_array(5) = 0
        end if
        pos = index(format_str, 'SS')
        if (pos .gt. 0) then
            read(date_str(pos:pos+1),*) date_array(6)
        else
            date_array(6) = 0
        end if
    end subroutine datestr_to_date