| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line | |||
| type(input_fragment_t), | intent(inout) | :: | fragment | |||
| type(error_t), | intent(out) | :: | error |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private | :: | count | ||||
| integer, | private | :: | idx | ||||
| integer, | private | :: | io_stat | ||||
| integer, | private, | allocatable | :: | new_indices(:) | |||
| integer, | private | :: | pos | ||||
| integer, | private, | allocatable | :: | temp_indices(:) | |||
| character(len=MAX_LINE_LEN), | private | :: | temp_line |
subroutine parse_indices_line(line, fragment, error) character(len=*), intent(in) :: line type(input_fragment_t), intent(inout) :: fragment type(error_t), intent(out) :: error integer :: io_stat, pos, count, idx character(len=MAX_LINE_LEN) :: temp_line integer, allocatable :: temp_indices(:), new_indices(:) temp_line = line ! Count how many integers count = 0 do read (temp_line, *, iostat=io_stat) idx if (io_stat /= 0) exit count = count + 1 ! Remove the read integer from temp_line pos = scan(temp_line, ' ') if (pos == 0) exit temp_line = adjustl(temp_line(pos:)) end do if (count == 0) return ! Allocate temporary array allocate (temp_indices(count)) ! Read the integers read (line, *, iostat=io_stat) temp_indices if (io_stat /= 0) then call error%set(ERROR_PARSE, "Error reading fragment indices") deallocate (temp_indices) return end if ! Append to existing indices if (allocated(fragment%indices)) then allocate (new_indices(size(fragment%indices) + count)) new_indices(1:size(fragment%indices)) = fragment%indices new_indices(size(fragment%indices) + 1:) = temp_indices call move_alloc(new_indices, fragment%indices) else call move_alloc(temp_indices, fragment%indices) end if end subroutine parse_indices_line