parse_indices_line Subroutine

subroutine parse_indices_line(line, fragment, error)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: line
type(input_fragment_t), intent(inout) :: fragment
type(error_t), intent(out) :: error

Calls

proc~~parse_indices_line~~CallsGraph proc~parse_indices_line parse_indices_line proc~error_set error_t%error_set proc~parse_indices_line->proc~error_set

Called by

proc~~parse_indices_line~~CalledByGraph proc~parse_indices_line parse_indices_line proc~parse_fragment parse_fragment proc~parse_fragment->proc~parse_indices_line proc~parse_fragments_generic parse_fragments_generic proc~parse_fragments_generic->proc~parse_fragment interface~parse_fragments_generic parse_fragments_generic interface~parse_fragments_generic->proc~parse_fragments_generic proc~parse_fragments_section parse_fragments_section proc~parse_fragments_section->interface~parse_fragments_generic proc~parse_molecule_fragments parse_molecule_fragments proc~parse_molecule_fragments->interface~parse_fragments_generic interface~parse_fragments_section parse_fragments_section interface~parse_fragments_section->proc~parse_fragments_section proc~parse_single_molecule parse_single_molecule proc~parse_single_molecule->proc~parse_molecule_fragments

Variables

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

Source Code

   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