My colleague just came in, shouting aloud.
He had a datafile with on a particular line the value
3E-1
For some reason (which would lead us beyond the scope of this forum)
he was forced to read it using a non-trivial FORMAT.
His Fortran-program was reading this as a F5.2 real value into a real-
valued variable, say x.
Now I know why happened what has happened, and it is all conform the
standards.
Nevertheless, I am curious to get to know what you think would be the
result of
WRITE(*,*) x
Please give me your suggestion without running the code!
Arjan
Along the same lines as your example, but perhaps more interesting, is this:
program afloat
real x
read('3e-1','(F5.2)')x
write(*,*)x
if(x.eq.3e-1)then
write(*,10)
else
write(*,20)
endif
10 format(' 0.3 and 0.3 are equal')
20 format(' 0.3 is not equal to 0.3')
end
What will be the output of this program?
--mecej4
This was discussed not so long ago. I expect 0.003.
I was suggesting always using .0 on input formats to avoid this
problem. While there is some use in the implied decimal for
input without an E, I see little use in this case.
-- glen
Okay, I cheated. If I have a single line input file, and on that single
line I have a single four character string 3E-1, I then get an eof error
when I read with F5.2 specifier. If I add either a leading or trailing
space, I get a numerical result which is the same in both cases. Not
sure why it would be come out the same, however.
(snip)
> read('3e-1','(F5.2)')x
I believe this is still illegal in Fortran 2003, I don't
know about 2008.
The internal file is required to be a variable, not a constant,
and not an expression.
-- glen
And yes, there are compilers that reject it as a result. I've been
bitten by that one, so I know. I'm not sure whether that got changed in
f2008.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
On 2009-11-20 19:37:01 -0500, nos...@see.signature (Richard Maine) said:
> And yes, there are compilers that reject it as a result. I've been
> bitten by that one, so I know. I'm not sure whether that got changed in
> f2008.
In f08, an internal file variable must be a variable.
See 9.4, especially the first couple of bullets.
--
Cheers!
Dan Nagle
Oops :-( I had better fix how I describe reading numbers in CSV
format in my course, then ....
Regards,
Nick Maclaren.