David
This function is not directly recursive, but many run time libraries croak
on code like this, as the WRITE which is contained within the function which
may be invoked from a WRITE statement (as in your example).
Have you considered the use of the G format? This has much the desired
effect, so you get F when it is ok and E when F is not ok. You could do
much the same with just:
PROGRAM RW
REAL :: X,Y
! Form not needed
X = 12.34567
WRITE (*, 100) ' X = ', X
Y = 12345.67
WRITE (*, 100) ' Y = ', Y
100 FORMAT(G20.7)
END PROGRAM RW
If you are really ambitious, the you can use the P qualifier with G!
Alistair
-----Original Message-----
From: Fortran 90 List [mailto:[log in to unmask]] On Behalf Of
Smith, David
Sent: 11 February 2003 19:59
To: [log in to unmask]
Subject: recursive write
Is the following program standard-conforming in Fortran-2000? Several F-95
compilers run it with no problems, although with debug options enabled some
give an error message about the recursive write.
Thanks,
David Smith
PROGRAM RW
REAL :: X,Y
CHARACTER(20), EXTERNAL :: FORM
X = 12.34567
WRITE (*,*) ' X = ',FORM(X)
Y = 12345.67
WRITE (*,*) ' Y = ',FORM(Y)
END PROGRAM RW
FUNCTION FORM(A)
CHARACTER(20) :: FORM
REAL :: A
IF (A >= 10.0 .AND. A <= 100.0) THEN
WRITE (FORM,"(F10.5)") A
ELSE
WRITE (FORM,"(E15.7)") A
ENDIF
END FUNCTION FORM
|