append_clean_flags Subroutine

public subroutine append_clean_flags(flags, new_flags)

Append new flags to existing flags, removing duplicates and empty flags (string version)

Arguments

Type IntentOptional Attributes Name
character(len=:), intent(inout), allocatable :: flags
character(len=*), intent(in) :: new_flags

Variables

Type Visibility Attributes Name Initial
type(string_t), public, allocatable :: flags_array(:)
integer, public :: i
integer, public :: n_old
type(string_t), public, allocatable :: new_flags_array(:)

Source Code

subroutine append_clean_flags(flags, new_flags)
    character(:), intent(inout), allocatable :: flags
    character(*), intent(in) :: new_flags

    type(string_t), allocatable :: flags_array(:), new_flags_array(:)
    integer :: i, n_old

    call tokenize_flags(flags, flags_array)
    call tokenize_flags(new_flags, new_flags_array)

    ! `flags_array` starts out holding the flags already in `flags`, and
    ! `append_clean_flags_array` only ever appends: re-emitting the whole array
    ! would repeat every one of them on each call
    n_old = size(flags_array)

    call append_clean_flags_array(flags_array, new_flags_array)

    do i = n_old + 1, size(flags_array)
        flags = flags // " " // flags_array(i)%s
    end do
end subroutine append_clean_flags