symbol_to_number Subroutine

public elemental subroutine symbol_to_number(number, symbol)

Convert element symbol to atomic number

Arguments

Type IntentOptional Attributes Name
integer, intent(out) :: number

Atomic number

character(len=*), intent(in) :: symbol

Element symbol


Source Code

elemental subroutine symbol_to_number(number, symbol)

   !> Element symbol
   character(len=*), intent(in) :: symbol

   !> Atomic number
   integer, intent(out) :: number

   character(len=2) :: lcsymbol
   integer :: i, j, k, l

   number = 0
   lcsymbol = '  '

   k = 0
   do j = 1, len_trim(symbol)
      if (k > 2) exit
      l = iachar(symbol(j:j))
      if (k >= 1 .and. l == iachar(' ')) exit
      if (k >= 1 .and. l == 9) exit
      if (l >= iachar('A') .and. l <= iachar('Z')) l = l + offset
      if (l >= iachar('a') .and. l <= iachar('z')) then
         k = k+1
         if (k > 2) exit
         lcsymbol(k:k) = achar(l)
      endif
   enddo

   do i = 1, size(lcpse)
      if (lcsymbol == lcpse(i)) then
         number = i
         exit
      endif
   enddo

   if (number == 0) then
      select case(lcsymbol)
      case('d ', 't ')
         number = 1
      end select
   end if

end subroutine symbol_to_number