C---------------------------------------------------------------------- subroutine ftldrc(iunit,nrec,igneof,status) C low-level routine to load a specified record from a file into C a physical buffer, if it is not already loaded. Reset all C pointers to make this the new current record for that file. C Update ages of all the physical buffers. C iunit i fortran unit number C nrec i direct access file record number to be loaded C igneof l ignore end of file error (107)? C status i output error status integer iunit,nrec,status logical igneof C COMMON BLOCK DEFINITIONS:-------------------------------------------- integer nb,ne,pb parameter (nb = 20) parameter (ne = 512) parameter (pb = 20) integer bufnum,chdu,hdutyp,maxhdu,hdstrt,hdend,nxthdr,dtstrt integer nxtfld logical wrmode common/ft0001/bufnum(199),chdu(nb),hdutyp(nb),maxhdu(nb), & wrmode(nb),hdstrt(nb,ne),hdend(nb),nxthdr(nb),dtstrt(nb),nxtfld 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) integer compid common/ftcpid/compid C END OF COMMON BLOCK DEFINITIONS----------------------------------- integer i,lbuff,pbuff,ounit,olen,orec,a1,tstat if (status .gt. 0)return lbuff=bufnum(iunit) C check if record is already loaded in one of the physical buffers do 10 i=1,maxbuf if (logbuf(i) .eq. lbuff .and. recnum(i) .eq. nrec)then C found the desired record; don't have to read it pbuff=i go to 20 end if 10 continue C the record is not already loaded, so we have to read it from disk. C First, decide which physical buffer into which to read it. call ftwhbf(lbuff,pbuff) if (modify(pbuff))then C old buffer has been modified, so we have to flush it to disk ounit=buflun(logbuf(pbuff)) olen=reclen(logbuf(pbuff)) orec=recnum(pbuff) call ftwrit(ounit,orec,olen,pbuff,status) modify(pbuff)=.false. end if C now read the record into the physical buffer olen=reclen(lbuff) tstat=0 call ftread(iunit,nrec,olen,pbuff,tstat) if (.not. igneof .and. tstat .eq. 107)then C return if hit EOF and told not to ignore it status=107 return else if (tstat .eq. 107)then C apparently hit end of file if (.not. wrmode(lbuff))then C just return if we don't have write access to the file return else C fill the new buffer with the desired value if (hdutyp(lbuff) .eq. 1)then C ASCII table: fill buffer with blanks call ftflbl(pbuff) else if (compid .ge. -1)then C initialize buffer = 0 (except on Cray machines) call ftflzr(pbuff) else C call special routine for Cray machines, since words C are twice as long (integers are 8-bytes long) call ftzrcr(pbuff) end if C mark the new record as having been modified modify(pbuff)=.true. end if end if C define log. buffer and the record number contained in the phys. buffer logbuf(pbuff)=lbuff recnum(pbuff)=nrec 20 continue C this is now the current buffer for this logical buffer currnt(lbuff)=pbuff bytnum(lbuff)=0 C find the current position of the buffer in the age index do 30 i=1,maxbuf if (pindex(i) .eq. pbuff)then a1=i go to 35 end if 30 continue 35 continue C rebuild the indices giving the chronological ordering of the buffers do 40 i=a1,maxbuf-1 pindex(i)=pindex(i+1) 40 continue C this buffer is now the youngest (= last in the index) pindex(maxbuf)=pbuff end