I think that stream I/O is long overdue in Fortran, so was pleased to
see it introduced in F2003, and also to see that the facility is
starting to appear in current compilers, e.g. g95.
I had assumed that with stream output, the information from the
data-transfer list of the WRITE statement would just be appended to the
output file. But a careful reading of the Standard makes it look much
more complicated.
For unformatted stream I/O, there can be a POS= specifier in the WRITE,
and POS is only allowed for READ/WRITE on files opened for stream access
- so far so good. Then I read in 9.5.1.10 that for formatted access the
only allowed values of the POS specifier are 1 or the value returned by
an INQUIRE statement. This seems to restrict output to the current end
of the file, or to its start. By positioning at the start, one would
seem to be overwriting its current contents there - but it is not clear
whether the previous contents further down the file are preserved or
not. If one can partially overwrite the start of a file, there seems no
reason to prevent a partial overwrite at some other intermediate point.
Or did I miss something?
As it is, with a formatted READ or WRITE, to move successively along the
stream it looks as if you have to have an INQUIRE by position before
every READ or WRITE. Can this really be true?
It also seems permissible to miss out the POS= in a WRITE or READ, in
which case 9.2.3.2 says that the file position is unchanged. This seems
to mean that successive WRITEs will just repeatedly overwrite at the
current point, and repeated READs just read the same thing repeatedly.
I can't see the value in that.
For unformatted stream I/O, there seems no similar restriction on the
value of POS=, but 9.2.3.2 says that if there is no error then the file
position is not changed. I do not understand the reason for this.
Nearly all of this seems counter-intuitive to me: I guess the inventors
of the stream I/O facility must have had some model of stream files in
mind which I have failed to understand. If anyone can enlighten me, I
would be grateful.
--
Clive Page
|