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




Ken Fairfield wrote:
On 7/17/2006 8:15 AM, bru wrote:
[...snip example of selecting output units...]
Your solution seems to me to heavy because I have hundred of writes in
my code!!

In priniciple, you could generalize jwm's example to any number of
units/files, but isolate the multiple WRITE's to a subroutine you've
written, e.g., MY_WRITE, and then replace all the WRITE's with
MY_WRITE's in your code. Unfortunately in practice, that may be
quite difficult because of needing to pass a variable number of
arguments to MY_WRITE. Only if the number of different combinations
of format, argument number and argument types is fairly small would
this be feasible (presumably be using a generic feature to overload
the finite number of different versions...).

How about using an internal WRITE first, then sending the resulting
string to a subroutine along with a flag value which selects where
output goes?

implicit none
character(len=256) :: s
integer :: i,j

open(7,file='out.txt')

i=10
j=20

write(s,*)i,j
call prt_sub(s,1)

i=i+10
j=j+20

write(s,*)i,j
call prt_sub(s,2)

i=i+10
j=j+20

write(s,*)i,j
call prt_sub(s,3)

end

subroutine prt_sub(s,f)
implicit none
character(*) :: s
integer :: f
select case(f)
case(1)
write(*,*)trim(s)
case(2)
write(7,*)trim(s)
case(3)
write(*,*)trim(s)
write(7,*)trim(s)
end select
end

-- elliot

.