parse_fragment Subroutine

subroutine parse_fragment(unit, fragment, error)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: unit
type(input_fragment_t), intent(inout) :: fragment
type(error_t), intent(out) :: error

Calls

proc~~parse_fragment~~CallsGraph proc~parse_fragment parse_fragment proc~error_add_context error_t%error_add_context proc~parse_fragment->proc~error_add_context proc~error_has_error error_t%error_has_error proc~parse_fragment->proc~error_has_error proc~error_set error_t%error_set proc~parse_fragment->proc~error_set proc~parse_indices_line parse_indices_line proc~parse_fragment->proc~parse_indices_line proc~strip_comment strip_comment proc~parse_fragment->proc~strip_comment proc~parse_indices_line->proc~error_set

Called by

proc~~parse_fragment~~CalledByGraph proc~parse_fragment parse_fragment 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 proc~parse_molecules_section parse_molecules_section proc~parse_molecules_section->proc~parse_single_molecule proc~read_mqc_file read_mqc_file proc~read_mqc_file->interface~parse_fragments_section

Variables

Type Visibility Attributes Name Initial
integer, private :: eq_pos
logical, private :: in_indices
integer, private :: io_stat
character(len=MAX_LINE_LEN), private :: key
character(len=MAX_LINE_LEN), private :: line
character(len=MAX_LINE_LEN), private :: value

Source Code

   subroutine parse_fragment(unit, fragment, error)
      integer, intent(in) :: unit
      type(input_fragment_t), intent(inout) :: fragment
      type(error_t), intent(out) :: error

      character(len=MAX_LINE_LEN) :: line, key, value
      integer :: io_stat, eq_pos
      logical :: in_indices
      in_indices = .false.

      do
         read (unit, '(A)', iostat=io_stat) line
         if (io_stat /= 0) then
            call error%set(ERROR_IO, "Unexpected end of file in %fragment")
            return
         end if

         line = adjustl(line)
         if (len_trim(line) == 0) cycle
         if (line(1:1) == '#' .or. line(1:1) == '!') cycle

         if (trim(strip_comment(line)) == 'end') then
            if (in_indices) then
               in_indices = .false.
               cycle
            else
               exit
            end if
         end if

         if (trim(line) == '%indices') then
            in_indices = .true.
            cycle
         end if

         if (in_indices) then
            ! Read indices
            call parse_indices_line(line, fragment, error)
            if (error%has_error()) then
               call error%add_context("mqc_config_parser:parse_fragment")
               return
            end if
         else
            eq_pos = index(line, '=')
            if (eq_pos > 0) then
               key = adjustl(line(1:eq_pos - 1))
               value = adjustl(line(eq_pos + 1:))

               select case (trim(key))
               case ('charge')
                  read (value, *, iostat=io_stat) fragment%charge
               case ('multiplicity')
                  read (value, *, iostat=io_stat) fragment%multiplicity
               case default
                  call error%set(ERROR_PARSE, "Unknown key in fragment properties: "//trim(key))
                  return
               end select
            end if
         end if
      end do

   end subroutine parse_fragment