(snip, someone wrote)
>> Hopefully, no one will call me "idiot" for asking but what
>> defines "end of record" in fortran? I too use gfortran.
then Dick Hendrickson <
dick.hen...@att.net> wrote:
> There isn't a specific definition of "end of record"; that is, there
> isn't specified character. To understand historic Fortran I/O you
> mostly have to think about card readers and line printers. When Fortran
> reads a "record" it reads one card-the entire card goes through the card
> reader. When it outputs a record, it prints one line and the printer
> moves the paper forward one notch. Of course, things are different now.
> Punch cards and line printers don't exist. But the idea is the same.
> Historically, a Fortran output statement would produce at least one
> record; you could get more by using a FORMAT statement with either long
> lists or special format things. Similarly, a read statement would read
> one (or more) input records.
It is interesting. The IBM 704, where Fortran started, read each row
of holes into two 36 bit words. Software had to rearrange that to
72 characters. The last 8 card columns weren't read at all.
> So, the simple answer is that an output statement produces one (or more)
> records; each separated from the other by a processor dependent
> end-of-record thing and a read statement reads one (or more) records; it
> reads the entire record, up to the end-of-record thing. The standard
> doesn't specify what the end-of-record thing is; but, Fortran exists in
> a computing system and usually uses whatever the other languages use.
> It's a little harder to understand with the later versions of Fortran.
> Non-advancing I/O allows you to read or write part of a record (sort of
> like reading the first half of a card). Stream I/O allows you to use the
> C model of I/O; I/O just produces a stream of characters and the OS
> doesn't impose a particular structure on the characters. Although other
> programs might require or expect some sort of structure. If you send a
> stream output file to a screen something has to happen when the cursor
> comes to the right hand edge of the screen.
I started learning PL/I, not so long after Fortran. Even though designed
around IBM's record oriented file system, PL/I uses STREAM I/O for
what Fortran calls FORMATTED. It is still record buffered, but the
program can write parts of records at a time.
I don't know so well the systems where C originated, but at least in
the ANSI standard, and I believe even in K&R the idea that the system
will buffer the I/O is there.
The usual implementation of getc() and putc() uses C macros to load
and store from/to a buffer, only doing an actual function call when
the buffer is empty/full.
The early Fortran systems might have directly used the I/O buffer
that the system used for actual I/O operations.
Many systems now put another level of buffering between the program
and the I/O devices. Unix uses that as a disk cache, to speed up
I/O by prefetching and delaying writing full buffers.
So, or a long time now, there is not necessarily a connection
between records as seen by the program and those actually seen
by the I/O device.
-- glen