3.3. Word-addressable I/O routines

A word-addressable (WA) random-access file consists of an adjustable number of contiguous words. The WA package performs unformatted buffered I/O; the WA routines perform efficiently when the I/O buffers are set to a size large enough to hold several records that are frequently read and/or written. When a WA read operation is executed, the I/O buffers are searched to see if the data that will be read is already in the buffers. If the data is found in the I/O buffers, I/O speedup is achieved because a system call is not needed to retrieve the data.

A program using the package may access a word or a contiguous sequence of words from a WA random-access file. The WA package cannot be used for tape files.

Although the WA I/O routines provide greater control over I/O operations than the record-addressable routines, they require that the user track information that the system would usually maintain when other forms of I/O are used. The program must keep track of the word position of each record in a file that it will read or write with WA I/O. This is easiest to do with fixed-length records; with variable-length records, the program must store record lengths for the file where they can be retrieved when the file is accessed. When variable-length records are used, the program should use record-addressable I/O.

The WA package allows both synchronous and asynchronous I/O. To speed up the program, the program must be able to do a significant amount of CPU-intensive work or other I/O while the asynchronous I/O is executing.

These library routines are not internally locked to ensure single-threading; a program must lock each call to the routine if the routine is called from more than one task.

The following list briefly describes the routines in this package; for details about the routines discussed in this section, see the individual man pages for each routine.

The following is an example of a program which uses the WA I/O routines:


Example 3-3. WA package use

        program waio
        dimension r(512), r1(512)
        iblks=10             !use a 10 block buffer
        istats=1             !print out I/O Stats

        call wopen(1,iblks,0,ier)
        if(ier.ne.0)then
          print *,"error on wopen=",ier
          goto 300
        end if

        iaddr=1
        do 100 k=1,100

          do 10 j=1,512
10        r(j)=j+k
          call putwa(1,r,iaddr,512,ier)
          if(ier.ne.0)then
             print *,"error on putwa=",ier," rec=",k
             goto 300
          end if
          iaddr=iaddr+512
100     continue

        iaddr=1
        do 200 k=1,100
          call getwa(1,r1,iaddr,512,ier)
          if(ier.ne.0)then
             print *, "error on getwa=",ier," rec=",k
             goto 300
          end if
          iaddr=iaddr+512
200     continue
300     continue
        call wclose(1)
        end