For details about the routines discussed in this chapter, see the individual
man pages for each routine. In addition, see the reference manuals for your
compiler system.
BUFFER IN/BUFFER OUT Routines
BUFFER IN and BUFFER OUT statements
initiate a data transfer between the specified file or unit at the current
record and the specified area of program memory. To allow maximum asynchronous
performance, all BUFFER IN and BUFFER OUT
operations should begin and end on a sector boundary.
The BUFFER IN and BUFFER OUT statements
can perform sequential asynchronous unformatted I/O if the files are assigned
as unbuffered files. You must declare the BUFFER IN and
BUFFER OUT files as unbuffered by using one of the following assign(1) commands.
assign -s u ...
assign -F system ... |
If the files are not declared as unbuffered, the BUFFER IN
and BUFFER OUT statements may execute synchronously.
For tapes, BUFFER IN and BUFFER OUT
operate synchronously; when you execute a BUFFER statement,
the data is placed in the buffer before you execute the next statement in
the program. Therefore, for tapes, BUFFER IN has no advantage
over a read statement or a CALL READ
statement; however, the library code is doing asynchronous read-aheads to
fill its own buffer.
The F77 format is the default file structure.
The
BUFFER IN and BUFFER OUT statements decrease
the overhead associated with transferring data through library and system
buffers. These statements also offer the advantages of asynchronous I/O. I/O
operations for several files can execute concurrently and can also execute
concurrently with CPU instructions. This can decrease overall wall-clock time.
In order for this to occur, the program must ensure that the requested
asynchronous data movement was completed before accessing the data. The program
must also be able to do a significant amount of CPU-intensive work or other
I/O during asynchronous I/O to increase the program speed.
Buffer I/O processing waits until any previous buffer I/O operation
on the file completes before beginning another buffer I/O operation.
Use the UNIT(3f) and
LENGTH(3f) functions with BUFFER IN and
BUFFER OUT statements to delay further program execution until the
buffer I/O statement completes.
For details about the routines discussed in this section, see the individual
man pages for each routine.
The UNIT
intrinsic routine waits for the completion of the BUFFER IN
or BUFFER OUT statement. A program that uses asynchronous
BUFFER IN and BUFFER OUT must ensure that the
data movement completes before trying to access the data. The UNIT
routine can be called when the program wants to delay further program
execution until the data transfer is complete. When the buffer I/O operation
is complete, UNIT returns a status indicating the outcome
of the buffer I/O operation.
The following is an example of the
UNIT routine:
The
LENGTH intrinsic routine returns the length of transfer for a
BUFFER IN or a BUFFER OUT statement. If the
LENGTH routine is called during a BUFFER IN or
BUFFER OUT operation, the execution sequence is delayed until the
transfer is complete. LENGTH then returns the number of
words successfully transferred. A 0 is returned for an end-of-file (EOF).
The following is an example of the
LENGTH routine: