next up previous 204
Next: The environment level routines
Up: Using FIO/RIO
Previous: Routines to enhance simple FORTRAN I/O

The stand-alone subroutines

In addition to the routines in the previous section, FIO provides a set of routines to do some simple I/O on files. FIO maintains a set of file descriptors for active files which are used by these routines. These descriptors contain such things as the access mode of a file (read only, update, etc.), which allow FIO to trap some errors rather than permitting a run time error to occur. For example, if an attempt is made to write to a file that has been opened with `read only' access, FIO will report the error, but the program will not crash, allowing the user to take corrective action. Use of these routines also makes user written code more portable. Issues such as requiring CARRIAGECONTROL='LIST' in DEC FORTRAN OPEN statements are handled internally. The routines that handle FIO file descriptors are:

FIO_CLOSE
Close a file.
FIO_FNAME
Get the name of a file.
FIO_OPEN
Open a file.
FIO_READ
Read a file.
FIO_READF
Read a file (faster than FIO_READ).
FIO_RWIND
Rewind a file.
FIO_UNIT
Get the unit number of a file.
FIO_WRITE
Write a file.
RIO_CLOSE
Close a file.
RIO_OPEN
Open a file.
RIO_READ
Read a file.
RIO_WRITE
Write a file.

Note that the same file descriptors are used by the FIO and RIO routines, so these can be freely mixed, where appropriate.

Here is an example of the use of some of these routines.

      ...
*  Open a file.
      CALL FIO_OPEN( FILNAM, 'WRITE', 'LIST', 0, FD, STATUS )
*  Write the data.
         DO I = 1, N
            CALL FIO_WRITE( FD, BUF( I ), STATUS )
         END DO
*  Close the file.
      CALL FIO_CLOSE( FD, STATUS )
      ...

Note that there is no testing for errors in this piece of code since the FIO routines follow the normal Starlink convention for error handling and will not execute if STATUS is bad. However, if the loop is to be executed many times, it would be worth testing that the call to FIO_OPEN was successful, otherwise you could end up executing the loop many times to no effect.


next up previous 204
Next: The environment level routines
Up: Using FIO/RIO
Previous: Routines to enhance simple FORTRAN I/O

FIO/RIO FORTRAN file I/O routines
Starlink User Note 143
P M Allan
A J Chipperfield
20 July 2001
E-mail:starlink@jiscmail.ac.uk

Copyright © 2000 Council for the Central Laboratory of the Research Councils