c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1990  by  Jay William Ponder  ##
c     ##              All Rights Reserved              ##
c     ###################################################
c
c     ################################################################
c     ##                                                            ##
c     ##  subroutine getword  --  extract first word from a string  ##
c     ##                                                            ##
c     ################################################################
c
c
c     "getword" searchs an input string for the first alphabetic
c     character (A-Z or a-z); the region from this first character
c     to the first blank space or comma is returned as a "word"; if
c     the actual word is too long, only the first part is returned
c
c     string    input character string to be searched
c     word      output with the first word in the string
c     next      input with first position of search string;
c                  output with position following word
c
c
      subroutine getword (string,word,next)
      implicit none
      integer i,j,len,length,size,next
      integer first,last,extent,initial,final
      character*1 letter
      character*(*) string,word
c
c
c     get the length of input string and output word
c
      length = len(string(next:))
      size = len(word)
c
c     move through the string one character at a time,
c     searching for the first alphabetic character
c
      first = 1
      last = 0
      initial = next
      final = next + length - 1
      do i = initial, final
         letter = string(i:i)
         if ((letter.ge.'A' .and. letter.le.'Z') .or.
     &       (letter.ge.'a' .and. letter.le.'z')) then
            first = i
            do j = i+1, final
               if (string(j:j).le.' ' .or. string(j:j).eq.',') then
                  last = j - 1
                  next = j
                  goto 10
               end if
            end do
         end if
      end do
   10 continue
c
c     trim the actual word if it is too long to return
c
      extent = next - first
      final = first + size - 1
      if (extent .gt. size)  last = final
c
c     transfer the word into the return string
c
      j = 0
      do i = first, last
         j = j + 1
         word(j:j) = string(i:i)
      end do
      do i = next, final
         j = j + 1
         word(j:j) = ' '
      end do
c
c     skip over the next character when it is a comma
c
      if (string(next:next) .eq. ',')  next = next + 1
      return
      end
