FORTRAN 77 Language Reference

List-Directed I/O

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:

Output Format

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:

Also note:

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%

Table 5-8 Default Formats for List-Directed Output

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.

Unquoted Strings

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%

Internal I/O

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.