| Application Programmer's I/O Guide - S-3695-35 | ||
|---|---|---|
| Prev Section | Chapter 3. Fortran I/O Extensions | Next Section |
The record-addressable random-access file I/O routines let you generate variable length, individually addressable records. The I/O library updates indexes and pointers.
Each record in a random-access file has a 1-word (64-bit) key or number indicating its position in an index table of records for the file. This index table contains a pointer to the location of the record on the device and can also contain a name of each record within the file.
Alphanumeric record keys increase CPU time compared to sequential integer record keys because the I/O routines must perform a sequential lookup in the index array for each alphanumeric key. Each record should be named a numeric value n; n is the integer that corresponds to the n th record created on the file.
The following two sets of record-addressable random-access file I/O routines are available:
The Mass Storage (MS) package provides routines that perform buffered, record-addressable file I/O with variable-length records. It contains the OPENMS, READMS, WRITMS, CLOSMS, WAITMS, FINDMS, SYNCMS, ASYNCMS, CHECKMS, and STINDX routines.
The Direct Random (DR) package provides routines that perform unbuffered, record-addressable file I/O. It contains the OPENDR, READDR, WRITDR, CLOSDR, WAITDR, SYNCDR, ASYNCDR, CHECKDR, and STINDR routines. The amount of data transferred for a record is rounded up to a multiple of 512 words, because I/O performance is improved for many disk devices.
Both synchronous and asynchronous MS and DR I/O can be performed on a random-access file. You can use these routines in the same program, but they must not be used on the same file simultaneously. The MS and DR packages cannot be used for tape files.
If a program uses asynchronous I/O, it must ensure that the data movement is completed before trying to access the data. Because asynchronous I/O has a larger overhead in CPU time than synchronous I/O, only very large data transfers should be done with asynchronous I/O. To increase program speed, 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.
The MS library routines are used to perform buffered record-addressable random-access I/O. The DR library routines are used to perform unbuffered record-addressable random-access I/O.
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 describes these two packages in more detail. For details about the routines discussed in this section, see the individual man pages for each routine.
OPENMS(3F) and OPENDR(3F) open a file and specify the file as a random-access file that can be accessed by record-addressable random-access I/O routines.
These routines must be used to open a file before the file can be accessed by other MS or DR package routines. OPENMS sets up an I/O buffer for the random-access file. These routines read the index array for the file into the array provided as an argument to the routine. CLOSMS or CLOSDR must close any files opened by the OPENMS or OPENDR routine. The following are examples of these two routines:
CALL OPENMS(80,intarr,len,it,ierr) CALL OPENDR(20,inderr,len,itflg,ierr) |
READMS(3F) performs a read of a record into memory from a random-access file. READDR reads a record from a random-access file into memory.
If READDR is used in asynchronous mode and the record size is not a multiple of 512 words, user data can be overwritten and not restored. You can use SYNCDR to switch to a synchronous read; the data is copied and restored after the read has completed. The following are examples of these routines:
CALL READMS(80,ibuf,nwrd,irec,ierr) CALL READDR(20,iloc,nwrd,irec,ierr) |
WRITMS(3F) writes to a random-access file on disk from memory. WRITDR writes data from user memory to a record in a random-access file on disk. Both routines update the current index. The following are examples of these routines:
CALL WRITMS(20,ibuf,nwrd,irec,irflg,isflag,ierr) CALL WRITDR(20,ibuf,nwrd,irec,irflag,isflg,ierr) |
The CLOSMS and CLOSDR routines write the master index specified in the call to OPENMS or OPENDR from the array provided in the user program to the random-access file and then close the file. These routines also write statistics about the file to the stderr file. The following are examples of these routines:
CALL CLOSMS(20,ierr) CALL CLOSDR(20,ierr) |
ASYNCMS(3F) and ASYNCDR set the I/O mode for the random-access routines to asynchronous. I/O operations can be initiated and subsequently proceed simultaneously with the actual data transfer. If the program uses READMS, precede asynchronous reads with calls to FINDMS. The following are examples of these routines:
CALL ASYNCMS(20,ierr) CALL ASYNCDR(20,ierr) |
CHECKMS(3F) and CHECKDR check the status of the asynchronous random-access I/O operation. The following are examples of these routines:
CALL CHECKMS(20,istat,ierr) CALL CHECKDR(20,istat,ierr) |
WAITMS(3F) and WAITDR wait for the completion of an asynchronous I/O operation. They return a status flag indicating if the I/O on the specified file completed without error. The following are examples of these routines:
CALL WAITMS(20,istat,ierr) CALL WAITDR(20,istat,ierr) |
SYNCMS(3F) and SYNCDR set the I/O mode for the random-access routines to synchronous. All future I/O operations wait for completion. The following are examples of these routines:
CALL SYNCMS(20,ierr) CALL SYNCDR(20,ierr) |
STINDX(3F) and STINDR allow an index to be used as the current index by creating a subindex. These routines reduce the amount of memory needed by a file that contains a large number of records. They also maintain a file containing records logically related to each other. Records in the file, rather than records in the master index area, hold secondary pointers to records in the file.
These routines allow more than one index to manipulate the file. Generally, STINDX or STINDR toggle the index between the master index maintained by OPENMS/OPENDR and CLOSMS/CLOSDR and the subindex supplied by the Fortran program. The following are examples of these routines:
CALL STINDX(20,inderr,len,itflg,ierr) CALL STINDR(20,inderr,len,itflg,ierr) |
FINDMS(3F) asynchronously reads the desired record into the data buffers for the specified file. The next READMS or WRITMS call waits for the read to complete and transfers data appropriately. An example of a call to FINDMS follows:
CALL FINDMS(20,inwrd,irec,ierr) |
The following program example uses the MS package:
Example 3-1. MS package use
program msio
dimension r(512)
dimension idx(512)
data r/512*2.0/
irflag=0
call openms(1,idx,100,0,ier)
do 100 i=1,100
call writms(1,r,512,i,irflag,0,ier)
if(ier.ne.0)then
print *,"error on writms=",ier
goto 300
end if
100 continue
do 200 i=1,100
call readms(1,r,512,i,irflag,0,ier)
if(ier.ne.0)then
print *,"error on readms=",ier
goto 300
end if
200 continue
300 continue
call closms(1,ier)
end |
The following program uses the DR package:
Example 3-2. DR package use
program daio
dimension r(512)
dimension idx(512)
data r/512*2.0/
irflag=0
ierrs=0
call assign('assign -R',ier1)
call asnunit(1,'-F mr.save.ovf1:10:200:20',ier2)
if(ier1.ne.0.or.ier2.ne.0)then
print *,"assign error=",ier1,ier2
ierrs=ierrs+1
end if
call opendr(1,idx,100,0,ier)
if(ier.ne.0)then
print *,"error on opendr=",ier
ierrs=ierrs+1
end if
do 100 i=1,100
call writdr(1,r,512,i,irflag,0,ier)
if(ier.ne.0)then
print *,"error on writdr=",ier
ierrs=ierrs+1
end if
100 continue
do 200 i=1,100
call readdr(1,r,512,i,irflag,0,ier)
if(ier.ne.0)then
print *,"error on readdr=",ier
ierrs=ierrs+1
end if
200 continue
300 call closdr(1,ier)
if(ier.ne.0)then
print *,"error on readdr=",ier
ierrs=ierrs+1
end if
400 continue
if(ierrs.eq.0)then
print *,"daio passed"
else
print *,"daio failed"
end if
end |
| Prev Section | Table of Contents | Title Page | Next Section |
| Fortran I/O Extensions | Up one level | Word-addressable I/O routines |