Parse a single %molecule block with its sections
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | unit | |||
| type(molecule_t), | intent(inout) | :: | mol | |||
| type(error_t), | intent(out) | :: | error |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private | :: | eq_pos | ||||
| 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 |
subroutine parse_single_molecule(unit, mol, error) !! Parse a single %molecule block with its sections integer, intent(in) :: unit type(molecule_t), intent(inout) :: mol type(error_t), intent(out) :: error character(len=MAX_LINE_LEN) :: line, key, value integer :: io_stat, eq_pos do read (unit, '(A)', iostat=io_stat) line if (io_stat /= 0) then call error%set(ERROR_IO, "Unexpected end of file in %molecule") 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') exit ! Check for key=value pairs (like name) eq_pos = index(line, '=') if (eq_pos > 0) then key = adjustl(line(1:eq_pos - 1)) value = adjustl(line(eq_pos + 1:)) if (trim(key) == 'name') then mol%name = trim(value) cycle end if end if ! Check for subsections if (line(1:1) == '%') then select case (trim(line)) case ('%structure') call parse_molecule_structure(unit, mol, error) case ('%geometry') call parse_molecule_geometry(unit, mol, error) case ('%fragments') call parse_molecule_fragments(unit, mol, error) case ('%connectivity') call parse_molecule_connectivity(unit, mol, error) case default ! Skip unknown subsections call skip_to_end(unit, error) end select if (error%has_error()) then call error%add_context("mqc_config_parser:parse_single_molecule") return end if end if end do end subroutine parse_single_molecule