Skip to main content

3.8) Example Of How To Output Results To A File


Now when you learned how to read data into a program from a file, that file had to exist with the data in it already.  Now when you are outputting to a file typically the file would not exist and the program will make it for you automatically. If the file does exist already then when the program runs the file will be wiped and the new data entered.

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

This shows you how to read and write from or to files.