Routine to find the indices of entries in a string
| Type | Intent | Optional | 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 |
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