| Application Programmer's I/O Guide - S-3695-35 | ||
|---|---|---|
| Prev Section | Chapter 3. Fortran I/O Extensions | Next Section |
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.
WOPEN(3F) opens a file and specifies it as a word-addressable random-access file. WOPEN must be called before any other WA routines are called because it creates the I/O buffer for the specified file by using blocks. By using WOPEN, you can combine synchronous and asynchronous I/O to a given file while the file is opened. The following is an example of a call to WOPEN:
CALL WOPEN(30,iblks,istat,err) |
GETWA(3F) synchronously reads data from a buffered word-addressable random-access file. SEEK(3F) is used with GETWA to provide more efficient I/O; the SEEK routine performs an asynchronous pre-fetch of data into a buffer. The following is an example of a call to GETWA:
CALL GETWA(30,iloc,iadr,icnt,ierr) |
SEEK asynchronously reads data from the word-addressable file into a buffer. A subsequent GETWA call will deliver the data from the buffer to the user data area. This provides a way for the user to do asynchronous read-ahead. The following is an example of a call to SEEK:
CALL SEEK(30,iloc,iadr,icnt,ierr) |
PUTWA(3F) synchronously writes from memory to a word-addressable random-access file. The following is an example of a call to PUTWA:
CALL PUTWA(30,iloc,iadr,icnt,ierr) |
APUTWA(3F) asynchronously writes from memory to a word-addressable random-access file. The following is an example of a call to APUTWA:
CALL APUTWA(30,iloc,iadr,icnt,ierr) |
WCLOSE(3F) finalizes changes and additions to a WA file and closes it. The following is an example of a call to WCLOSE:
CALL WCLOSE(30,ierr) |
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 |
| Prev Section | Table of Contents | Title Page | Next Section |
| Random access I/O routines | Up one level | Asynchronous queued I/O (AQIO) routines |