.TI F77/IO_INTRO "Sep. 4, 1985"
F77 I/O - Introduction

By default, Fortran units 5, and 6 are connected to standard input and
standard output and unit 0 is connected to standard error.

A 'read' with no unit number reads from unit 5; a 'print' writes
to unit 6.  Thus, the default is that

.nf
	read 8010, ...
	read (5,8010) ...
	read (*,8010) ...
.fi

read from standard input (the terminal),

.nf
	print 8020, ...
	write (6,8020) ...
	write (*,8020) ...
.fi

write to standard output (the terminal) and

	write (0,8020) ...

writes to standard error (the terminal).

To enter an end-of-file from a terminal, type control-D (type the letter "d"
while holding down the key labeled "control").

You can avoid the use of format statements by using list directed I/O.
For example, the statements

.nf
	read *,  i,j,x,y
	print *, i,j,x,y
.fi

read i, j, x, and y from the terminal and write them back to it.

To read and write from disk files, it is simplest to write your program
as if you are reading and writing on the terminal.  Then use shell
I/O redirection:

	a.out < infile

reads from the file 'infile' instead of the terminal and

	a.out > outfile

writes to the file 'outfile' instead of the terminal.  These may be
combined as in:

	a.out < infile > outfile

F77 allows unit numbers to be between 0 and 99.  If you use a unit number
N other than 0, 5, or 6, then the default is for it to reference a file
named 'fort.N'.

Disk files may be explicitly opened for reading and writing with the 'open'
statement:

	open( N, file='filename')

where N is any of 0 ... 99 .

Appropriately named environment variables override default file names
or file names in 'open' statements.
The corresponding environment variable name is the same
as the file name with periods deleted.
For example, a program containing:
.nf

      open(32,file="data.d")
      read(32,100) vec
      write(44) vec

.fi
normally will read from file 'data.d' and write to
file 'fort.44' in the current directory.
If the environment variables 'datad' and 'fort44' are set:
.nf

% setenv datad mydata
% setenv fort44 myout

.nf
in the C shell or:
.nf

$ datad=mydata
$ fort44=myout
$ export datad fort44

.fi
in the Bourne shell, then the program will read from 'mydata' and
write to 'myout'.
If the file name in the open statement is a path name including
slashes, then only the tail (the part after the last slash) is used
in looking for an environment variable.

Carriage control is not normally recognized by the f77 I/O library,
see "help f77 carriage_cc" to see how to use carriage control.

To find out if a logical unit is connected to a terminal, use the 
logical function 'isatty()',  see "man 3f ttynam" for details.

For an example of random access I/O, see "help f77 io_random".
For a list of errors from the f77 I/O library, see "help f77 io_err_msgs".
