next up previous
Next: Computational Science and Up: Input in Fortran Previous: Input in Fortran

Reading from a file.

Just as the print * has an equivalent form in write(6,*) or write (unit=6,,fmt=*), the read * statement also has an equivalent statement.

      read (unit=5,fmt=*) count
tells the program to read count from (unit =5) the keyboard.

The read can also be used to read from a file. Consider:

      open (unit =7, file="input.file",status="old") 
                              ! An input file is assigned to unit 7.
      ...
      ...
      read (unit=7,fmt=*) alphad ! A variable is read from the input file.
      ...
      close (unit=7)
This program reads a real number from the file input.file which has been assigned to unit=7, and stores value in the variable alphad.


J. C. Diaz