JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for COMP-FORTRAN-90 Archives


COMP-FORTRAN-90 Archives

COMP-FORTRAN-90 Archives


COMP-FORTRAN-90@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

COMP-FORTRAN-90 Home

COMP-FORTRAN-90 Home

COMP-FORTRAN-90  2005

COMP-FORTRAN-90 2005

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: Stream I/O questions

From:

Malcolm Cohen <[log in to unmask]>

Reply-To:

Fortran 90 List <[log in to unmask]>

Date:

Thu, 7 Jul 2005 09:53:21 +0900

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (116 lines)

Clive Page wrote:
>I had not appreciated the substantial differences between formatted and 
>unformatted stream I/O, and had only looked properly at the sections of 
>the Standard describing the former.

Right.

Of course these are meant to interoperate with the different kinds of C
files, as I mentioned.  In strict C (that is, by the C standard), binary
and text files behave quite differently.  On Unix these are essentially
identical.  But on other operating systems (C has existed on IBM MVS, DEC
VMS, not to mention uSoft Windows) these are either slightly different or
wildly different.

Unix C programmers often don't appreciate this - as they used to say
"All the world's a VAX" (meaning VAX Unix).

>However  there does not seem to be any corresponding statement in 
>9.5.3.4.2 describing formatted data transfer.  To me this looks like an 
>unfortunate omission from the Standard.

I remembered where one part of this was - in 10.6.3 and 10.7.2.
This covers the situation where a complete record is transferred
(the normal situation), and is quite clear (even if it might not
be where you were expecting it!).

For non-advancing i/o, I think the language is a little harder to find and
understand.  Maybe some of 10.7.1 helps (then again, maybe not since it
talks about transmission of characters to/from the record instead of the
file -- some of the terminlogy could do with updating here).  Actually,
I think the difficulty here is pretty much unrelated to stream i/o and
is all involved in non-advancing i/o.  I'd hesitate to say that it was
wrong or omitted though, even if I think it warrants improved wording.
(Saying "I can't nail it down" is not equivalent to "It is not fixed down".)

>Actually, I still don't quite see why the restriction is needed: what 
>harm can come from being able to re-write a section of a file starting 
>at any arbitrary byte-offset, since one can do this with an unformatted 
>file?  I suppose it must be something to do with the penchant that some 
>systems have for inserting arbitrary CR and/or LF characters in 
>formatted output, which would make the resulting character-count hard to 
>determine.

It's worse than that, though that is one aspect.  Consider what happens
to a file with variable-length records with embedded record counts (not
that uncommon a file format outside of Unix; VMS and MVS both have these,
for example).  If you write to it thinking it is a Unix file, you are
likely to clobber a record count and end up with complete gibberish if not
an invalid file.

Anyway, can I refer you to a very important section of the
Fortran standard: "1.1 Scope".  I quote

  "The purpose of [the Fortran standard] is to promote portability,
   reliability, maintainability, and efficient execution of Fortran
   programs for use on a variety of computing systems."

Relaxing the restriction you mention would promote non-portability,
unreliability, maintenance difficulty ... and all without improving
execution efficiency.  So it really goes against the whole point of
having a standard in the first place, which is so that people can
write programs and expect to have some chance of them working,
and continuing to work later.

>I can't help feeling that the description of stream I/O in the F2003 
>Standard is somewhat less than clear.  I think the basic mistake is for 
>it to be interspersed with the complexities of record-handling.

Well, a C "text stream" or Fortran "formatted stream" is in fact a record
file.  If you read the C standard that is in fact how they are described,
though it uses the term "lines" instead of "records".  And on many C
implementations, in particular the ones I mentioned before on MVS VMS et
al, C reads (and can write) the native record files perfectly fine.

So I disagree that the formatted i/o stuff (around 30 pages) should be
duplicated - the differences between the two versions would, I think,
be less than 2 pages worth.  That argues very strongly that we should
say it once, not twice.

> The whole point of stream I/O, I thought, was that for the first time it 
>frees the Fortran programmer from the shackles of record-based I/O.

I'm not sure which shackle you mean.

One that it does free you from is the fixed record length of a
sequential file.

It doesn't free you from being able to do
   WRITE(stream,*) "The value of X is",X
and have it work (and do the obvious thing).  Suggesting that this
shouldn't work would be akin to suggesting to a C programmer that "printf"
and friends are entirely wrong-headed and should be avoided as "shackles",
and is unlikely to receive a favourable reaction.

>If only IBM had been using punched tape instead of cards at the time 
>Fortran was invented, maybe this whole elaborate edifice would never 
>have been constructed?

Au contraire.  Formatted i/o is fundamentally about communicating with
people.  Not many people prefer to read their book or newspaper on a
kilometre-long strip of paper.

Even unformatted i/o was based on records (magtapes worked that way).
Losing the record structure doesn't actually change very much except
what you can do (no record structure = more restrictions on what the
programmer can do), which in turn enables different compiler optimisations
(for a disc file, don't bother to write the record lengths).

So I'd say that in every sense except the record length, a stream file puts
MORE shackles on the programmer, not fewer.

Cheers,
-- 
...........................Malcolm Cohen, Nihon NAG, Tokyo, Japan.
                           ([log in to unmask])

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

December 2023
February 2023
November 2022
September 2022
February 2022
January 2022
June 2021
November 2020
September 2020
June 2020
May 2020
April 2020
December 2019
October 2019
September 2019
March 2019
February 2019
January 2019
November 2018
October 2018
September 2018
August 2018
July 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
December 2015
November 2015
October 2015
September 2015
August 2015
June 2015
April 2015
March 2015
January 2015
December 2014
November 2014
October 2014
August 2014
July 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
July 2013
June 2013
May 2013
April 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
August 2010
July 2010
June 2010
March 2010
February 2010
January 2010
December 2009
October 2009
August 2009
July 2009
June 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998
1997


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager