From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,55ff5d6ec3ad09b6,start X-Google-Attributes: gidfee84,public X-Google-Thread: 1094ba,55ff5d6ec3ad09b6,start X-Google-Attributes: gid1094ba,public From: A.Panjkov@latrobe.edu.au.remove.this.tail.to.email.me.sorry (Andrej Panjkov) Subject: How to flush UBC buffers from Fortran 90? Date: 1997/05/28 Message-ID: #1/1 X-Deja-AN: 244366425 Organization: La Trobe University School of Mathematics Newsgroups: comp.unix.osf.osf1,comp.lang.fortran Hi... I'm running Fortran 90 under Digital Unix 3.2g. Sometimes I like to have my program print a little ticker on the screen to show me where it's up to: stdout=6 write(stdout,'(1x,i10, a1)', advance='no') icount, achar(13) The idea here is that the advance='no' option suppresses the newline character. The achar(13) takes us back to the start of the line, so the number printed for icount is overwritten each time: a nice one line ticker. (Note that this is stock standard Fortran 90, with an easy-to-control machine dependent bit, the use of achar(13). This is the sort of thing I used to do with the + carriage control character (and the fpr utility on systems that do not follow Fortran carriage control rules.) If you run this as is, all the output appears long after the program has been past the icount stage. Aha, I thought, buffering, read the manual. I was referred to flush(3f) and fsync(3f). Ok, let's try: stdout=6 write(stdout,'(i10, a1)', advance='no') icount, achar(13) call flush(stdout) No joy. It appears that flush(3f) doesn't quite spit everything onto the screen. I think that what is happening is that flush(3f) flushes the program's internal buffers to the *kernel's* buffers. Right, so let's try this fsync(3f) thing. Where's the man page? $ man 3f fsync There is not an entry for fsync in section 3. What? The Fortran 90 User manual says (5.5.7) "To request that UBC system buffers be written to disk, use the fsync library routine (see fsync(3f) and Chapter 11)." Just for fun, put in a call to (the incompletely documented) fsync(3f) anyway. ... call fsync() This compiles and links, but I still don't get instant output. QUESTIONS: 1) Why haven't I got the man page for fsync(3f) on my system? Is it in some Layered Software Product I haven't installed? 2) Why are internal buffers set up inside fortran programs when the OS kernel provides buffers as well? 3) I tried using the getfd function to try and get the file descriptor associated with logical unit 6 (stdout). It returned a -1 signalling an error. If I knew the file descriptor, I could call the C version of fsync (maybe). How can I find the file descriptor? 4) Does fsync flush the terminal i/o buffers as well as the disk buffers? 5) What is the interaction between non-advancing output and terminal buffering? Why doesn't a call to flush(3f) flush queued non-advancing output? Can I control buffering (maybe switching off line buffering)? stty raw doesn't seem to help. 6) I thought standard error was unbuffered? This appears not to be the case. 7) How does (and should) fpr interact with nonadvancing output? I don't think advance='no' is purely for simple prompts, but unless I can flush queued non-advancing output without sending an end-of-record at some point, that seems to be all I can do with it. Thanks for your help! -- --Andrej Sorry, to email me, remove the trailing words on my email address. I have to do this to limit the amount of junk email I receive. Dr Andrej Panjkov, Maths, La Trobe Uni, Melbourne Australia, Email: A.Panjkov@latrobe.edu.au.REMOVE.THIS.TO.EMAIL.ME Phone: Work: (03)94792595, Mobile: 0418 342 893 WWW: http://guardian.maths.latrobe.edu.au Public PGP key available from my web site. Fingerprint follows: pub 1024/4D09A1AD 1996/10/28 Andrej Panjkov Key fingerprint = BB 8D CB 1B 72 82 FC C7 0F 21 6B 85 CB 71 22 18