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



jwm wrote:
bru wrote:

Some time I want to have at the same time output on screen (Unit 6 or *)
and onto a file (OPEN(8,FILE= 'sosout')


An an other time I want only output on file (here unit 8) (for me it is
easier to visualize the output using vim editor) So I put in this case
OPEN(6,FILE= 'NO') because I dont need it


What about this:

integer, parameter :: USR_UNIT(2) = [6, 8]
integer i
logical StdOutput, FileOutput
real a, b, c

a = 1.; b = 2.; c = 3.

write(*, '("Std output? [T/F]: ")', ADVANCE = 'NO')
read(*, *) StdOutput

write(*, '("File? [T/F]: ")', ADVANCE = 'NO')
read(*, *) FileOutput

if (FileOutput) Open(unit = USR_UNIT(2), file = 'userfile.txt')

do i = 1, 2
if (i == 1 .AND. (.NOT.StdOutput)) cycle
if (i == 2 .AND. (.NOT.FileOutput)) cycle
write(USR_UNIT(i), "(' A B C=', 3F12.4)") a, b, c
enddo


I tried to compile your code: it works with g95, ifort and pgf90 but not with f90 of Sun; error messages are:


integer, parameter :: USR_UNIT(2) = [6, 8]
^
"io.f90", Line = 2, Column = 40: ERROR: Unexpected syntax: "operand" was expected but found "[".
^
"io.f90", Line = 2, Column = 44: ERROR: Unexpected syntax: "object-name" was expected but found "8".

f90: COMPILE TIME 0.090000 SECONDS
f90: MAXIMUM FIELD LENGTH 4282502 DECIMAL WORDS
f90: 22 SOURCE LINES
f90: 2 ERRORS, 0 WARNINGS, 0 OTHER MESSAGES, 0 ANSI

nor with f95 of NAG :

Error: io.f90, line 2: Illegal character '['
Error: io.f90, line 2: syntax error
***Invalid item in type declaration
Error: io.f90, line 2: Illegal character ']'
[f95 terminated - errors found by pass 1]

I'm not a specialist of Fortran 90!!

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

Thanks a lot for your ansver

Bernard Bru
.