Sun Studio 12: Fortran User's Guide

4.7 Additional I/O Extensions

The section describes extensions to Fortran 95 Input/Output handling that are accepted by the f95 compiler that are not part of the Fortran 2003 draft standard. Some are I/O extensions that appeared in the Fortran 77 compiler, f77, and are now part of the Fortran 95 compiler.

4.7.1 I/O Error Handling Routines

Two new functions enable the user to specify their own error handling routine for formatted input on a logical unit. When a formatting error is detected, the runtime I/O library calls the specified user-supplied handler routine with data pointing at the character in the input line causing the error. The handler routine can supply a new character and allow the I/O operation to continue at the point where the error was detected using the new character; or take the default Fortran error handling.

The new routines, SET_IO_ERR_HANDLER(3f) and GET_IO_ERR_HANDLER(3f), are module subroutines and require USE SUN_IO_HANDLERS in the routine that calls them. See the man pages for these routines for details.

4.7.2 Variable Format Expressions

Fortran 77 allowed any integer constant in a format to be replaced by an arbitrary expression enclosed in angle brackets:

1 FORMAT(< expr > … )

Variable format expressions cannot appear as the n in an nH… edit descriptor, in a FORMAT statement that is referenced by an ASSIGN statement, or in a FORMAT statement within a parallel region.

This feature is enabled natively in f95, and does not require the -f77 compatibility option flag.

4.7.3 NAMELIST Input Format

4.7.4 Binary Unformatted I/O

Opening a file with FORM=’BINARY’ has roughly the same effect as FORM=’UNFORMATTED’, except that no record lengths are embedded in the file. Without this data, there is no way to tell where one record begins, or ends. Thus, it is impossible to BACKSPACE a FORM=’BINARY’ file, because there is no way of telling where to backspace to. A READ on a ’BINARY’ file will read as much data as needed to fill the variables on the input list.

4.7.5 Miscellaneous I/O Extensions