C     .TITLE FILMCO
C
C  10 JAN 75 (PDH) DROP ALL FILTERS AT END OF FRAME
C   3 JAN 75 - PAUL HENDERSON
C
C  ACCUMULATOR SWITCH SETTINGS:
C
C   0 - TYPE HOW MUCH CORE AVAILABLE FOR 'DISPLY' FILES
C   1 - DEBUGGING AID: WRITE, UNIT, K, FRAME
C   2 - BYPASS CALLS TO 'SHUTTR'
C  16 - PAUSE BEFORE PAINTING IMAGE WITH PARTICULAR COLOUR
C  17 - PAUSE AT END OF FRAME TO ALLOW MANUAL FILM ADVANCE
C
C  PROGRAM TO RETRIEVE DATA FILES AND FILM THEM
C
      LOGICAL T/.TRUE./,F/.FALSE./,ERROR/.FALSE./,ISENSW
      INTEGER SIZE,PAINTS,UNIT/2/,INDEX,FRAME
      INTEGER COLOUR(3,4)/0,0,63, 16,23,0, 31,0,0, 0,24,31/
C
C  THE SEQUENCE OF 'DPASS' VALUES IN 'COLOUR' IS BLUE-GREEN-RED.
C  BECAUSE OF SYSTEM SOFTWARE DIFFICULTIES, THE LAST 'DPASS' VALUE
C  IN EACH SUB-PICTURE IS REDUCED BY ONE.  THIS IS PICKED UP
C  BY THE SYSTEM, WHETHER WE WANT IT OR NOT.
C
      COMMON /OIL/IVECT(600)
C
   1  CALL CLEAR (T)
      CALL DISPLY (0,20000,IGET)
      IF (ISENSW(0)) WRITE (4,*) 'ASK 20000; GET',IGET
      CALL OPEN (2,'COOPS2BIN')
      CALL OPEN (3,'COOPS3BIN')
C
C  READ FIRST RECORD TO GET PROCESS UNDERWAY
C
      READ (UNIT) INDEX,FRAME
C
C  PROCEED THROUGH THE FRAME SEQUENCES VIA A DO-LOOP
C
      DO 220 K=1,11
C
C  ALSO USE DO-LOOP TO PROCESS SUB-PICTURES
C
      DO 200 J=1,4
      ITAG = 0
      GO TO 101
C
 100  READ (UNIT,END=110) INDEX,FRAME
 101  IF (INDEX .NE. J) GO TO 110
C
      READ (UNIT) SIZE
      READ (UNIT)(IVECT(I),I=1,SIZE)
C
C  STORE PICTURE FILES WITH SEQUENTIAL TAG NUMBERS
C
      ITAG = ITAG + 1
      CALL DISPLY (1,ITAG,IVECT,1,SIZE)
      GO TO 100
C
C  STOP DISPLAY PRIOR TO TURNING ON THE PICTURE FILES
C
 110  CALL DSTOP
      WRITE (4,999) K,J
      DO 120 I=1,ITAG
      CALL DISPLY (4,I)
 120  CONTINUE
C
C  OPEN SHUTTER
C
      IF (ISENSW(2)) GO TO 130
      CALL SHUTTR (T,ERROR)
      IF (ERROR) WRITE (4,*) 'SHUTTER ALREADY OPEN'
C
C  NOW PROCESS THE SUB-PICTURE FOR EACH COMPONENT COLOUR
C
 130  DO 180 I=1,3
      PAINTS = COLOUR(I,J)
      IF (PAINTS .EQ. 0) GO TO 180
C
C  BRANCH TO PROPER SELECTION OF BLUE, GREEN, OR RED
C
      GO TO (140,150,160),I
C
 140  CALL BLUE
      IF (ISENSW(16)) PAUSE 1
      GO TO 170
C
 150  CALL GREEN
      IF (ISENSW(16)) PAUSE 2
      GO TO 170
C
 160  CALL RED
      IF (ISENSW(16)) PAUSE 3
C
 170  CALL DPASS (PAINTS)
 180  CONTINUE
C
C  DELETE ALL EXISTING DISPLAY FILES
C
      CALL DGO
      CALL DISPLY (8)
C
C  DROP ALL FILTERS TO PRODUCE BLACK IMAGE
C
      CALL SWITCH (1,F,2,F,3,F)
 200  CONTINUE
C
C  ALL PICTURES FOR A COMPLETE FRAME HAVE BEEN FILMED.  CLOSE SHUTTER.
C
      IF (ISENSW(2)) GO TO 210
      CALL SHUTTR (F,ERROR)
      IF (ERROR) WRITE (4,*) 'SHUTTER ALREADY CLOSED'
 210  IF (ISENSW(17)) PAUSE 4
C
C  SPECIAL ACTION TO BE TAKEN AT END OF 6TH FRAME.
C
      IF (K .EQ. 6) UNIT = 3
      IF (K .EQ. 6) READ (UNIT) INDEX,FRAME
      IF (ISENSW(1)) WRITE (4,998) UNIT,K,FRAME
 220  CONTINUE
      STOP
 999  FORMAT (' FRAME',I3,' PART',I2)
 998  FORMAT ('   UNIT K FRAME',3I3)
      END
