Flush buffer in Fortran
I have a long-running job that writes messages to a file to tell how it
is doing. The job runs in the background under UNIX (f77 under SUN
Sparc running Solaris, and also on a DEC alpha under ULTRIX).
Trouble is I can't read the messages till they are ancient history.
Is there a way to flush the output buffer each time a message is
written? Most likely this is operating system specific, but
any help would be appreciated.
Answer 1:
Many FORTRAN systems have a flush routine: call flush(6)
You can insert this line just after the print statement that you want
to see the output from immediately after it is executed. On some
machines the unit number is different. For example, on Cray computers
you would do something like
print'(a,/,(1p10e13.5))',' DEBUG ARRAY:',array
cal flush(101)
Answer 2:
OPEN the file once with STATUS='UNKNOWN' and CLOSE it immediately.Then OPEN it everytime before you write the message with STATUS='OLD'
and CLOSE it after the message. The CLOSE should flush the output
buffer. I don't think that this is covered by the standard, but it's
hard to imagine a runtime than would not flush the buffer after a
CLOSE. It worked for me on various UN*X systems.

0 Comments:
Post a Comment
<< Home