Richard Maine <nos...@see.signature> wrote:
> <
john.chl...@gmail.com> wrote:
>> I have a data file that includes many real values without a decimal point,
(snip)
>> read(unit=funit, fmt="(a)", iostat=stat) line
>> read(line, "(f10.0)") Eng_GimRatio(6)
Why read into line, and then read from there?
There are some reasons to do that, but none that I can
see from what was (before snip) given.
>> Of course f10.0 doesn't work. Is there some format that will?
> Others seem to have adequately already answered the question. Let me
> just note that "doesn't work" is almost always an inadequate
> description. In fact, as dpb pointed out, the above "of course" to the
> contrary, it does work. Or anyway, it should work and it does for me.
I it is likely to fail for Fortran 66 and, I believe for Fortran 77.
I am not sure when BLANK='NULL' was added to OPEN. Before that,
or now with BLANK='ZERO' the value must be right justified in
ten columns. (And note that it will still fail for numbers longer
than 10 digits.
It can also fail if line is too small to hold the whole thing.
(Say, CHARACTER*1 for example.)
Since internal READ doesn't have an OPEN, there isn't any place
to put BLANK=.
> I confess as to some curiosity as to what it is that "doesn't work" for
> you. My crystal ball isn't working for me. I made a few wild guesses,
> but when I tested them, they all worked too, so they are probably out.
> Makes me almost wonder whether you didn't actually try it because you
> assumed that, of course, it wouldn't work.
>> I could read the values as integers and then convert them to double
>> precision? Would that be best?
The idea behind the .0 part of the format descriptor is to
specify the position of the decimal point if it isn't supplied
in the input data.
> That will work, but then so will the original, or list-directed as
> Dieter suggested.
List directed is a good choice. Explicit format is most useful when
the data has fixed columns. In the days of punched cards, it was
somewhat usual to punch the fields with no extra space in between,
and sometimes with no decimal point. You could read a card like
123453927851203
with 3F5.2 into a three element REAL array, and get
(values approximating) 123.45, 392.78, and 512.03. Sometimes cards
would be preprinted with lines separating the columns making it easier
to read (by people).
This made some sense on cards, but much less for terminal input.
> I'd probably lean sligtly towards the list-directed option, but I'm
> still curious about what the alleged problem was.
Also, in many cases you can do the list directed read directly,
without the intermediate line variable.
-- glen