best ways to flush? 
Author Message
 best ways to flush?

I'm currently writing a c/mpi program that forks off a child and hooks
up to the child's stdin, stdout and stderr.  Unfortunately, the child
fortran program never flushes to stdout or stderr, so I can't read the
buffers until the child dies and flushes automatically.

Though the program has hundreds, if not thousands, of different write
statements in its many subdirectories, it only prompts for new input
in around 8 different locations.  I'm considering putting a CALL
FLUSH(OUTUNT) at every prompt location.  Is this the best way to solve
my problem?  Are there WRITE or PRINT statements in fortran that flush
automatically?

Alternatively, is there a way that I can specify zero size for the
output buffer so the fortran program flushes with every character?

If none of this works, I may have to write a full pseudo-term or
borrow from expect c libraries.

thanks in advance,
Andrew Cook

P.S.- I wrote a test fortran program, and when I called flush after a
write, I ended up reading the stdio contents on the error stream!  Is
this more likely c related or fortran related?



Wed, 11 Aug 2004 05:23:52 GMT  
 best ways to flush?

Quote:

> Are there WRITE or PRINT statements in fortran that flush
> automatically?

Nope.  Anyway nothing portable, and I don't know of anything
even particularly common.

Quote:
> Alternatively, is there a way that I can specify zero size for the
> output buffer so the fortran program flushes with every character?

Perhaps.  This is all non-standard and system-specific, but I don't
see how you are going to avoid that.  (The flush procedure is
non-standard and system-specific, for that matter, although several
different systems do support something like it).

I use the following C code as part of my initialization for some
Fortran programs.  It sets line-buffering instead of completely
unbuffered, but you can probably make the appropriate mods (you
sound familliar with such things) or perhaps line-buferring is
adequate for you.

I've used this with the NAG f90/f95 compilers on multiple operating
systems.  It probably won't work for all Fortran compilers - I'd
almost guarantee hat it won't.  But it's worth a try.  I've deleted
a bunch of other functions from the file.  But I didn't bother to
check which includes were needed by this particular function, so
some of them are probably completely irrelevant.

/* sysdepc.c
 * system dependent io routines for getData.
 *
 * Version NAG f90 on most unix systems.
 * 22 Nov 96, Richard Maine: add sys_mem_copy.
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <errno.h>
#include <string.h>

/* Defines to make routines fortran-callable */
#define init_stdout init_stdout_

/* Initialize stdout to be linebufferred. */
void init_stdout()
{
  setvbuf(stdout, (char *) 0, _IOLBF, 256);

Quote:
}

--
Richard Maine                       |  Good judgment comes from experience;
email: my last name at host.domain  |  experience comes from bad judgment.
host: altair, domain: dfrc.nasa.gov |        -- Mark Twain


Wed, 11 Aug 2004 05:57:15 GMT  
 best ways to flush?


Quote:

> > Are there WRITE or PRINT statements in fortran that flush
> > automatically?

> Nope.  Anyway nothing portable, and I don't know of anything
> even particularly common.

> > Alternatively, is there a way that I can specify zero size for the
> > output buffer so the fortran program flushes with every character?

> Perhaps.  This is all non-standard and system-specific, but I don't
> see how you are going to avoid that.  (The flush procedure is
> non-standard and system-specific, for that matter, although several
> different systems do support something like it).

In a well designed system, events that cause or might need interaction
with external processes (like people or other programs) are automatically
detected and cause all buffers for the relevant I/O channels to flush at that
point.  Of course, such well designed systems are hard to find.  There used
to be more than now.

The point of this is that it would be a disservice to future users of the
language to enshrine a feature in the standard that shouldn't be needed
in the first place.

--
J. Giles



Wed, 11 Aug 2004 06:33:25 GMT  
 best ways to flush?

"James Giles"  wrote

Quote:
> In a well designed system, events that cause or might need interaction
> with external processes (like people or other programs) are automatically
> detected and cause all buffers for the relevant I/O channels to flush at
that
> point.  Of course, such well designed systems are hard to find.  There
used
> to be more than now.

Wouldn't this be a helpful feature for John Appleyard to include in his
comparisons of compiler debugging features?


Thu, 12 Aug 2004 02:23:19 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Best Place to trap all ways out of a window

2. Best word to flush output buffer

3. Which ways better??

4. Better ways of expressing "KIND"

5. Good ways to debug Tcl/Tk?

6. ** HELP ** Any way to flush unit 6 w/o flush command?

7. Top Ten ways to shoot yourself in the foot

8. ways to collect data from two collections of the same size

9. 27 MILLION WAYS To Make Money

10. How many ways can you get change from N dollars

11. The Many Ways of Sine

12. Object3D.Shape - ways to access/control multiple shapes?

 

 
Powered by phpBB® Forum Software