C---------------------------------------------------------------------- subroutine ftwhbf(ilbuff,pbuff) C decide which physical buffer to use to load in a new record C ilbuff i the logical buffer number of the record to be loaded (input) C pbuff i the physical buffer that should be used (output) integer ilbuff,pbuff C COMMON BLOCK DEFINITIONS:-------------------------------------------- integer nb,pb parameter (nb = 20) parameter (pb = 20) integer buflun,currnt,reclen,bytnum,maxrec common/ftlbuf/buflun(nb),currnt(nb),reclen(nb), & bytnum(nb),maxrec(nb) integer maxbuf,logbuf,recnum,pindex logical modify common/ftpbuf/maxbuf,logbuf(pb),recnum(pb),modify(pb), & pindex(pb) C END OF COMMON BLOCK DEFINITIONS----------------------------------- integer i,num,lbuff C search from the oldest to the youngest for an unlocked record do 10 i=1,maxbuf C num is the number of the next oldest buffer num=pindex(i) C lbuff is the logical buffer associated with this physical buffer lbuff=logbuf(num) C is the physical buffer a current buffer (i.e., locked)? if (lbuff .eq. 0 .or. currnt(lbuff) .ne. num)then pbuff=num return end if 10 continue C all the buffers are locked, so we have to reuse the current one pbuff=currnt(ilbuff) end