For Programmers: Free Programming Magazines  


Home > Archive > Fortran > December 2005 > how to WRITE(*,*) in a RECURSIVE FUNCTION?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to WRITE(*,*) in a RECURSIVE FUNCTION?
Jonas Stein

2005-12-09, 7:18 pm

Hi,

i use gfortran, a gnu fortran compiler.=20
For debugging it would be usefull if i could write variables to std-out=
in a
(recursive) function.

My compiler denies that. ;-(

Any tricks, how i can do it?

--=20
mit besten Gr=FC=DFen,

Jonas Stein <news@jonasstein.de> =20

Richard Maine

2005-12-09, 7:18 pm

Jonas Stein <news@jonasstein.de> wrote:

> i use gfortran, a gnu fortran compiler.
> For debugging it would be usefull if i could write variables to std-out in a
> (recursive) function.
>
> My compiler denies that. ;-(


There is nothing particularly unusual about I/O (to standard out or
elsewhere) in recursive functions. If that doesn't work, it is a
compiler bug. *BUT*...

What is invalid is to do I/O in a function that is invoked from an I/O
statement. This is referred to as recursive I/O. It doesn't necessarily
have anything to do with whether or not any recursive functions are
involved; it can (and regularly does) come up even with nonrecursive
functions.

F2003 allows a limitted but common case. In particular, in f2003 you can
do internal I/O, but not external I/O (standard out would be external)
while another I/O statement is active. Several f90/f95 compilers already
allow that f2003 feature (and I think I recall that gfortran either does
or plans to do so), but it won't help you for standard output.

The workaround, if you have a function (recursive or not) that does I/O,
is to avoid invoking that function directly in an I/O statement. That
is, instead of doing

write (...) f(whatever)

instead do

temp_variable = f(whatever)
write (...) temp_variable

If your problem actually has anything at all to do with recursive
functions (as opposed to recursive I/O), then something else is wrong
and you will need to show the actual code.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com