Using fortran library flush() in a subroutine
Hi,
Using studio 11.
There is a different behavior when using flush() in main compared to
when using it in a subroutine. flush() doesn't work in a subroutine.
When using flush() in main the output is flushed to th i/o unit.
When using flush() in a subroutine the buffer is not being flushed
until the i/o unit is actually closed.
In this case the i/o unit is a FIFO.
Any comments appreciated.
/BR
Ulf
[469 byte] By [
Uffe_ba] at [2007-11-27 3:12:31]

# 2
I'm using tail -f f1 in one window for verifying the output activity.
dbx is used to step through in the main and p1 respectively.
compiled on Solaris 10 u3 Sparc as follows:
f90 -f77 -g -ftrap=%none -xrecursive -o FIFOTEST1 fifotest1.f
f90 -f77 -g -ftrap=%none -xrecursive -o FIFOTEST2 p1.f fifotest2.f
1. Using flush() from main:
fifotest1.f
program fifotest1
***f1 is a fifo created with mkfifo
integer*4 ios
open(50, file="f1", iostat=ios)
write(50,'(a)', iostat=ios) 'First line'
call sleep(2)
write(50,'(a)', iostat=ios) 'Next line'
call flush(50)
call sleep(2)
close(50)
stop
end
2. The same but from a subroutine
fifotest2.f
program fifotest2
cexecute :
cmkfifo f1
cFIFOTEST
ctail -f f1 in another window
call p1
stop
end
p1.f:
subroutine p1
integer*4 ios
open(50, file="f1", iostat=ios)
write(50,'(a)', iostat=ios) 'First line'
call sleep(2)
write(50,'(a)', iostat=ios) 'Next line'
call flush(50)
call sleep(2)
close(50)
return
end
# 3
I think the problem is the tail command. I get unpredictable behavior with both versions of the program: the output sometimes doesn't appear until the close statement is executed. However, if I use "cat f1" instead of "tail -f f1" then the output appears when the flush statement is
igba at 2007-7-12 8:15:00 >
