FIO/RIO can be used in three main ways; you can use it in a minimalist way to ease the writing of normal FORTRAN programs, you can use the extra functionality provided by FIO file descriptors in stand alone FORTRAN programs, or you can use the ADAM parameter system interface in ADAM programs.
Some of the FIO/RIO routines do not use FIO file descriptors and are provided to simplify common I/O operations. For example, FIO_GUNIT will get an unused FORTRAN unit number. Using this routine is better than ‘hard wiring’ unit numbers into code as you may not know what unit numbers other subroutines are using. The routines that do not use the FIO file descriptors are:
Here is an example of the use of some of these routines.
Consistent use of the FIO_GUNIT and FIO_PUNIT routines has reduced the likelihood of a clash of unit number between this part of the program and some other part, and the use of FIO_REP allows machine independent reporting of any errors.
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:
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.
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.
The last way of using FIO/RIO is in its fully integrated ADAM form. The following routines provide an interface to the ADAM parameter system:
These routines are typically used to get the name of a file through the ADAM parameter system. For instance, the previous example could be re-written as:
When the call to FIO_ASSOC is executed, the name of the file will be obtained via the parameter system. This may involve prompting the user, but the file name could equally well be defaulted from the interface file. The interface file might contain something like this:
N.B. At present, if you specify a file name that contains a directory name in an interface file, then you must use the appropriate (Unix or VMS) syntax. In the future, FIO may be enhanced to handle environment variables and logical names as part of the file specification.