* Last processed by NICE on 12-Jun-2000 15:53:00
* Customized for :  IEEE, LINUX, UNIX, MOTIF, F77
      SUBROUTINE INCLUDE (LINE,COMM,ERROR)
      CHARACTER*(*) LINE,COMM
      LOGICAL ERROR
*
      INCLUDE 'setup.inc'
      EXTERNAL GET_SCANS,GET_SOURCES
*
      LOGICAL SIC_PRESENT
      CHARACTER*12 ARGUM
      REAL*4 TMIN,TMAX
      INTEGER*4 NA
*
      IF (SIC_PRESENT(1,0)) THEN
         CALL SIC_CH (LINE,1,1,ARGUM,NA,.FALSE.,ERROR)
         IF (ERROR) RETURN
         IF (ARGUM.EQ.'*') THEN
            CALL GET_ALL(NPT)
            FITTED = .FALSE.
         ELSE
            CALL DO_LIST (LINE,1,1,ERROR,GET_SCANS)
            FITTED = .FALSE.
         ENDIF
      ENDIF
      IF (SIC_PRESENT(2,0)) THEN
         CALL SIC_CH (LINE,2,1,ARGUM,NA,.FALSE.,ERROR)
         IF (ERROR) RETURN
         IF (ARGUM.EQ.'*') THEN
            CALL GET_ALL(NPT)
            FITTED = .FALSE.
         ELSE
            CALL DO_LIST (LINE,2,1,ERROR,GET_SOURCES)
            FITTED = .FALSE.
         ENDIF
      ENDIF
      IF (SIC_PRESENT(3,0)) THEN
         CALL SIC_R4 (LINE,3,2,TMAX,.TRUE.,ERROR)
         IF (ERROR) RETURN
         CALL SIC_R4 (LINE,3,1,TMIN,.TRUE.,ERROR)
         IF (ERROR) RETURN
         CALL GET_TI (NPT,TMIN,TMAX)
         FITTED = .FALSE.
      ENDIF
      END
*<FF>
      SUBROUTINE IGNORE (LINE,COMM,ERROR)
      CHARACTER*(*) LINE,COMM
      LOGICAL ERROR
*
      INCLUDE 'setup.inc'
      EXTERNAL FLAG_SCANS,FLAG_SOURCES
*
      LOGICAL SIC_PRESENT
      REAL*4 TMIN,TMAX
*
      IF (SIC_PRESENT(2,0)) THEN
         CALL DO_LIST (LINE,2,1,ERROR,FLAG_SOURCES)
         FITTED = .FALSE.
      ENDIF
      IF (SIC_PRESENT(1,0)) THEN
         CALL DO_LIST (LINE,1,1,ERROR,FLAG_SCANS)
         FITTED = .FALSE.
      ENDIF
      IF (SIC_PRESENT(3,0)) THEN
         CALL SIC_R4 (LINE,3,2,TMAX,.TRUE.,ERROR)
         IF (ERROR) RETURN
         CALL SIC_R4 (LINE,3,1,TMIN,.TRUE.,ERROR)
         IF (ERROR) RETURN
         CALL FLAG_TI (NPT,TMIN,TMAX)
         FITTED = .FALSE.
      ENDIF
      END
*<FF>
      SUBROUTINE REJECT (LINE,COMM,ERROR)
      CHARACTER*(*) LINE,COMM
      LOGICAL ERROR
*
      INCLUDE 'setup.inc'
      REAL RMSERR
*
      CALL SIC_R4  (LINE,0,1,RMSERR,.TRUE.,ERROR)
      IF (ERROR) RETURN
      FITTED = .FALSE.
      CALL FLAG_RE (NDATA,RMSERR)
      END
*<FF>
      SUBROUTINE DO_LIST (LINE,IOPT,JARG,ERROR,FUNC)
C----------------------------------------------------------------------
C GREG	Internal routine
C 	Decode a list of numbers in the following format
C	(CHAIN =) n1 n2 n3 TO n4 n5 n6 n7 TO n8 BY n9
C	The list will contain
C	n1,n2, n3,n3+1,...,n4, n5, n6,n6+n9,n6+2*n9,...,n7
C Arguments :
C	I1	R*8 (*)	Array of start value of loop
C	I2	R*8 (*)	Array of end value of loop
C	I3	R*8 (*)	Array of increment value of loop
C	MAXK	I	Size of arrays
C	M	I	Number of loops				Output
C	CHAIN	C*(*)	String to be decoded			Input
C	ERROR	L	Logical error flag			Output
C Subroutines :
C	(SIC-SIC_NEXT,SIC_MATH)
C----------------------------------------------------------------------
      CHARACTER*(*) LINE
      INTEGER IOPT,JARG
      EXTERNAL FUNC
      LOGICAL ERROR
