split Subroutine

public pure subroutine split(string, set, pos, back)

Parse a string into tokens, one at a time. This subroutine implements the split intrinsic procedure as defined in the Fortran 2023 language standard (Section 16.9.196). We implement it ourselves because the compiler support may take years to become widespread. (KCW, 2025-10-29)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: string
character(len=*), intent(in) :: set
integer, intent(inout) :: pos
logical, intent(in), optional :: back

Calls

proc~~split~~CallsGraph proc~split split interface~clamp clamp proc~split->interface~clamp proc~clamp_int32 clamp_int32 interface~clamp->proc~clamp_int32 proc~clamp_int64 clamp_int64 interface~clamp->proc~clamp_int64 proc~clamp_real32 clamp_real32 interface~clamp->proc~clamp_real32 proc~clamp_real64 clamp_real64 interface~clamp->proc~clamp_real64

Called by

proc~~split~~CalledByGraph proc~split split proc~tokenize_into_first_last tokenize_into_first_last proc~tokenize_into_first_last->proc~split interface~tokenize tokenize interface~tokenize->proc~tokenize_into_first_last proc~tokenize_into_tokens_separator tokenize_into_tokens_separator interface~tokenize->proc~tokenize_into_tokens_separator proc~parse_stream_name parse_stream_name proc~parse_stream_name->interface~tokenize proc~tokenize_into_tokens_separator->interface~tokenize proc~dyn_mpas_init_stream_with_pool mpas_dynamical_core_type%dyn_mpas_init_stream_with_pool proc~dyn_mpas_init_stream_with_pool->proc~parse_stream_name proc~dyn_mpas_read_write_stream mpas_dynamical_core_type%dyn_mpas_read_write_stream proc~dyn_mpas_read_write_stream->proc~parse_stream_name proc~dyn_mpas_read_write_stream->proc~dyn_mpas_init_stream_with_pool proc~dyn_init dyn_init proc~dyn_init->proc~dyn_mpas_read_write_stream proc~dyn_variable_dump dyn_variable_dump proc~dyn_variable_dump->proc~dyn_mpas_read_write_stream proc~model_grid_init model_grid_init proc~model_grid_init->proc~dyn_mpas_read_write_stream interface~dyn_init dyn_init interface~dyn_init->proc~dyn_init interface~model_grid_init model_grid_init interface~model_grid_init->proc~model_grid_init proc~dyn_final dyn_final proc~dyn_final->proc~dyn_variable_dump interface~dyn_final dyn_final interface~dyn_final->proc~dyn_final proc~stepon_final stepon_final proc~stepon_final->interface~dyn_final

Variables

Type Visibility Attributes Name Initial
integer, private :: offset

Source Code

    pure subroutine split(string, set, pos, back)
        character(*), intent(in) :: string, set
        integer, intent(inout) :: pos
        logical, optional, intent(in) :: back

        integer :: offset

        if (present(back)) then
            if (back) then
                offset = clamp(pos, 1, len(string) + 1)
                pos = scan(string(1:offset - 1), set, back=.true.)

                return
            end if
        end if

        offset = clamp(pos, 0, len(string))
        pos = scan(string(offset + 1:), set)

        if (pos == 0) then
            pos = len(string) + 1

            return
        end if

        pos = offset + pos
    end subroutine split