Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Friday-afternoon

0 views
Skip to first unread message

Arjan

unread,
Nov 20, 2009, 10:23:52 AM11/20/09
to
Hi!

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

mecej4

unread,
Nov 20, 2009, 10:57:25 AM11/20/09
to

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

glen herrmannsfeldt

unread,
Nov 20, 2009, 12:23:20 PM11/20/09
to

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

user1

unread,
Nov 20, 2009, 2:56:48 PM11/20/09
to

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.

glen herrmannsfeldt

unread,
Nov 20, 2009, 5:22:56 PM11/20/09
to
mecej4 <mecej4_...@operamail.com> wrote:

(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

Richard Maine

unread,
Nov 20, 2009, 7:37:01 PM11/20/09
to
glen herrmannsfeldt <g...@ugcs.caltech.edu> wrote:

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

Dan Nagle

unread,
Nov 20, 2009, 9:20:42 PM11/20/09
to
Hello,

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

nm...@cam.ac.uk

unread,
Nov 21, 2009, 3:13:52 AM11/21/09
to
In article <he7ipp$8gs$1...@news.eternal-september.org>,

Oops :-( I had better fix how I describe reading numbers in CSV
format in my course, then ....


Regards,
Nick Maclaren.

0 new messages