C (c) 1991 The Board of Trustees of the University of Illinois
C          "All Rights Reserved Under the Copyright Laws".

      PROGRAM INSTRM
      PARAMETER(MXCLAS = 10, MXLIST = 1000,MXINT=500)
C     COMMANDS ARE IN CMD FILE PIPED INTO THE PROGRAM
C     SO IS THE NAME OF THE INPUT FILE AND OUTPUT FILE.
C     THE FORMAT OF THE CMD FILE IS:
C$$$      NAME OF SRCFILE 
C$$$      NAME OF OUTFILE
C$$$      CLASSY
C$$$      0     (MAIN_ENTRY)
C$$$      5     (MAIN_EXIT)
C$$$      [1]   (DOENTRY)
C$$$      [2]   (DOEXIT)
C$$$      [3]   (SUBR_ENTRY)
C$$$      [4]   (SUBR_EXIT)
C$$$      [6]   (TR_COUNTER)
C$$$      [7]   (TR_COUNTER_DUMP)
C$$$
C$$$      [EVENT_RANGE]   (range of events to be activated )
C$$$      [start-event(I4)  end-event(I4)]
C$$$      [start-event(I4)  end-event(I4)]
C$$$      ...................................
C$$$      [EVENT_LISTY]   ( a space separated list of events )
C$$$      [event(I4)]
C$$$      [event(I4)]
C$$$      ...................................
c$$$      THE "[ ..]" notation means that the specification is optional
c$$$      To activate the X Library calls the same format of
c$$$      event-specification can be used as the one above, with the
c$$$      difference that the keywords will end in "X" instead of "Y".
c$$$      (e.g. CLASSX, EVENT_RANGEX, EVENT_LISTX.)
c$$$      The order of these event-specifications groups in the file is
c$$$      not relevant.

      COMMON/EVBNDS/EVLOHI
      COMMON/EVLST/EVLIST
      COMMON/EVCLAS/CLASS
      INTEGER EVLOHI(2,2,MXINT)
      INTEGER EVLIST(2,MXLIST)
      INTEGER CLASS(2,MXCLAS)
      INTEGER NUMCL(2), NUMEVS(2), NUMINT(2)
      CHARACTER*(72) LINE
      INTEGER CL, EV

      DO 1 J=1,MXLIST
         EVLIST(1,J)=0
         EVLIST(2,J)=0
 1    CONTINUE
      DO 2 J=1,MXCLAS
      CLASS(1,J)=0
      CLASS(2,J)=0
 2    CONTINUE
      DO 3 J=1,MXINT
         EVLOHI(1,1,J)=0
         EVLOHI(2,1,J)=0
         EVLOHI(1,2,J)=0
         EVLOHI(2,2,J)=0
 3    CONTINUE
C
      DATA NUMCL /2*0/
      DATA NUMEVS /2*0/
      DATA NUMINT /2*0/

      CALL  RDCMD(NUMCL, NUMEVS, NUMINT)
      I = 1

 10   CONTINUE

      READ (1,20,ERR=300,END=400) LINE
 20   FORMAT(A)


      IF ((LINE(1:2) .EQ. 'CX') .OR. (LINE(1:2) .EQ. 'CY')) THEN
         IF (LINE(1:2) .EQ. 'CX') THEN
            INDEX = 1
         ELSE
            INDEX = 2
         ENDIF
         READ(UNIT=LINE(3:7),FMT=30,ERR=90) CL,EV
 30      FORMAT(I1,I4)
         DO 60 J=1,NUMCL(INDEX)
            IF (CL .EQ. CLASS(INDEX,J)) THEN
               LINE(1:7) = '       '
            ENDIF
 60      CONTINUE
         DO 70 J=1,NUMINT(INDEX)
            IF ((EV .GE. EVLOHI(INDEX,1,J)) .AND.
     $           (EV .LE. EVLOHI(INDEX,2,J))) THEN
               LINE(1:7) = '       '
            ENDIF

 70      CONTINUE

         DO 80 J=1,NUMEVS(INDEX)
            IF (EV .EQ. EVLIST(INDEX,J)) THEN
               LINE(1:7) = '       '
            ENDIF
 80      CONTINUE

      ENDIF
 90   CONTINUE
      WRITE(2,20) LINE
      I = I+1
      GOTO 10

 300  WRITE(6,310) SRCFIL,I
 310  FORMAT( 'ERROR IN READING SOURCEFILE',A,'IN LINE',I4)
 400  CONTINUE
      CLOSE(1)
      CLOSE(2)
      END






CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
 
      SUBROUTINE RDCMD(NUMCL, NUMEVS, NUMINT)
      PARAMETER(MXCLAS = 10, MXLIST = 1000,MXINT=500)
      COMMON/EVBNDS/EVLOHI
      COMMON/EVLST/EVLIST
      COMMON/EVCLAS/CLASS
      INTEGER EVLOHI(2,2,MXINT)
      INTEGER EVLIST(2,MXLIST)
      INTEGER CLASS(2,MXCLAS)
      INTEGER NUMCL(2), NUMEVS(2), NUMINT(2)
      INTEGER CL,LO,HI,EV
      CHARACTER*(72) LINE
      CHARACTER*(20) SRCFIL, OUTFIL
      CHARACTER*(20) EVSPEC
      DATA SRCFIL / '                    '/
      DATA OUTFIL / '                    '/
      DATA EVSPEC / '                    '/


      READ(*,10) SRCFIL
      READ(*,10) OUTFIL

      OPEN(UNIT=1,FILE=SRCFIL,STATUS='OLD')
      OPEN(UNIT=2,FILE=OUTFIL)
      

      READ(*,10,END=300,ERR=200) LINE
 25   READ(UNIT=LINE,FMT=10,ERR=200) EVSPEC
      IF ((EVSPEC .EQ. 'CLASSX') .OR.
     $     (EVSPEC .EQ. 'CLASSY')) THEN
         IF  (EVSPEC .EQ. 'CLASSX') THEN
            INDEX = 1
         ELSE 
            INDEX = 2
         ENDIF
         
 100     READ(*,10,END=300,ERR=200) LINE
          IF ((LINE .EQ. 'EVENT_RANGEX') .OR.
     $        (LINE .EQ. 'EVENT_RANGEY') .OR. 
     $        (LINE .EQ. 'EVENT_LISTX') .OR.
     $        (LINE .EQ. 'EVENT_LISTY'))  GOTO 25
         READ(UNIT=LINE,FMT=40,ERR=25) CL      
         NUMCL(INDEX) = NUMCL(INDEX) +1
         CLASS(INDEX,NUMCL(INDEX)) = CL
         GOTO 100
      ELSE IF ((EVSPEC .EQ. 'EVENT_RANGEX') .OR.
     $        (EVSPEC .EQ. 'EVENT_RANGEY')) THEN
         IF (EVSPEC .EQ. 'EVENT_RANGEX') THEN 
            INDEX  = 1
         ELSE
            INDEX = 2
         ENDIF
         
 110     READ(*,10,END=300,ERR=200) LINE
          IF ((LINE .EQ. 'EVENT_RANGEX') .OR.
     $        (LINE .EQ. 'EVENT_RANGEY') .OR. 
     $        (LINE .EQ. 'EVENT_LISTX') .OR.
     $        (LINE .EQ. 'EVENT_LISTY'))  GOTO 25
         READ(UNIT=LINE,FMT=60,ERR=25) LO,HI
         NUMINT(INDEX) = NUMINT(INDEX) + 1
         EVLOHI(INDEX,1,NUMINT(INDEX)) = LO
         EVLOHI(INDEX,2,NUMINT(INDEX)) = HI
         GOTO 110
         
      ELSE IF ((EVSPEC .EQ. 'EVENT_LISTX') .OR.
     $        (EVSPEC .EQ. 'EVENT_LISTY')) THEN
         IF  (EVSPEC .EQ. 'EVENT_LISTX') THEN 
            INDEX = 1
         ELSE
            INDEX = 2
         ENDIF

 120     READ(*,10,END=300,ERR=200) LINE
          IF ((LINE .EQ. 'EVENT_RANGEX') .OR.
     $        (LINE .EQ. 'EVENT_RANGEY') .OR. 
     $        (LINE .EQ. 'EVENT_LISTX') .OR.
     $        (LINE .EQ. 'EVENT_LISTY'))  GOTO 25

         READ(UNIT=LINE,FMT=40,ERR=25) EV
         NUMEVS(INDEX) = NUMEVS(INDEX)+1
         EVLIST(INDEX,NUMEVS(INDEX))=EV
         GOTO 120
      ENDIF

 200  PRINT *,'ERROR IN READING SELECTION FILE'
 300  CONTINUE
 10   FORMAT(A)
 40   FORMAT(I4)
 60   FORMAT(2I4)
      CALL SELECT(NUMCL, NUMEVS, NUMINT)
      RETURN
      END
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

      SUBROUTINE SELECT(NUMCL, NUMEVS, NUMINT)
      PARAMETER(MXCLAS = 10, MXLIST = 1000,MXINT=500)
      COMMON/EVBNDS/EVLOHI
      COMMON/EVLST/EVLIST
      COMMON/EVCLAS/CLASS
      INTEGER EVLOHI(2,2,MXINT)
      INTEGER EVLIST(2,MXLIST)
      INTEGER CLASS(2,MXCLAS)
      INTEGER NUMCL(2), NUMEVS(2), NUMINT(2)

      IF ( (NUMCL(1)+NUMCL(2)).GT.0) THEN
         PRINT *,' SELECTED EVENT CLASSES ARE: '
         DO 100 J=1,NUMCL(1)
            PRINT *,' CLASSX :',CLASS(1,J)
 100     CONTINUE
         DO 600 J=1,NUMCL(2)
            PRINT *,' CLASSY :',CLASS(2,J)
 600     CONTINUE
      ENDIF

      IF ( (NUMINT(1) + NUMINT(2)).GT.0 ) THEN
         PRINT *,' SELECTED EVENT RANGES ARE: '
         DO 200 J=1,NUMINT(1)
            PRINT *,' EVENT LOW X: ',EVLOHI(1,1,J),' EVENT HIGH X: ',
     $           EVLOHI(1,2,J)
 200     CONTINUE
         DO 700 J=1,NUMINT(2)
            PRINT *,' EVENT LOW Y: ',EVLOHI(2,1,J),' EVENT HIGH Y: ',
     $           EVLOHI(2,2,J)
 700     CONTINUE
      ENDIF

      IF ( (NUMEVS(1)+NUMEVS(2)) .GT. 0 ) THEN
         PRINT *,' SELECTED EVENT LIST IS: '
         DO 300 J=1,NUMEVS(1)
            PRINT *,' EVENT LIST X: ',EVLIST(1,J)
 300     CONTINUE
         DO 800 J=1,NUMEVS(2)
            PRINT *,' EVENT LIST Y: ',EVLIST(2,J)
 800     CONTINUE
      ENDIF
      RETURN
      END


