List-directed I/O is a free-form I/O for sequential access devices. To get it, use an asterisk as the format identifier, as in:
READ( 6, * ) A, B, C
Note these rules for list-directed input:
On input, values are separated by strings of blanks and, possibly, a comma.
Values, except for character strings, cannot contain blanks.
Character strings can be quoted strings, using pairs of quotes ("), pairs of apostrophes ('), or unquoted strings (see "Unquoted Strings "), but not hollerith (nHxyz) strings.
End-of-record counts as a blank, except in character strings, where it is ignored.
Complex constants are given as two real constants separated by a comma and enclosed in parentheses.
A null input field, such as between two consecutive commas, means that the corresponding variable in the I/O list is not changed.
Input data items can be preceded by repetition counts, as in:
4*(3.,2.) 2*, 4*'hello'
The above input stands for 4 complex constants, 2 null input fields, and 4 string constants.
A slash (/) in the input list terminates assignment of values to the input list during list-directed input, and the remainder of the current input line is skipped. Any text that follows the slash is ignored and can be used to comment the data line.
List-directed output provides a quick and easy way to print output without fussing with format details. If you need exact formats, use formatted I/O. A suitable format is chosen for each item, and where a conflict exists between complete accuracy and simple output form, the simple form is chosen.
Note these rules for list-directed output:
In general, each record starts with a blank space. For a print file, that blank is not printed. See "Printing Files" for details. @
Character strings are printed as is. They are not enclosed in quotes, so only certain forms of strings can be read back using list-directed input. These forms are described in the next section.
A number with no exact binary representation is rounded off.
Example: No exact binary representation:
demo% cat lis5.f READ ( 5, * ) X WRITE( 6, * ) X, ' beauty' WRITE( 6, 1 ) X 1 FORMAT( 1X, F13.8, ' truth' ) END demo% f77 lis5.f lis5.f: MAIN: demo% a.out 1.4 1.40000000 beauty 1.39999998 truth demo%
In the above example, if you need accuracy, specify the format.
Also note:
Output lines longer than 80 characters are avoided where possible.
Complex and double complex values include an appropriate comma.
Real, double, and quadruple precision values are formatted differently.
A backslash-n (\n) in a character string is output as a carriage return, unless the -xl option is on, and then it is output as a backslash-n(\n).
Example: List-directed I/O and backslash-n, with and without -xl:
demo% cat f77 bslash.f CHARACTER S*8 / '12\n3' / PRINT *, S END demo%
Without -xl, \n prints as a carriage return:
demo% f77 -silent bslash.f demo% a.out 12 3 demo%
With -xl, \n prints as a character string:
demo% f77 -xl -silent bslash.f demo% a.out 12\n3 demo%
Type |
Format |
---|---|
BYTE CHARACTER*n COMPLEX COMPLEX*16 COMPLEX*32 INTEGER*2 INTEGER*4 INTEGER*8 LOGICAL*1 LOGICAL*2 LOGICAL*4 LOGICAL*8 REAL REAL*8 REAL*16 |
Two blanks followed by the number An {n = length of character expression} '¤¤(', 1PE14.5E2, ',', 1PE14.5E2, ')' '¤¤(', 1PE22.13.E2, ',', 1PE22.13.E2, ')' '¤¤(', 1PE44.34E3, ',', 1PE44.34E3, ')' Two blanks followed by the number Two blanks followed by the number Two blanks followed by the number Two blanks followed by the number L3 L3 L3 1PE14.5E2 1PE22.13.E2 1PE44.34E4 |
COMPLEX*32 and REAL*16 are SPARC only.
f77 list-directed I/O allows reading of a string not enclosed in quotes. @
The string must not start with a digit, and cannot contain separators (commas or slashes (/)) or whitespace (spaces or tabs). A newline terminates the string unless escaped with a backslash (\). Any string not meeting the above restrictions must be enclosed in single or double quotes.
Example: List-directed input of unquoted strings:
CHARACTER C*6, S*8 READ *, I, C, N, S PRINT *, I, C, N, S END
The above program, unquoted.f, reads and displays as follows:
demo% a.out 23 label 82 locked 23label 82locked demo%
f77 extends list-directed I/O to allow internal I/O. @
During internal, list-directed reads, characters are consumed until the input list is satisfied or the end-of-file is reached. During internal, list-directed writes, records are filled until the output list is satisfied. The length of an internal array element should be at least 20 characters to avoid logical record overflow when writing double-precision values. Internal, list-directed read was implemented to make command line decoding easier. Internal, list-directed output should be avoided.