C   07/06/96 606071833  MEMBER NAME  BSEP     (S4)          FORTG1
      SUBROUTINE BSEQ(MARK)
C     BOS SUBPROGRAM =3.9=
#include "acs.for"
      COMMON/BCS/IW(1)
      INTEGER LIMSEC/2/,LIMREC/0/,IUNIT/1/,NUNIT/0/,NUNITS(3)/3*0/
      IF(MARKWR.GE.0) GOTO 2
C     INITIALIZE
      I=JUHR(LIMSEC)
      NREC=0
      IUNIT=1
      KUNIT=1
      IF(NUNIT.NE.0) IUNIT=NUNITS(1)
      WRITE(6,101) IUNIT,LIMREC,LIMSEC
      MARKWR=0
    2 MARK=0
      IF(MARKWR.EQ.0) GOTO 20
C----- OUTPUT - WRITE LAST EVENT, IF MARKED
      CALL BSLW
      DO 14 I=1,MARKWR
      IUN=NOUT(I)
      IF(IUN.LE.0) GOTO 14
   10 CALL BWRS(IUN,NBUFL,INIW)
      IF(INIW.EQ.0) GOTO 12
      CALL WRFIX(IUN,NBUFL,IW(INIW))
      GOTO 10
   12 NOUT(I)=-IUN
   14 CONTINUE
C----- DELETE LAST EVENT AND MAKE GARBAGE COLLECTION
   20 CALL BSLT
      CALL BDLG
C----- CHECK TIME AND NR OF RECORDS
      IF(JUHR(LIMSEC).EQ.1) GOTO 22
      WRITE(6,102)
      CALL MSGTXT('TIMELIMIT')
      GOTO 40
   22 IF(LIMREC.EQ.0.OR.NREC.LT.LIMREC) GOTO 24
      WRITE(6,103)
      CALL MSGTXT('RECDLIMIT')
      GOTO 40
   24 NREC=NREC+1
C----- INPUT - READ NEXT EVENT
   30 MARKWR=0
   32 CALL BRDS(IUNIT,NBUFL,INIR)
      IF(INIR.EQ.0) GOTO 100
      CALL RDVAR(IUNIT,IW(INIR),IW(INIR+1),NBUFL)
      IF(IW(INIR).GE.0) GOTO 32
      WRITE(6,104) IUNIT
      IF(KUNIT.GE.NUNIT) GOTO 40
      REWIND IUNIT
      KUNIT=KUNIT+1
      IUNIT=NUNITS(KUNIT)
      WRITE(6,105) IUNIT
      GOTO 30
C----- END OF INPUT - WRITE LAST BUFFER
   40 CALL BMLT(0,DUMMY)
      IF(MARKWR.LE.0) GOTO 46
      DO 44 I=1,MARKWR
      IUN=IABS(NOUT(I))
      IF(IUN.EQ.0) GOTO 44
   42 CALL BWRS(IUN,NBUFL,INIW)
      IF(INIW.EQ.0) GOTO 44
      CALL WRFIX(IUN,NBUFL,IW(INIW))
   44 CONTINUE
C----- MARK END OF INPUT
   46 MARK=1
      MARKWR=-1
      NUNIT=0
      GOTO 100
C----- RETURN
      ENTRY BSEW(MARK)
C----- OUTPUT - DEFINE MARKER FOR OUTPUT
      IF(MARK.EQ.0) GOTO 100
      MARKA=IABS(MARK)
      IF(MARKWR.LE.0) GOTO 52
      DO 50 I=1,MARKWR
      IF(MARKA.EQ.IABS(NOUT(I))) GOTO 54
   50 CONTINUE
      IF(MARKWR.EQ.3) GOTO 100
   52 MARKWR=MARKWR+1
      IF(MARKWR.LE.0) MARKWR=1
      I=MARKWR
   54 NOUT(I)=MARK
      GOTO 100
C
      ENTRY BSET(MARK)
      LIMSEC=MARK
      GOTO 100
C
      ENTRY BSEL(MARK)
      LIMREC=MARK
      GOTO 100
C
      ENTRY ASVBS(MARK)
      ENTRY BSEU(MARK)
      IF(NUNIT.GE.3) GOTO 100
      NUNIT=NUNIT+1
      NUNITS(NUNIT)=MARK
  100 RETURN
  101 FORMAT('0++++ BSEQ START UNIT',I3,'   -  END WILL BE AFTER',I6,
     1   ' RECORDS OR',I3,' SECONDS BEFORE TIMEOVFL'/)
  102 FORMAT('0++++ BSEQ END OF READING  -  TIME LIMIT REACHED'/)
  103 FORMAT('0++++ BSEQ END OF READING  -  RECORD LIMIT REACHED'/)
  104 FORMAT('0++++ BSEQ                 -  END-OF-DATA ON UNIT',I3/)
  105 FORMAT('0++++ BSEQ START UNIT',I3/)
      END
