next up previous contents
Next: Application Up: File I/O Previous: Opening files   Contents

Read and Write

The file read function has two parameters

  read( unit=unit-no, fmt=format-label )   [ list of arguments ]
Each parameter can be replaced by a , with the meaning ``default unit'' or ``default format''. We will talk later about formats.

The call

  read(5,*) R, V
reads two reals from unit number 5 in default format. Unit is predefined, and is the standard input (keyboard, unless redirected). Thus, an equivalent formulation is
  read(*,*) R, V

The file write function is very similar,

  write( unit\_no, format label )  [ list of arguments ]
Each parameter can be replaced by a (defaults). The call
  write(6,*) R, V
writes two reals onto unit number 6 in default format. Unit is predefined, and is the standard output (monitor, unless redirected). Thus, an equivalent formulation is
  write(*,*) R, V
The list of arguments must be of standard intrinsic types (unless explicit format is used). Each READ statement reads the arguments from a new line; non-advancing READ is possible, but we need to use formats.



Adrian Sandu 2001-08-26