      LOGICAL FUNCTION FIND_OPTION(LINE,COMMANDS,NSPECS,N,NP)
C
C     this logical function examines LINE to determine
C     which option it represents.  FIND_OPTION returns
C     true unless LINE contains an invalid option.
C     On return, N is the option number, and NP is the
C     offset in LINE at which any parameters begin.
C     If there are no parameters, NP is returned as 0.
C     COMMANDS contains the list of options to look for.
C     NSPECS is the number of options in the list.
C
      CHARACTER*(*) LINE
      CHARACTER*(*) COMMANDS(NSPECS)
      LOGICAL HIT
C
C     skip over initial blanks
C
      NB = 1
10    CONTINUE
      IF(LINE(NB:NB).NE.' ')GOTO 20
      NB = NB + 1
      IF(LEN(LINE).LT.NB)GOTO 58   ! bad value
      GOTO 10
20    CONTINUE
D     IF(NB.GT.1)TYPE *,'HERE ARE THE LEADING BLANKS : '//LINE(1:NB-1)
      DO 25 I = NB , LEN(LINE)
         IF(LINE(I:I).EQ.' ')GOTO 28
25    CONTINUE
      I = LEN(LINE)+1
28    LC = I - NB
C
C     now we need to find the rest of the line
C
      NP = INDEX(LINE(NB:),' ')
      IF(NP.EQ.0)GOTO 80
      NP = NP + NB - 1
70    CONTINUE
      IF(LINE(NP:NP).NE.' ')GOTO 80
      NP = NP + 1
      IF(LEN(LINE).GE.NP)GOTO 70
      NP = 0
80    CONTINUE
D     IF(NP.NE.0)TYPE *,'PARAMETERS : '//LINE(NP:)
C
C     check whether a valid response was given
C
      DO 40 I = 1 , LEN(COMMANDS(1))
C
C     first we check for 1 character matches, then 2s, up to the option length.
C     The checking is terminated when we find only one match
C     at a given level.
C
         HIT = .FALSE.
C
C        Initialize to no matches yet at this level
C
c        IF(LEN(LINE).LT.NB+I-1)GOTO 55   !  ambiguous at previous level
         IF(LC.LT.I)GOTO 55   !  ambiguous at previous level
C
C        make sure we don't exceed LINE length
C
         DO 30 J = 1 , NSPECS
            IF(LINE(NB:NB+I-1).EQ.COMMANDS(J)(1:I))THEN
C
C           we found a match
C
               IF(HIT)GOTO 40
C
C              if we already had one at this level, then we
C              need to look at more levels to resolve it
C
               HIT = .TRUE.
C
C              otherwise, we retain this command's number
C
               N = J
            END IF
30       CONTINUE
         IF(HIT)THEN
C
C           we found a unique match
C
            GOTO 60
         ELSE
C
C           we found no matches. abort the search.
C
            GOTO 50    ! bad value
         END IF
40    CONTINUE
C
C     Not a valid option
C
50    FIND_OPTION = .FALSE.
      N = -2
      RETURN
55    FIND_OPTION = .FALSE.
      N = -1
      RETURN
58    FIND_OPTION = .FALSE.
      N = -3
      RETURN
60    CONTINUE
      FIND_OPTION = .TRUE.
      RETURN
      END
