Re: writing output listing onto screen (or not) and onto file



On Mon, 17 Jul 2006 08:15:09 -0700, bru wrote
(in article <e9g9ht$662$1@xxxxxxxxxxxxxxxx>):
Some time I want to have at the same time output on screen (Unit 6 or *)
and onto a file (OPEN(8,FILE= 'sosout')
....
integer, parameter :: USR_UNIT(2) = [6, 8]
^
"io.f90", Line = 2, Column = 40: ERROR: Unexpected syntax: "operand" was
expected but found "[".

That's just because of the use of the [] for array constructors. That
is an f2003 feature adopted as an extension by some f95 compilers, but
you can't portably count on it in f95. But that is peripheral to the
question.

Your solution seems to me to heavy because I have hundred of writes in
my code!!

Yes. I'd agree that this is a bit much for most applications. It
requires too much structuring of the code around this particular I/O
requirement.

If you want output to go to *EITHER* the terminal or a file, that is
relatively simple. There is a minor system-dependent piece needed to
get a unit number that is connected to standard output (f2003 finally
has a standard way to do this). Then you can select between that unit
or a unit connected to some other file. I do that kind of thing
regularly.

But if you want the output to go to both places, there isn't a "nice"
way to do that within Fortran. It requires that two WRITE statements be
executed. Something like the trick that jwm illustrated can be used to
make one statement that is executed twice, but still, the fundamental
issue is that there have to be two writes, whether written as two
separate statements, or as a single statement executed twice.

There are often ways outside of Fortran to do this. See the Unix "tee"
command (although sometimes it has "issues" with buffering, which can
cause awkwardness for interactive use.)

--
Richard Maine | Good judgment comes from
experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain

.