*
      CHARACTER*132 PAR
      LOGICAL FIRST,FTO,FBY
      INTEGER LPAR,IARG,KARG,NARG, SIC_NARG
      REAL*8 DBLE
      INTEGER LOOP(3)
*
      ERROR = .FALSE.
      FTO = .FALSE.
      FBY = .FALSE.
      KARG = 1
      IARG = JARG
      NARG = SIC_NARG(IOPT)
      FIRST = .TRUE.
*
      DO WHILE (IARG.LE.NARG)
         IF (KARG.GE.0) THEN
            CALL SIC_CH (LINE,IOPT,IARG,PAR,LPAR,.TRUE.,ERROR)
            IF (ERROR) GOTO 100
         ENDIF
*
* First argument
         IF (KARG.LE.1) THEN
            IF (PAR(1:LPAR).EQ.'TO') THEN
*
* Following a BY Increment or implicit BY 1 : cannot be TO
               IF (KARG.LE.0) THEN
                  GOTO 100
               ELSE
                  KARG = 2
               ENDIF
*
* New Loop: First Value
            ELSE
               IF (.NOT.FIRST)  CALL FUNC(LOOP)
               FIRST = .FALSE.
               CALL SIC_MATH (PAR,LPAR,DBLE,ERROR)
               IF (ERROR) GOTO 100
               LOOP(1) = NINT(DBLE)
               LOOP(2) = LOOP(1)
               LOOP(3) = 1
               KARG =1
            ENDIF
*
* TO was found: Item is now Last value
         ELSEIF (KARG.EQ.2) THEN
            CALL SIC_MATH (PAR,LPAR,DBLE,ERROR)
            IF (ERROR) GOTO 100
            LOOP(2)=NINT(DBLE)
            KARG = 3
*
* TO End was found: Item may be BY
         ELSEIF (KARG.EQ.3) THEN
            IF (PAR(1:LPAR).EQ.'BY') THEN
               KARG = 4
            ELSEIF (PAR(1:LPAR).EQ.'TO') THEN
               GOTO 100
            ELSE
               KARG = -1
            ENDIF
*
* BY was found: Item is increment
         ELSEIF (KARG.EQ.4) THEN
            CALL SIC_MATH (PAR,LPAR,DBLE,ERROR)
            IF (ERROR) GOTO 100
            LOOP(3) = NINT(DBLE)
            IF (LOOP(3).EQ.0) LOOP(3)=1
            KARG = 0
         ENDIF
         IF (KARG.GE.0) IARG = IARG+1
      ENDDO
      IF (.NOT.FIRST) CALL FUNC(LOOP)
      RETURN
*
100   CALL GAGOUT('E-LIST,  Syntax error in list')
      ERROR = .TRUE.
      RETURN
      END
*<FF>
      SUBROUTINE GET_SCANS (LOOP)
      INTEGER LOOP(3)
      INTEGER I
      INCLUDE 'setup.inc'
*
      DO I=LOOP(1),LOOP(2),LOOP(3)
         CALL GET_SCAN (NPT,I)
      ENDDO
      END
*<FF>
      SUBROUTINE GET_SOURCES (LOOP)
      INTEGER LOOP(3)
      INTEGER I
      INCLUDE 'setup.inc'
*
      DO I=LOOP(1),LOOP(2),LOOP(3)
         CALL GET_SOURCE (NPT,I)
      ENDDO
      END
*<FF>
      SUBROUTINE FLAG_SCANS (LOOP)
      INTEGER LOOP(3)
      INTEGER I
      INCLUDE 'setup.inc'
*
      DO I=LOOP(1),LOOP(2),LOOP(3)
         CALL FLAG_SCAN (NPT,I)
      ENDDO
      END
*<FF>
      SUBROUTINE FLAG_SOURCES (LOOP)
      INTEGER LOOP(3)
      INTEGER I
      INCLUDE 'setup.inc'
*
      DO I=LOOP(1),LOOP(2),LOOP(3)
         CALL FLAG_SOURCE (NPT,I)
      ENDDO
      END
