Search code examples
fortranflushgfortran

How do I flush output to file after each write with a Fortran program?


I am running a loop in a Fortran program compiled with gfortran that outputs numerical values to an output file for each iteration of the loop. The problem is that the output is not saved to the file but every so many steps. How do I get it to flush each step?

Example code:

open(unit=1,file='output')

do i = 1, 1000
 write(1,*) i
end do

close(unit=1)

Solution

  • The other way, if gfortran implements it, is to call the non-standard subroutine flush. Not all compilers do implement this.