count_shells_for_element Subroutine

private 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,

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: basis_string
character(len=*), intent(in) :: element_name
integer, intent(out) :: nshells
type(error_t), intent(out) :: error

Calls

proc~~count_shells_for_element~~CallsGraph proc~count_shells_for_element count_shells_for_element proc~classify_line classify_line proc~count_shells_for_element->proc~classify_line proc~error_set error_t%error_set proc~count_shells_for_element->proc~error_set proc~get_next_line get_next_line proc~count_shells_for_element->proc~get_next_line proc~strings_equal strings_equal proc~count_shells_for_element->proc~strings_equal proc~is_blank_or_control is_blank_or_control proc~classify_line->proc~is_blank_or_control proc~is_function_line is_function_line proc~classify_line->proc~is_function_line proc~is_shell_header is_shell_header proc~classify_line->proc~is_shell_header

Called by

proc~~count_shells_for_element~~CalledByGraph proc~count_shells_for_element count_shells_for_element proc~parse_element_basis parse_element_basis proc~parse_element_basis->proc~count_shells_for_element proc~build_molecular_basis build_molecular_basis proc~build_molecular_basis->proc~parse_element_basis

Variables

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

Source Code

   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