Help Files: Fortran77: IO Introdction





     HELP                      June 15, 1985              F77/IO_INTRO



                          F77 I/O - Introduction

     By default, Fortran units 5, and 6 are connected to standard  in-
     put  and  standard output and unit 0 is connected to standard er-
     ror.

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

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

     read from standard input (the terminal),

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

     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

             read *,  i,j,x,y
             print *, i,j,x,y

     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 en-
     vironment variable name is the same as the file name with periods
     deleted.  For example, a program containing:

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

     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:

     % setenv datad mydata
     % setenv fort44 myout

     in the C shell or:

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

     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  li-
     brary, see "help f77 carriage_cc" to see how to use carriage con-
     trol.

     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".  For detailed information on the I/O  library,  see
     "help f77 io_details".

             


Comments to decf@euler.berkeley.edu
© 1998 UC Regents