C   21/11/78 C9071601   MEMBER NAME  ZBOS08   (S)           FORTRAN
      SUBROUTINE BSCOM
C     -----------------------------------------------------------------800000200
C     8.  UNFORMATED INPUT/OUTPUT OF BANKS
C
C     BANK RECORDS ARE OF THE FORM
C        NTOT, BANK1, BANK2, . . . BANKN
C     WITH NTOT = NR OF WORDS OF ALL BANKS, THE TOTAL NR OF (USED)
C     WORDS IN A RECORD IS THEREFORE NRECL = NTOT +1.
C
C        FIRST WORD IN RECORD   = NTOT
C        NEXT WORD              = NAME
C        NEXT WORD              = NUMBER OF FIRST BANK
C        NEXT WORD              = POINTER (NO MEANING IN RECORD)
C        NEXT WORD              = NR.OF WORDS OF THE FIRST BANK
C        ETC.
C
C
C
C
C     8.1 STANDARD OUTPUT AND INPUT
C
C
C     OUTPUT IS DONE BY FIRST SELECTING THE NAMES OF ALL BANKS
C     TO BE WRITTEN AND THEN BY CALLING THE OUTPUT PROGRAM. THE
C     SET OF BANKS DEFINES ONE EVENT. IF THE EVENT IS WRITTEN,
C     THE ORDER OF THE BANKS IS ALWAYS THE SAME AS WITHIN THE LIST,
C     WITH BANKS OF THE SAME NAME IN THE ORDER OF INCREASING NUMBER.
C     ALL BANKS OF ONE EVENT ARE READ INTO THE COMMON/BCS/ BY
C     ONE CALL OF THE INPUT PROGRAM.
C
C
C
C
C
C
C
C     OUTPUT OF ONE EVENT
C
C        CALL BSLW               OR  CALL BMLT(N,LIST OF NAMES)
C
C
C        CALL BWRITE(IUN)
C
C     AFTER THE LAST EVENT, A ZERO LIST OF NAMES HAS TO BE DEFINED
C     AND BWRITE HAS TO BE CALLED AGAIN.
C
C        CALL BMLT(0,DUMMY)
C        CALL BWRITE(IUN)
C
C
C
C     INPUT OF ONE EVENT
C
C        CALL BREAD(IUN,&1,&2)         CALL CREAD(IUN,IER)
C
C     SPECIAL CONDITIONS
C
C                      BREAD                    CREAD
C
C     READ ERROR       RETURN1 (&1)             IER=1
C     END-OF-DATA      RETURN2 (&2)             IER=2
C
C
C
C     8.2 OUTPUT MODES AND RECORD TYPES
C
C
C     THERE ARE TWO TYPES OF RECORDS AND THREE MODES OF OUTPUT.
C
C     TYPES OF RECORDS
C
C     S-RECORDS     ONE RECORD CONTAINS ONE EVENT
C
C     M-RECORDS     ONE RECORD MAY CONTAIN SEVERAL EVENTS OR PARTS
C                   OF EVENTS. WITHIN THE RECORD, EVENTS OR PARTS
C                   OF EVENTS ARE WITHIN BANKS WITH THE NAME 'HIDD'.
C
C     FOR BOTH RECORD TYPES, THE INPUT PROGRAM ALWAYS PUTS THE
C     BANKS OF ONE EVENT INTO COMMON/BCS/.
C
C     THE OUTPUT MODE AND A MAXIMUM RECORD LENGTH IS DEFINED BY ONE
C     CALL (BEFORE THE FIRST CALL OF THE OUTPUT PROGRAM) FOR THE
C     OUTPUT UNIT IUNIT.
C
C                  ----- ----- ----
C        CALL BWRO(IUNIT,NRECL,MODE)
C
C     IF NOT CALLED, MODE = 0 IS ASSUMED WITH NRECL TAKEN FROM THE
C     CALL TO THE BOS INITIALIZATION PROGRAM BINT (SEE CH. 1).
C
C
C
C
C     MODES OF OUTPUT
C
C     MODE = 0     S-RECORDS ARE WRITTEN. THE EVENT IS NOT WRITTEN, IF
C                  THE LENGTH OF THE EVENT EXCEEDS NRECL WORDS.
C
C     MODE = 1     S-RECORDS OR M-RECORDS ARE WRITTEN. M-RECORDS ARE
C                  WRITTEN, IF THE LENGTH OF ONE EVENT EXCEEDS NRECL
C                  WORDS.
C
C     MODE = 2     M-RECORDS ARE WRITTEN.
C
C     THE RECORD LENGTH WILL NEVER EXCEED NRECL WORDS. IT IS POSSIBLE
C     (AND DONE IN BWRITE), TO WRITE RECORDS OF FIXED LENGTH NRECL
C     (ADDING UNUSED WORDS, IF NTOT IS LESS THAN NRECL - 1)
C
C
C     8.3 USER WRITE AND READ STATEMENTS
C
C     THE USER CAN USE HIS OWN WRITE AND READ STATEMENTS, TO ALLOW
C     E.G. USING THE IBM-FORTRAN DIRECT ACCESS STATEMENTS.
C     FOR OUTPUT THE STATEMENT CALL BWRITE(IUN) HAS TO BE REPLACED
C     (ALSO FOR THE CALL AFTER THE LAST EVENT) BY THE FOLLOWING
C     STATEMENTS.
C
C        1  CALL BWRS(IUN,NREC,INIW)
C           IF(INIW.EQ.0) GOTO 2
C           WRITE ONE RECORD ON UNIT IUN OF TOTAL NREC WORDS
C           IW(INIW),IW(INIW+1), . . . IW(INIW+NREC-1)
C           GOTO 1
C        2  CONTINUE
C
C     REMARK. IW(INIW) CONTAINS NTOT. FOR MODE = 0 OR = 1, NREC
C     IS EQUAL TO NTOT+1, FOR MODE = 2 NREC IS EQUAL TO NRECL
C     (FIXED NUMBER OF WORDS).
C
C
C     FOR INPUT THE STATEMENT CALL BREAD(IUN,&1,&2) HAS TO BE
C     REPLACED BY THE FOLLOWING STATEMENTS.
C
C
C        1  CALL BRDS(IUN,NREC,INIR)
C           IF(INIR.EQ.0) GOTO 2
C           READ ONE RECORD FROM UNIT IUN INTO WORDS
C           IW(INIR),IW(INIR+1), . . .
C           (SEE REMARKS BELOW)
C           GOTO 1
C        2  CONTINUE
C
C     REMARKS. THE ARGUMENT NREC IS (FOR INIR NOT EQUAL 0) EQUAL
C     TO THE LARGEST ALLOWED NUMBER OF WORDS, WHICH CAN BE READ.
C     SAFE INPUT IS POSSIBLE USING A SUITABLE ASSEMBLER READ ROUTINE.
C     THE END-OF-DATA CONDITION HAS TO BE HANDLED BY THE USER. IN
C     CASE OF READ ERRORS THIS CONDITION CAN BE SIGNALLED TO THE
C     BRDS PROGRAM BY DEFINING IW(INIR) = 0 AND GOTO 1. OTHERWISE
C     IW(INIR) CONTAINS NTOT = NR OF WORDS OF THE RECORD FOLLOWING.
C
C     FOR THE USE IN SPECIAL USER-WRITTEN INPUT-OUTPUT PROGRAMS
C     OR OTHER APPLICATIONS, THERE ARE TWO CALLS, WHICH ASSEMBLE
C     BANKS BELONGING TO THE CURRENT LIST IN CONTIGUOUS BANKSPACE
C     (BOUTP) AND STORE BANKS FROM AN ARBITRARY ARRAY INTO THE
C     COMMON /BCS/ (BINP).
C
C     CALL BOUTP(NRW,INIW)
C                --- ----
C     ALL BANKS BELONGING TO THE CURRENT LIST ARE ARRANGED IN
C     CONTIGUOUS BANK SPACE, STARTING AT LOCATION IW(INIW) WITH
C     A TOTAL OF NRW WORDS (INIW = 0 IN CASE OF ERRORS).
C
C               --- --
C     CALL BINP(NRW,AR)
C
C     ALL BANKS STORED IN THE ARRAY AR(1) . . . AR(NRW) ARE STORED
C     IN THE COMMON /BCS/, IF THERE IS ENOUGH SPACE AND IF THE ARRAY AR
C     CONTAINS CORRECT BANKS.
C
C
C
C     8.4   BUFFER BANKS
C
C     FOR EACH INPUT/OUTPUT UNIT IUN A BANK ('+BUF',IUN) IS USED
C     WITH BETWEEN 11 AND 10 +NRECL WORDS DEPENDING ON RECORD TYPE.
C     THESES BANKS ALSO CONTAIN STATISTIC ON INPUT/OUTPUT,
C     WHICH IS PRINTED BY CALLING THE STATUS-PRINT ROUTINE BSTA.
C     AFTER THE END OF INPUT/OUTPUT THESE BANKS CAN BE DELETED BY THE
C     USUAL CALL
C        CALL BDLS('+BUF',IUN)
C     THIS IS NECESSARY, IF THE SAME UNIT NUMBER IUN IS USED AFTERWARDS.
C     THE CONTENT OF THE BUFFER BANKS IS DESCRIBED IN CH. 10.
C
C
C
C     8.5    STANDARD EVENT READING/WRITING
C
C     PROGRAMMING EXAMPLE OF STANDARD EVENT PROCESSING WITH REPEATED
C     EXECUTION OF
C
C             INPUT OF ONE EVENT
C             PROCESS EVENT
C             OUTPUT OF EVENT
C             DELETE BANKS AND GARBAGE COLLECTION.
C
C     INPUT IS ASSUMED FROM UNIT 1, OUTPUT TO UNIT 2 WITH OUTPUT
C     MODE 0 AND A LIMIT OF 5000 WORDS PER RECORD.
C
C
C           CALL BINT(10000,0,0,0)
C           CALL BWRO(2,5000,0)
C     C
C     C     EVENT LOOP
C     C
C         1 CALL BREAD(1,&1,&2)
C     C     PROCESS EVENT
C           .....
C           .....
C           .....
C           CALL BSLW
C           CALL BWRITE(2)
C           CALL BSLT
C           CALL BDLG
C           GOTO 1
C     C
C     C     END OF EVENT LOOP
C     C
C         2 CALL BMLT(0,DUMMY)
C           CALL BWRITE(2)
C           STOP
C           END
C
C
C
C
C     THERE IS A STANDARD PROGRAM BSEQ, WHICH INCLUDES THE STANDARD
C     BOS PROGRAMS FOR INPUT, OUTPUT AND THE DELETING OF BANKS, AS
C     SHOWN IN THE EXAMPLE ABOVE.
C
C
C     CALL BSEQ(MARK)
C               ----
C
C        WHERE MARK = 0   ONE EVENT READ
C                   = 1   END, NO EVENT READ
C
C
C     BESQ, WHICH IS USED IN A LOOP, READS, EACH TIME CALLED, ONE
C     EVENT FROM UNIT 1. BSEQ RETURNS WITH MARK =1 IN THE END-OF-DATA
C     CONDITION, OR NSEC = 2 SECONDS BEFORE TIME OVERFLOW (TIME IS
C     CHECKED USING THE PROGRAM JUHR). THIS LIMIT CAN BE CHANGED
C     BY (BEFORE THE LOOP)
C
C     CALL BSET(NSEC)
C
C
C     IT IS ALSO POSSIBLE, TO DELIMIT THE NR OF EVENTS TO BE READ
C     BY (BEFORE THE LOOP)
C
C     CALL BSEL(LIMIT)
C
C     BSEQ WILL RETURN WITH MARK = 1 AFTER LIMIT EVENTS.
C
C     OUTPUT IS POSSIBLE WITH BSEQ ONTO THREE DIFFERENT OUTPUT UNITS.
C     IF AN EVENT SHOULD BE WRITTEN ONTO UNIT IUN, THIS HAS TO
C     SIGNALLED BY
C
C     CALL BSEW(IUN)
C
C     IF THE EVENT SHOULD NOT BE WRITTEN ONTO UNIT IUN, THIS IS
C     SIGNALLED BY (WITH A NEGATIVE UNIT)
C
C     CALL BSEW(-IUN)
C
C     DEFAULT IS NO OUTPUT FOR ALL EVENTS. THE OUTPUT ROUTINES ARE
C     CALLED WITHIN BSEQ AT THE NEXT ENTRY, USING THE SPECIAL LIST
C     OF NAMES (BSLW FOR OUTPUT, BSLT FOR DELETING BANKS).
C     THE OUTPUT MODES HAVE TO BE DEFINED BEFORE THE LOOP.
C
C
C
C     EXAMPLE FOR A COMPLETE MAIN PROGRAM.
C     1000 EVENTS ARE TO BE READ FROM UNIT 1, OUTPUT IS TO
C     UNIT 2 FOR ALL EVENTS, AND, FOR CERTAIN EVENTS, ALSO TO
C     THE UNITS 3 AND 4.
C
C
C           CALL BINT(10000,0,0,)
C           CALL BSET(5)
C           CALL BSEL(1000)
C           CALL BWRO(2,5000,0)
C           CALL BWRO(3,2000,1)
C           CALL BWRO(4,2000,1)
C     C
C     C     EVENT LOOP
C     C
C         1 CALL BSEQ(MARK)
C           IF(MARK.EQ.1) GOTO 2
C     C     PROCESS EVENT
C           .....
C           CALL BSEW(2)
C           CALL BSEW(3)
C           .....
C           .....
C           IF(.....) CALL BSEW(-3)
C           IF(.....) CALL BSEW(4)
C           GOTO 1
C     C
C     C     END OF EVENT LOOP
C     C
C         2 CALL BSTA
C           STOP
C           END
C
C
C     THERE IS ALSO THE POSSIBILITY IN BSEQ, TO READ WITH AN
C     ASSEMBLER PROGRAM (VBS RECORDS). IF THIS IS WANTED, ONE
C     HAS TO CALL
C
C     CALL ASVBS(IU)
C
C     BEFORE THE FIRST CALL OF BSEQ , TO DEFINE THE INPUT UNIT
C     NUMBER IU (DDNAME FTIUF001).
C
C
C
C
      RETURN
      END
