      integer*4 function itch (string, ier)

c  Alternative to RAL function ITEM DH/15 using character variable

c  Assumes a character variable in string is to be converted
c     to a binary integer.
c  Leading blanks are treated as zeros.
c  Embedded blanks are not allowed.
c  A blank character other than a leading blank terminates the
c     string.
c  Plus or minus signs, when used, must prefix the digits with
c     no embedded blanks.

c  IER returns 0 if no digits were found
c             +n number terminated at byte n, by space or
c                end of string
c             -n error found at byte n

      character*(*) string
      logical more

      itch = 0
      length = len(string)
      i = 1
      ier = 0
      more = .true.
      do while (i .le. length .and. more)
        more = string(i:i) .eq. ' '
        if (more) i = i + 1
      end do
      if (i .le. length) then         ! all blanks
        jsign = 1
        if (string(i:i) .eq. '+') then
          i = i + 1
        else if (string(i:i) .eq. '-') then
          jsign = -1
          i = i + 1
        end if
        if (i .le. length) then               ! only a sign
          do while (i .le. length .and. ier .eq. 0)
            if (string(i:i) .eq. ' ') then
              ier = i
            else if (string(i:i) .ge. '0' .and. string(i:i) .le. '9')
     2      then
              itch = itch*10 + ichar(string(i:i)) - ichar('0')
              i = i + 1
            else
              ier = -i
            end if
          end do
          if (ier .eq. 0) ier = i - 1
          itch = jsign * itch
        end if
      end if
      return
      end
