C   07/06/96 606071851  MEMBER NAME  ILOC     (S4)          FORTG1
      FUNCTION   ILOC(NA,NB,NC)
C     BOS SUBPROGRAM =0.2=
#include "acs.for"
      COMMON/BCS/IW(1)
      EQUIVALENCE (XNAME,INAME)
      REAL FF/Z000000FF/
      INTEGER ISTAR/Z0000005C/
      REAL AND
      EXTERNAL AND
C
C
      IF(NA.EQ.0) GOTO 70
    1 IF(NC+4.EQ.0) GOTO 60
    2 IW(INAMV)=NA
      LFDI=MOD(IABS(NAMEV),NPRIM)+NAMAX1
    4 LFDI=IW(LFDI+IPLST)
      IF(IW(LFDI+INAMV).NE.IW(INAMV)) GOTO 4
      IF(LFDI.EQ.0) LFDI=IBLN(IW(INAMV))
      LFDK=LFDI+1
      LFDI=IW(LFDI)
    6 IF(LFDI.EQ.0)     GOTO 30
      IF(IW(LFDI-2)-NB) 8,10,30
    8 LFDK=LFDI
      LFDI=IW(LFDI-1)
      GOTO 6
C
C     BANK FOUND --------------
   10 ILOC=LFDI
      IF(NC) 12,100,20
   12 IF(NC+3.EQ.0) GOTO 40
      IF(NC+4.EQ.0) GOTO 90
C     DELETE BANK
      NN=4+IW(LFDI)
      IW(LFDI  )=-NN
      IW(LFDK-1)=IW(LFDI-1)
      INAME=NA
      XNAME=AND(XNAME,FF)
      IF(INAME.EQ.ISTAR) NCPL=NCPL-NN
      IF(LFDI+NN-3.NE.NEXT) GOTO 14
      NEXT=NEXT-NN
      GOTO 16
   14 NFRE=NFRE+NN
      ILOW=MIN0(ILOW,ILOC)
   16 IF(NC+2.NE.0) GOTO 100
C     RESTRICTED GARBAGE COLLECTION
      JLOW=ILOW
      II=LFDI
      ILOW=II
      CALL BGAR(IGA)
      ILOC=0
      IF(JLOW.LT.II) ILOW=JLOW
      GOTO 100
C     CHANGE LENGTH, IF DIFFERENT
   20 NW=NC-IW(LFDI)
      IF(NW.EQ.0) GOTO 100
      IF(LFDI+IW(LFDI)+1.EQ.NEXT) GOTO 50
      IF(NW) 22,100,40
   22 IF(NW+4.GT.0) GOTO 40
      IW(LFDI)=NC
      KND=LFDI+NC+4
      ILOW=MIN0(ILOW,KND)
      IW(KND)=NW
      NFRE=NFRE-NW
      GOTO 56
C
C     BANK NOT FOUND ----------
   30 LFDI=0
      IF(NC+4.EQ.0) GOTO 62
      IF(NC.LE.0) GOTO 90
      INAME=NA
      XNAME=AND(XNAME,FF)
C     CREATE BANK
      NN=4+NC
      IF(NEXT+NN.GE.NLST) GOTO 80
   32 IF(INAME.NE.ISTAR) GOTO 36
      IF(NCPL+NN.LT.NSPL) GOTO 34
      NHISTL(11)=NHISTL(11)+1
      GOTO 90
   34 NCPL=NCPL+NN
   36 ILOC=NEXT+3
      ISV =IW(LFDK-1)
      IW(LFDK-1)=ILOC
      IW(ILOC-3)=NA
      IW(ILOC-2)=NB
      IW(ILOC-1)=ISV
      IW(ILOC  )=NC
      NEXT=NEXT+NN
      LIND=ILOC
      CALL VZERO(IW(ILOC+1),NN)
      GOTO 100
C     MOVE BANK
   40 IF(NEXT+4+MAX0(IW(LFDI),NC).GE.NLST) GOTO 80
      NN=4+IW(LFDI)
      CALL UCOPY2(IW(LFDI-3),IW(NEXT),NN)
      ILOW=MIN0(ILOW,LFDI)
      ILOC=NEXT+3
      IW(LFDI  )=-NN
      IW(LFDK-1)=ILOC
      NEXT=NEXT+NN
      NFRE=NFRE+NN
      IF(NC+3.EQ.0) GOTO 100
C     CHANGE LAST BANK
   50 IF(INAME.NE.ISTAR) GOTO 54
      IF(NCPL+NW.LT.NSPL) GOTO 52
      NHISTL(11)=NHISTL(11)+1
      GOTO 90
   52 NCPL=NCPL+NW
   54 IW(ILOC)=IW(ILOC)+NW
      NEXT=NEXT+NW
      IF(NW.GT.0) CALL VZERO(IW(ILOC+NN-3),NW)
   56 IF(INAME.EQ.ISTAR) NCPL=NCPL+NW
      GOTO 100
C
C     RENAME
   60 KK=LFDK
      II=LFDI
      NL=0
      INAME=IW(II-3)
      XNAME=AND(XNAME,FF)
      IF(INAME.EQ.ISTAR) NL=-IW(II)-4
      GOTO 2
   62 IW(KK-1)=IW(LFDI-1)
      IW(II-1)=IW(LFDK-1)
      IW(LFDK-1)=II
      IW(II-3)=NA
      IW(II-2)=NB
      ILOC=II
      INAME=NA
      XNAME=AND(XNAME,FF)
      IF(INAME.EQ.ISTAR) NL=NL+IW(II)+4
      NCPL=NCPL+NL
      GOTO 100
C
C     LOCATE BUFFER SPACE
   70 IF(NB.NE.0.OR.NC.NE.0) GOTO 1
      ILOC=NEXT
      IW(ILOC)=NLST-NEXT-4
      GOTO 100
C
C
   80 NHISTH(11)=NHISTH(11)+1
   90 ILOC=0
  100 RETURN
      END
