Write statement does not print correct value?

Write statement does not print correct value?

Post by jchauvi » Thu, 23 Mar 2006 01:47:56


I am stumped by the following code (cut and trimmed from a larger
program). When compiled and executed as shown on a SGI UNIX workstation
using a Fortran 77 compiler, the two write statements generate this
output:

4860.850000000000
Value= 48608.5000

As you can see, the write statement in Main writes the value as if
multiplied by 10. If I delete the write statement in Function Value the
output is correct: Any idea what is wrong with this code?


PROGRAM Main

IMPLICIT NONE

DOUBLE PRECISION A
DOUBLE PRECISION Value

A = 1.0D0

WRITE(0,700) Value(A)
700 FORMAT('Value=',F12.4)

STOP
END
DOUBLE PRECISION FUNCTION Value(A)

IMPLICIT NONE

DOUBLE PRECISION A

Value = 4860.8500D0
WRITE(0,*) Value

RETURN
END
 
 
 

Write statement does not print correct value?

Post by Michael Me » Thu, 23 Mar 2006 01:59:24


Very strange. Works perfectly well with CVF. A compiler bug, but a very odd
one for an old compiler?

Regards,

Mike Metcalf

 
 
 

Write statement does not print correct value?

Post by Warner BRU » Thu, 23 Mar 2006 02:16:53


This is a case of Input/Output while Input Output is active.
If you assign the value of the FUNCTION Value to some variable,
and then print the value of the variable, it will work.

b= Value(A)
write (0,700) b

Warner
 
 
 

Write statement does not print correct value?

Post by Gordon San » Thu, 23 Mar 2006 02:50:54

On 2006-03-21 12:47:56 -0400, XXXX@XXXXX.COM said:


Did you cut and trim a "1p" format modifier out of existance?
(Please read Richard's many stern, and all too true, instructions
on the perils of "describing" the error rather than showing the error.)

"1p" modifiers make e formats nicer but have this !@#%! effect on f formats
if you forget the fine print of the rules.
 
 
 

Write statement does not print correct value?

Post by nospa » Thu, 23 Mar 2006 03:10:16


And though you implied it, I didn't see you explicitly say, so I will...

Code that does this violates the standard, so this constitutes a bug in
your code. And no, compilers are not required to catch that bug; it is
of a kind where you can just get silent corruption of results.

As Gordon said, 1P edit descriptors can have symptoms like this. My
first reaction was to look for such a 1P because it sounds so much like
that kind of problem; those can be darn confusing - a stronger word than
"darn" might even be more appropriate. Might possibly still be the
problem, though I didn't see such a 1P. The so-called "recursive I/O"
(aka I/O while I/O is active) is a bug in the code in any case.

--
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
 
 
 

Write statement does not print correct value?

Post by Walter Spe » Thu, 23 Mar 2006 03:56:31


Which version of compiler are you using?

Your example works fine with the MIPSpro f90 compiler.

Walt
 
 
 

Write statement does not print correct value?

Post by Joos » Thu, 23 Mar 2006 04:31:38

I think this is not a compiler bug, but triggered by the recursive IO
statement.

Joost
 
 
 

Write statement does not print correct value?

Post by Michael Me » Thu, 23 Mar 2006 05:38:54


You're right. My too hasty conclusion.

Regards,

Mike Metcalf