* Last processed by NICE on 12-Jun-2000 15:53:00
* Customized for :  IEEE, LINUX, UNIX, MOTIF, F77
*
* Written by r.neri May -1995
*
*  Gets either first found scan, next scan or previous scan.
*
*  GET FIRST or LAST or NEXT or PREVIOUS or SCAN_NUMBER
*
      SUBROUTINE GET_SCAN (LINE,ERROR)
*
*----------------------------------------------------------------------
*       Support routine for command
* Arguments :
*       LINE    C*(*)   Command line                    Input
*       ERROR   L       Logical error flag              Output
*
*----------------------------------------------------------------------
      CHARACTER*(*) LINE
      LOGICAL ERROR
*
      INCLUDE 'nic.inc'
      INCLUDE 'parameter.inc'
      INCLUDE 'par.inc'
*
      LOGICAL FOUND, NUMBER
      INTEGER I, NC, MVOCAB, SCAN
*
      PARAMETER (MVOCAB = 4)
      CHARACTER MODE(MVOCAB)*10, ARGUM1*14, SCAN_TEXT*22
*
      DATA MODE /'F','L','N','P'/
      DATA SCAN_TEXT /'FILE IN BOLO_DATA:0000'/
*
* Any GET possible ?
*
      SCAN = 0
      NUMBER = .TRUE.
      CALL SIC_KE(LINE,0,1,ARGUM1,NC,.FALSE.,ERROR)
      DO I=1,NC
         IF (ARGUM1(I:I).LT.'0'.OR.ARGUM1(I:I).GT.'9') THEN
            NUMBER = .FALSE.
         ENDIF
      ENDDO
      IF (NUMBER) THEN
         CALL SIC_I4(LINE,0,1,SCAN,.FALSE.,ERROR)
         IF (SCAN.GT.9999) THEN
            CALL MESSAGE(2,1,'GET','Illegal scan number')
            ERROR = .TRUE.
            RETURN
         ENDIF
      ELSE
         IF (IPSCANLIST.EQ.0.OR.MAXFOUND.EQ.0) THEN
            CALL MESSAGE(2,1,'GET','You need to execute FIND')
            ERROR = .TRUE.
            RETURN
         ENDIF
      ENDIF
*
* Options
*
      IF (.NOT.NUMBER) THEN
         ARGUM1 = 'N'
         CALL SIC_KE(LINE,0,1,ARGUM1,NC,.FALSE.,ERROR)
         IF (ERROR) GOTO 999
         FOUND = .FALSE.
         DO I=1,MVOCAB
            FOUND = (INDEX(MODE(I),ARGUM1(1:1)).NE.0).OR.FOUND
         ENDDO
         IF (.NOT.FOUND) THEN
            CALL MESSAGE(2,1,'GET','Bad parameter')
            ERROR = .TRUE.
            RETURN
         ENDIF
*
         IF (ARGUM1(1:1).EQ.'F'.OR.ARGUM1(1:1).EQ.'f') THEN
            ACTUALSCAN = 1
         ENDIF
         IF (ARGUM1(1:1).EQ.'L') THEN
            ACTUALSCAN = MAXFOUND
         ENDIF
         IF (ARGUM1(1:1).EQ.'N') THEN
            IF (ACTUALSCAN.GE.MAXFOUND) THEN
               CALL MESSAGE(2,1,'GET','End of scan list')
               ERROR = .TRUE.
               RETURN
            ELSE
               ACTUALSCAN = ACTUALSCAN + 1
            ENDIF
         ENDIF
         IF (ARGUM1(1:1).EQ.'P') THEN
            IF (ACTUALSCAN.EQ.1) THEN
               CALL MESSAGE(2,1,'GET','Begin of scan list')
               ERROR = .TRUE.
               RETURN
            ELSE
               ACTUALSCAN = ACTUALSCAN - 1
            ENDIF
         ENDIF
         WRITE (SCAN_TEXT(19:22),'(i4.4)')
     $   MEMORY(IPSCANLIST+(ACTUALSCAN-1))
      ELSE
         WRITE (SCAN_TEXT(19:22),'(i4.4)') SCAN
      ENDIF
*
      CALL EXEC_ALL (SCAN_TEXT)
*
999   RETURN
      END
