Count the number of shells for a specific element in a GAMESS formatted basis string,
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | basis_string | |||
| character(len=*), | intent(in) | :: | element_name | |||
| integer, | intent(out) | :: | nshells | |||
| type(error_t), | intent(out) | :: | error |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=1), | private | :: | ang_mom | ||||
| logical, | private | :: | found_element | ||||
| logical, | private | :: | in_target_element | ||||
| character(len=256), | private | :: | line | ||||
| integer, | private | :: | line_end | ||||
| integer, | private | :: | line_start | ||||
| integer, | private | :: | line_type |
pure subroutine count_shells_for_element(basis_string, element_name, nshells, error) !! Count the number of shells for a specific element in a GAMESS formatted basis string, character(len=*), intent(in) :: basis_string character(len=*), intent(in) :: element_name integer, intent(out) :: nshells type(error_t), intent(out) :: error integer :: line_start, line_end, line_type character(len=256) :: line logical :: in_target_element, found_element character(len=1) :: ang_mom nshells = 0 in_target_element = .false. found_element = .false. line_start = 1 do while (line_start <= len(basis_string)) call get_next_line(basis_string, line_start, line, line_end) if (line_end == 0) exit line = adjustl(line) line_type = classify_line(line) select case (line_type) case (LINE_ATOM) ! Check if this is our target element if (strings_equal(line, element_name)) then in_target_element = .true. found_element = .true. else ! Different element - stop counting if we were in target if (in_target_element) exit in_target_element = .false. end if case (LINE_SHELL) if (in_target_element) then ! Extract angular momentum line = adjustl(line) ang_mom = line(1:1) ! L shells become 2 shells (S + P) if (ang_mom == 'L') then nshells = nshells + 2 else nshells = nshells + 1 end if end if case (LINE_UNKNOWN) ! Skip blank lines and comments continue case default ! Skip any other line types (e.g., LINE_FUNCTION) continue end select line_start = line_end end do ! Check if we found the element at all if (.not. found_element) then call error%set(ERROR_PARSE, "Element not found in basis string: "//trim(element_name)) end if end subroutine count_shells_for_element