Re: Write after nonadvancing read
- From: Gordon Sande <g.sande@xxxxxxxxxxxxxxxx>
- Date: Sat, 09 Feb 2008 17:19:09 GMT
On 2008-02-09 12:34:29 -0400, nospam@xxxxxxxxxxxxx (Richard Maine) said:
Thomas Koenig <tkoenig@xxxxxxxxxxxxx> wrote:
Should the following program do what I expect it to do, i.e....
print " ab12" ?
program main
character(len=2) :: c
character(len=4) :: d
write (10,'(A)') 'abcd'
rewind 10
read (10,'(A2)',advance="no") c
write(10,'(A)') '12'
rewind 10
read (10,'(A)') d
print *,d
end program main
The same should be true for stream I/O.
Is my analysis correct, or did I miss something?
I believe you have it right.
Well, there is a silly caveat that has nothing to do with the
nonadvancing stuff and also won't be a problem in practice, but just to
pick a nit as I'm looking for anything that could go wrong...
You don't have an OPEN statement. In particular, you don't have an OPEN
statement with pos='rewind'. The standard allows this to open an
existing file at a position other than the beginning, which would
certainly not give the result that you expect. There used to be systems
on which this could actually happen; I don't think there are any today,
but the standard allows it.
I recall using this trick of positioning a file in one step and
starting from that in the next on OS/360. That was some time ago as
360 has become 370 etc. They have very good historical continuity
so I would be surprised if it did not still work. For some reason
I think that it was safe to assume that the file was at the beginning
for the whole job, but clearly not for each step.
The notion comes from the physical properties of tape drives.
.
- Follow-Ups:
- Re: Write after nonadvancing read
- From: glen herrmannsfeldt
- Re: Write after nonadvancing read
- References:
- Write after nonadvancing read
- From: Thomas Koenig
- Re: Write after nonadvancing read
- From: Richard Maine
- Write after nonadvancing read
- Prev by Date: Re: Write after nonadvancing read
- Next by Date: Re: Replace one single line in a ascii data file
- Previous by thread: Re: Write after nonadvancing read
- Next by thread: Re: Write after nonadvancing read
- Index(es):
Relevant Pages
|