get_fields_string Subroutine

private subroutine get_fields_string(line, delims, n_max, n_found, ixs_start, ixs_end)

Routine to find the indices of entries in a string

Arguments

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

The line from which we want to read

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

A string with delimiters. For example delims = " ,'"""//char(9)

integer, intent(in) :: n_max

Maximum number of entries to read in

integer, intent(inout) :: n_found

Number of entries found

integer, intent(inout) :: ixs_start(n_max)

On return, ix_start(i) holds the starting point of entry i

integer, intent(inout) :: ixs_end(n_max)

On return, ix_end(i) holds the end point of entry i


Called by

proc~~get_fields_string~2~~CalledByGraph proc~get_fields_string~2 get_fields_string proc~read_variable read_variable proc~read_variable->proc~get_fields_string~2 proc~add_int add_int proc~add_int->proc~read_variable proc~add_int_array add_int_array proc~add_int_array->proc~read_variable proc~add_logic add_logic proc~add_logic->proc~read_variable proc~add_logic_array add_logic_array proc~add_logic_array->proc~read_variable proc~add_real add_real proc~add_real->proc~read_variable proc~add_real_array add_real_array proc~add_real_array->proc~read_variable proc~add_string add_string proc~add_string->proc~read_variable proc~add_string_array add_string_array proc~add_string_array->proc~read_variable proc~cfg_read_file CFG_read_file proc~cfg_read_file->proc~read_variable interface~cfg_add CFG_add interface~cfg_add->proc~add_int interface~cfg_add->proc~add_int_array interface~cfg_add->proc~add_logic interface~cfg_add->proc~add_logic_array interface~cfg_add->proc~add_real interface~cfg_add->proc~add_real_array interface~cfg_add->proc~add_string interface~cfg_add->proc~add_string_array proc~add_get_int add_get_int proc~add_get_int->proc~add_int proc~add_get_int_array add_get_int_array proc~add_get_int_array->proc~add_int_array proc~add_get_logic add_get_logic proc~add_get_logic->proc~add_logic proc~add_get_logic_array add_get_logic_array proc~add_get_logic_array->proc~add_logic_array proc~add_get_real add_get_real proc~add_get_real->proc~add_real proc~add_get_real_array add_get_real_array proc~add_get_real_array->proc~add_real_array proc~add_get_string add_get_string proc~add_get_string->proc~add_string proc~add_get_string_array add_get_string_array proc~add_get_string_array->proc~add_string_array proc~cfg_update_from_arguments CFG_update_from_arguments proc~cfg_update_from_arguments->proc~cfg_read_file interface~cfg_add_get CFG_add_get interface~cfg_add_get->proc~add_get_int interface~cfg_add_get->proc~add_get_int_array interface~cfg_add_get->proc~add_get_logic interface~cfg_add_get->proc~add_get_logic_array interface~cfg_add_get->proc~add_get_real interface~cfg_add_get->proc~add_get_real_array interface~cfg_add_get->proc~add_get_string interface~cfg_add_get->proc~add_get_string_array

Source Code

  subroutine get_fields_string(line, delims, n_max, n_found, ixs_start,&
      ixs_end)
    !> The line from which we want to read
    character(len=*), intent(in)  :: line
    !> A string with delimiters. For example delims = " ,'"""//char(9)
    character(len=*), intent(in)  :: delims
    !> Maximum number of entries to read in
    integer, intent(in)           :: n_max
    !> Number of entries found
    integer, intent(inout)        :: n_found
    !> On return, ix_start(i) holds the starting point of entry i
    integer, intent(inout)        :: ixs_start(n_max)
    !> On return, ix_end(i) holds the end point of entry i
    integer, intent(inout)        :: ixs_end(n_max)

    integer                       :: ix, ix_prev

    ix_prev = 0
    n_found = 0

    do while (n_found < n_max)

       ! Find the starting point of the next entry (a non-delimiter value)
       ix = verify(line(ix_prev+1:), delims)
       if (ix == 0) exit

       n_found            = n_found + 1
       ixs_start(n_found) = ix_prev + ix !This is the absolute position in 'line'

       ! Get the end point of the current entry (next delimiter index minus one)
       ix = scan(line(ixs_start(n_found)+1:), delims) - 1

       if (ix == -1) then              ! If there is no last delimiter,
          ixs_end(n_found) = len(line) ! the end of the line is the endpoint
       else
          ixs_end(n_found) = ixs_start(n_found) + ix
       end if

       ix_prev = ixs_end(n_found) ! We continue to search from here
    end do

  end subroutine get_fields_string