Skip to main content

3.5) Example Of 'Open' To Read Data From A File


The inputdata.dat must exist in the directory that you run the program and, of course, it must have the data that you are trying to read into the program.

1       program example4
2       ! example of reading from the keyboard
3       real :: a
4       open(unit=22, file=’inputdata.dat’)
5       read (22,*) a
6       print *, a
7       end program example4

This shows you how to read values into programs from files using the read statement on line 5. Remember, the 22 is a number you choose and if you have more than one input file use different numbers to label each.