C   21/12/82 606071922  MEMBER NAME  BCFILE   (S)           FORTRAN
      SUBROUTINE BCFILE(LUN,NRECA,NBLOCK,IPASS,IOPT)
      COMMON/ACS/DUMMI(90),NUNTB
      COMMON/BCS/IW(1)
      COMMON/CCS/IUND,INDT,INDC,NPTR,INDA,LISTE(5),IPAS,NDAREC
C
C     IUND   =   UNIT
C     INDT   =   INDEX OF DIRECTOTY ENTRY
C     INDC   =   INDEX OF BANK TO BE COPIED
C     NPTR   =   RECORD NR WITH DATA
C     INDA   =   INDEX OF MASTER DIRECTORY BANK
C     LISTE  =   NAME, NR, DATA RECORD NR, NR OF WORDS
C     IPAS   =   PASSWORD
C     NDAREC =   NR OF WORDS/RECORD
C
      REAL*8 DATE(2)
      INTEGER IOPNEW/3HNEW/,IOPOLD/3HOLD/,IOP0LD/3H0LD/,DIRA/4H+DIR/
C
C     FORMAT AND CONTENT OF MASTER DIRECTORY RECORD (RECORD NR 1)
C
C     INDEX      CONTENT
C     ---------- ----------------
C         1      = 49
C         2      = 'DIRA'
C         3      = 0
C         4      = 0
C         5      = 45
C         6      TOTAL NR OF RECORDS
C         7      NR OF USED RECORD
C         8      NPRIME FOR HASH FUNCTION
C         9      = 0 OR NAME OF ADDED/CHANGED BANK
C        10      = 0 OR NR OF ADDED/CHANGED BANK
C        11      NR OF WORDS/RECORD
C        12      = 0 OR (DAY) TIME OF UPDATE IN 1/100 SEC
C        13
C        14
C        15
C        16
C        17
C        18
C        19      (PASSWORD)
C        20      = 0 CHANGES ALLOWED, = 1 CHANGES NOT ALLOWED
C     21-24      DATE/TIME OF LAST LOAD
C     25-28      DATE/TIME OF LAST UPDATE
C     29-32      DATE/TIME OF LAST UNLOAD
C        33      NR OF BANKS AT LAST LOAD
C        34      NR OF BANKS AT LAST UPDATE
C        35      NR OF BANKS AT LAST UNLOAD
C         .
C        50
C     ---------- ----------------
C        51      PRINTOUT COUNTER
C        52
C
C
C
C     FORMAT AND CONTENT OF DIRECTORY RECORDS (RECORD NRS 2, 3 ...)
C
C     INDEX      CONTENT
C     ---------- ----------------
C         1      = 4 + 3*NE        FOR NE ENTRIES
C         2      = 'DIRA'
C         3      = 0
C         4      = 0
C     ---------- ----------------
C         5      NAME
C         6      NR
C         7      NR OF DATA RECORD
C         8      NR OF WORDS
C         9      NAME ETC
C        10
C        11
C        12
C        13
C        14
C        15
C
      NREC=NRECA
      IOP=0
      IF(IOPT.EQ.IOPNEW) IOP=1
      IF(IOPT.EQ.IOPOLD) IOP=2
      IF(IOPT.EQ.IOP0LD) IOP=2
      CALL DAY(DATE(1),DATE(2))
      IF(NUNTB.NE.0) WRITE(NUNTB,101) LUN,NREC,NBLOCK,IPASS,IOPT
      IF(IOP.EQ.0) GOTO 201
      IUND=LUN
      IPAS=IPASS
      IF(IOP.EQ.1) GOTO  10
C
C     OLD DATA SET / CHECK NR OF RECORDS AND NR OF WORDS/RECORD
C
      CALL DIDA(0,LISTE,1)
C
C     'OLD BOS' DATA SET IS INDICATED BY NREC=-1610
C
      IF(NREC+1610.EQ.0) NREC=IW(INDA+6)
      IF(NUNTB.NE.0) WRITE(NUNTB,101) LUN,NREC,NBLOCK,IPASS,IOPT
      IF(IW(INDA+6).NE.NREC)    GOTO 203
      IF(IW(INDA+11).NE.NBLOCK) GOTO 203
      IF(IW(INDA+20).NE.0)      GOTO 203
      IW(INDA+34)=0
      GOTO 12
C
C     DETERMINE PRIME NUMBER FOR HASH SEARCH ALGORITHM
C
   10 IF(NUNTB.NE.0) WRITE(NUNTB,101) LUN,NREC,NBLOCK,IPASS,IOPT
      INDA=IBANK(4H+DIR,IUND,2HDL)
      INDA=IBANK(4H+DIR,IUND,52)
      IF(INDA.EQ.0) GOTO 204
   12 NPRIME=NREC/20
      IF(NPRIME.LE.5) NPRIME=5
      NPRIME=(NPRIME/2)*2+1
      NPRIME=NPRIME-2
   14 NPRIME=NPRIME+2
      A=NPRIME
      J=SQRT(A)
      DO 16 K=3,J,2
      NDIV=NPRIME/K
      IF(NDIV*K.EQ.NPRIME) GOTO 14
   16 CONTINUE
C
C     INITIAL DEFINITION OF THE FIRST RECORD
C
      IW(INDA+1)=4
      IW(INDA+2)=DIRA
      IW(INDA+3)=0
      IW(INDA+4)=0
      IW(INDA+5)=0
      IW(INDA+6)=NREC
      IW(INDA+7)=NPRIME+2
      IW(INDA+8)=NPRIME
      IW(INDA+9)=0
      IW(INDA+10)=0
      IW(INDA+11)=NBLOCK
      IW(INDA+19)=IPASS
      CALL DAY(DATE(1),DATE(2))
      CALL UCOPY(DATE,IW(INDA+21),4)
      IF(IOP.EQ.1) CALL UCOPY(DATE,IW(INDA+25),4)
      IF(IOP.EQ.1) CALL UCOPY(DATE,IW(INDA+29),4)
C
C     WRITE EMPTY DIRECTORY RECORDS
C
      DO 18 K=1,NPRIME
      IW(INDA+3)=K+1
   18 CALL WRDA(K+1,IW(INDA+1),IW(INDA+2))
C
C     WRITE EMPTY NEXT RECORD
C
      IW(INDA+1)=0
      CALL WRDA(NPRIME+2,IW(INDA+1),IW(INDA+2))
C
C     DEFINE AND WRITE MASTER DIRECTORY RECORD
C
      IW(INDA+1)=49
      IW(INDA+3)=0
      IW(INDA+5)=45
      CALL WRDA(1,IW(INDA+1),IW(INDA+2))
C
C     MAKE PRINTOUT AND DELETE MASTER DIRECTORY BANK
C
      INDA=IBANK(4H+DIR,IUND,2HDL)
      IPAS=IPASS
      CALL DIDA(0,LISTE,1)
      CALL BGAR(IGA)
C
C
C
  100 RETURN
  101 FORMAT('0---- DIR-UNIT',I3,9X,'INITIALIZE/CLEAR',I8,' RECORDS *',
     1   I5,' WORDS, PASSWORD = ',A4,'   OPTION = ',A4,4X,'(BCFILE)')
C
C     ILLEGAL ARGUMENT IN BCFILE
C
  201 CALL BDMPA(201)
C
C     DIFFERENCE IN DATA SET
C
  203 CALL BDMPA(203)
C
C     INSUFFICIENT SPACE FOR DIRECTORY BANK
C
  204 CALL BDMPA(204)
      GOTO 100
      END
