Note that Paul's code is essentially what "wc -l" does anyway. Most
current operating systems don't store information about the number of
records in a file, so the only way to find it out is to read through
the file and count them. Even if the Fortran language defined such a
query, that's how it would be implemented behind your back on most
current actual operating systems.
--
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
Well, the unix implementations of wc read the file in some sized blocks and
count the number of '\n' characters. It can do this without, for example,
needing a buffer big enough to store a line into.
I have had files with millions of characters and words, but no lines.
-- glen
> "Richard Maine" <nos...@see.signature> wrote in message
> news:uey8yhj...@altair.dfrc.nasa.gov...
> > Note that Paul's code is essentially what "wc -l" does anyway...
> Well, the unix implementations of wc read the file in some sized blocks and
> count the number of '\n' characters. It can do this without, for example,
> needing a buffer big enough to store a line into.
That's close enough to be what I intended to cover with my "essentially".
The fundamental approach theere is still "read through the file and
count"; it just tries to be efficient about doing that.
BTW, Paul's code doesn't necessarily need a buffer big enough to hold a
record either as he doesn't read any data items. Depends on the
particular compiler runtimes whether or not they would hav eto be able
to buffer the whole record or not.
The tradition I used to know for Fortran was that each read started with a
new record (line), and anything left at the end of the read statement was
ignored. In that case, yes, it should be able to ignore it. It isn't
easy to write the loop to do that, and it isn't easy to test all the cases,
either.
-- glen