11.  Input/Output

11.1.  Format Variables

11.2.  END=, ERR=, and IOSTAT= Clauses

11.3.  Formatted I/O

11.3.1.  Character Constants

11.3.2.  Positional Editing Codes

11.3.3.  Colon

11.3.4.  Optional Plus Signs

11.3.5.  Blanks on Input

11.3.6.  Unrepresentable Values

11.3.7.  Iw.m

11.3.8.  Floating Point

11.3.9.  ``A'' Format Code

11.4.  Standard Units

11.5.  List-Directed Formatting

11.6.  Direct I/O

11.7.  Internal Files

11.8.  OPEN, CLOSE, and INQUIRE Statements

11.8.1.  OPEN

\(IP .nr IP +1

unit= a small non-negative integer which is the unit to which the file is to be connected. We allow, at the time of this writing, 0 through 9. If this parameter is the first one in the open statement, the unit= can be omitted. \(IP .nr IP +1

iostat= is the same as in read or write. \(IP .nr IP +1

err= is the same as in read or write. \(IP .nr IP +1

file= a character expression, which when stripped of trailing blanks, is the name of the file to be connected to the unit. The filename should not be given if the status=scratch. \(IP .nr IP +1

status= one of old, new, scratch, or unknown. If this parameter is not given, unknown is assumed. If scratch is given, a temporary file will be created. Temporary files are destroyed at the end of execution. If new is given, the file will be created if it doesn't exist, or truncated if it does. The meaning of unknown is processor dependent; our system treats it as synonymous with old. \(IP .nr IP +1

access= sequential or direct, depending on whether the file is to be opened for sequential or direct I/O. \(IP .nr IP +1

form= formatted or unformatted. \(IP .nr IP +1

recl= a positive integer specifying the record length of the direct access file being opened. We measure all record lengths in bytes. On UNIXsystems a record length of 1 has the special meaning explained in section 5.1 of the text. \(IP .nr IP +1

blank= null or zero. This parameter has meaning only for formatted I/O. The default value is null. zero means that blanks, other than leading blanks, in numeric input fields are to be treated as zeros.

11.8.2.  CLOSE

11.8.3.  INQUIRE

\(IP .nr IP +1

file= a character variable specifies the file the inquire is about. Trailing blanks in the file name are ignored. \(IP .nr IP +1

unit= an integer variable specifies the unit the inquire is about. Exactly one of file= or unit= must be used. \(IP .nr IP +1

iostat=, err= are as before. \(IP .nr IP +1

exist= a logical variable. The logical variable is set to .true. if the file or unit exists and is set to .false. otherwise. \(IP .nr IP +1

opened= a logical variable. The logical variable is set to .true. if the file is connected to a unit or if the unit is connected to a file, and it is set to .false. otherwise. \(IP .nr IP +1

number= an integer variable to which is assigned the number of the unit connected to the file, if any. \(IP .nr IP +1

named= a logical variable to which is assigned .true. if the file has a name, or .false. otherwise. \(IP .nr IP +1

name= a character variable to which is assigned the name of the file (inquire by file) or the name of the file connected to the unit (inquire by unit). The name will be the full name of the file. \(IP .nr IP +1

access= a character variable to which will be assigned the value 'sequential' if the connection is for sequential I/O, 'direct' if the connection is for direct I/O. The value becomes undefined if there is no connection. \(IP .nr IP +1

sequential= a character variable to which is assigned the value 'yes' if the file could be connected for sequential I/O, 'no' if the file could not be connected for sequential I/O, and 'unknown' if we can't tell. \(IP .nr IP +1

direct= a character variable to which is assigned the value 'yes' if the file could be connected for direct I/O, if the file could not be connected for direct I/O, and 'unknown' if we can't tell. \(IP .nr IP +1

form= a character variable to which is assigned the value 'formatted' if the file is connected for formatted I/O, or 'unformatted' if the file is connected for unformatted I/O. \(IP .nr IP +1

formatted= a character variable to which is assigned the value 'yes' if the file could be connected for formatted I/O, 'no' if the file could not be connected for formatted I/O, and 'unknown' if we can't tell. \(IP .nr IP +1

unformatted= a character variable to which is assigned the value 'yes' if the file could be connected for unformatted I/O, 'no' if the file could not be connected for unformatted I/O, and 'unknown' if we can't tell. \(IP .nr IP +1

recl= an integer variable to which is assigned the record length of the records in the file if the file is connected for direct access. \(IP .nr IP +1

nextrec= an integer variable to which is assigned one more than the number of the the last record read from a file connected for direct access. \(IP .nr IP +1

blank= a character variable to which is assigned the value 'null' if null blank control is in effect for the file connected for formatted I/O, 'zero' if blanks are being converted to zeros and the file is connected for formatted I/O.

      The gentle reader will remember that the people who wrote the standard probably weren't thinking of his needs. Here is an example. The declarations are omitted.

open(1, file="/dev/console")
On a UNIXsystem this statement opens the console for formatted sequential I/O. An inquire statement for either unit 1 or file "/dev/console" would reveal that the file exists, is connected to unit 1, has a name, namely "/dev/console", is opened for sequential I/O, could be connected for sequential I/O, could not be connected for direct I/O (can't seek), is connected for formatted I/O, could be connected for formatted I/O, could not be connected for unformatted I/O (can't seek), has neither a record length nor a next record number, and is ignoring blanks in numeric fields.

      In the UNIXsystem environment, the only way to discover what permissions you have for a file is to open it and try to read and write it. The err= parameter will return system error numbers. The inquire statement does not give a way of determining permissions.