I am working through the Fortran tutorial at http://en.wikibooks.org/wiki/Fortran/Fortran_simple_input_and_output. In the following program, what does unit=out_unit do?
program xproduct
implicit none
integer :: i,j
integer, parameter :: out_unit=20
print*,"enter two integers"
read (*,*) i,j
open (unit=out_unit,file="results.txt",action="write",status="replace")
write (out_unit,*) "The product of",i," and",j
write (out_unit,*) "is",i*j
close (out_unit)
end program xproduct
When I run this program, the text file results.txt contains the following text:
The product of 2 and 3
is 6
It specifies the “terminal” to write to. The number contained in out_unit represents the file you opened with the
openstatement. If you hadn’t used theopenstatement and specified the file, output would have been tofort.20Some terminal numbers have specific meanings. For example, 6 is (usually) stdout, and 5 is (usually) stdin.