Question

I am running a loop in a Fortran 90 program 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)

Thanks in advance.

Was it helpful?

Solution

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

OTHER TIPS

You need to make the output unbuffered. Try setting the GFORTRAN_UNBUFFERED_ALL environment variable to 'y', 'Y' or 1.

When I need to flush, I just close the file and reopen. This is clumsy and slow, but I don't know of a better way in fortran 90 that'll work with all compilers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top