What is the supposed result when one runs the following program?
Shall it print "0" or shall it abort with an end-of-record error?
Naively I had expected an EOR (or EOF), but with all but one compiler
there is no reading error but a "0" is printed.
What does the standard demand (and in the case both is acceptable by the
standard, what is the personally prefered result)?
I looked into the standard, but I could seemingly not spot the right place.
---------------------------------
implicit none
character(len=5) :: str
integer :: a
str = ''
a = 5
read(str,'(5x,i1)') a
print *, a
end
---------------------------------
(The zero printing is due to: "10.6.1 Numeric editing": "On Input [...]
A field containing only blanks is considered to be zero.")
Thanks,
Tobias
|
|
0
|
|
|
|
Reply
|
burnus (564)
|
4/27/2009 11:49:48 AM |
|
Tobias Burnus <burnus@net-b.de> wrote:
> What is the supposed result when one runs the following program?
> Shall it print "0" or shall it abort with an end-of-record error?
> Naively I had expected an EOR (or EOF), but with all but one
> compiler there is no reading error but a "0" is printed.
> What does the standard demand (and in the case both is
> acceptable by the standard, what is the personally
> prefered result)?
As far as I understand it, at least for external I/O, it has been
allowed over the years either EOR or to consider the record
extended with blanks. Part of the reason for the confusion is
from the transition from fixed length records (cards) to variable
length (CRLF terminated lines). With card input, records were
always 80 characters long, even if there were no printable
characters.
> I looked into the standard, but I could seemingly not spot
> the right place.
> ---------------------------------
> implicit none
> character(len=5) :: str
> integer :: a
> str = ''
> a = 5
> read(str,'(5x,i1)') a
> print *, a
> end
> ---------------------------------
> (The zero printing is due to: "10.6.1 Numeric editing": "On Input [...]
> A field containing only blanks is considered to be zero.")
-- glen
|
|
0
|
|
|
|
Reply
|
gah (12236)
|
4/27/2009 12:11:31 PM
|
|
Tobias Burnus wrote:
> What is the supposed result when one runs the following program?
> Shall it print "0" or shall it abort with an end-of-record error?
>
> Naively I had expected an EOR (or EOF), but with all but one compiler
> there is no reading error but a "0" is printed.
>
> What does the standard demand (and in the case both is acceptable by the
> standard, what is the personally prefered result)?
>
> I looked into the standard, but I could seemingly not spot the right place.
It's scattered around, but the PAD= is the thing you want.
In internal I/O it says it acts as if there were an OPEN
without a PAD= specifier. In the OPEN section it says the
default for no PAD= is YES. In 9.5.3.4.2 it finally says
"During advancing input when the pad mode has the value YES,
blank characters are supplied by the processor if the input
list and format specification require more characters from the record
than the record contains."
So, the processor should supply extra blanks as needed.
Dick hendrickson
>
> ---------------------------------
> implicit none
> character(len=5) :: str
> integer :: a
> str = ''
> a = 5
> read(str,'(5x,i1)') a
> print *, a
> end
> ---------------------------------
>
> (The zero printing is due to: "10.6.1 Numeric editing": "On Input [...]
> A field containing only blanks is considered to be zero.")
>
> Thanks,
>
> Tobias
|
|
0
|
|
|
|
Reply
|
dick.hendrickson (1286)
|
4/27/2009 3:51:27 PM
|
|
Dick Hendrickson <dick.hendrickson@att.net> wrote:
> Tobias Burnus wrote:
> > What is the supposed result when one runs the following program?
> > Shall it print "0" or shall it abort with an end-of-record error?
> >
> > Naively I had expected an EOR (or EOF), but with all but one compiler
> > there is no reading error but a "0" is printed.
....
> It's scattered around, but the PAD= is the thing you want.
> In internal I/O it says it acts as if there were an OPEN
> without a PAD= specifier....
> So, the processor should supply extra blanks as needed.
DIck has the basic analysis here. The one thing I'd add is that this
area has been tightened up over the years. I'd have to go dig to find
the exact relevant versions of the standard, but the business about
internal I/O acting as if there were an OPEN was not there in all
versions.
I'm sure (fairly :-)) that this stuff is all straightened out by f2003,
which is probably what Dick is citing. I am also sure that it was not
specified in f77. I got bit by some related things in f77. In my case,
it was the BLANK specifier instead of PAD, but it was a simillar issue
of specifying how it worked for internal I/O. F77 completely failed to
state. My code failed with one compiler because I had assumed that the
default for PAD applied if PAD wasn't specified. It turns out that the
relevant material was all under the OPEN statement and did not apply to
any case where there wasn't an OPEN statement; the standard left those
cases unspecified and compilers varied in how they treated them.
I recall that, somewhere between f90/f95/f2003, there were at least two
revisions that tightened up this kind of thing. One revision specified
some cases, but missed others. By f2003, I'm fairly sure that things are
stated generally enough that all cases are covered. For f90 and f95, I'd
have to go digging to find exactly what cases are covered and what ones
aren't. I'm thinking it was something like that one revision hit
internal I/O, but forgot that the same question comes up for
preconnected units and the * files.
The code shown by the OP requires at least f90 (for several reasons, one
perhaps less than obvious at first glance). But it is at least possible
that the one compiler that did other than return a zero might still be
conforming to f90; I'd need to check more carefully.
EOR should not be a possibility in any case. That applies only to
nonadvancing reads. And EOF would be wrong as well. For versions of the
standard prior to when PAD got adequately specified here, ERR would be
more appropriate... except that the standard doesn't specify the set of
I/O error conditions, so you couldn't count on that either.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
|
|
0
|
|
|
|
Reply
|
nospam47 (9742)
|
4/27/2009 4:45:20 PM
|
|
Richard Maine <nospam@see.signature> wrote:
> Dick Hendrickson <dick.hendrickson@att.net> wrote:
>> Tobias Burnus wrote:
>> > What is the supposed result when one runs the following program?
>> > Shall it print "0" or shall it abort with an end-of-record error?
>> > Naively I had expected an EOR (or EOF), but with all but one compiler
>> > there is no reading error but a "0" is printed.
>> It's scattered around, but the PAD= is the thing you want.
>> In internal I/O it says it acts as if there were an OPEN
>> without a PAD= specifier....
>> So, the processor should supply extra blanks as needed.
> DIck has the basic analysis here. The one thing I'd add is that this
> area has been tightened up over the years. I'd have to go dig to find
> the exact relevant versions of the standard, but the business about
> internal I/O acting as if there were an OPEN was not there in all
> versions.
So, as of Fortran 2003 it is required to pad with blanks.
For some older versions that requirement wasn't there.
I do remember end of record errors from OS/360 Fortran, reading
(or writing) fixed length records (often LRECL=80 for input,
and LRECL=133 for output). The DEC Fortran 66 compilers pretty
much had to pad, as programs would expect to read an input
record with a format like 80A1, and users would not be exprected
to add enough blanks to reach 80. No internal I/O in Fortran 66,
but DEC supplied ENCODE/DECODE for it. I don't remember if they
did padding for those.
> I'm sure (fairly :-)) that this stuff is all straightened out by f2003,
> which is probably what Dick is citing. I am also sure that it was not
> specified in f77. I got bit by some related things in f77.
(snip)
> I recall that, somewhere between f90/f95/f2003, there were at least two
> revisions that tightened up this kind of thing. One revision specified
> some cases, but missed others. By f2003, I'm fairly sure that things are
> stated generally enough that all cases are covered. For f90 and f95, I'd
> have to go digging to find exactly what cases are covered and what ones
> aren't. I'm thinking it was something like that one revision hit
> internal I/O, but forgot that the same question comes up for
> preconnected units and the * files.
> The code shown by the OP requires at least f90 (for several reasons, one
> perhaps less than obvious at first glance). But it is at least possible
> that the one compiler that did other than return a zero might still be
> conforming to f90; I'd need to check more carefully.
But if not, other than the reasons you indicate that the code
requires F90, an F77 implementation could generate an error?
> EOR should not be a possibility in any case. That applies only to
> nonadvancing reads. And EOF would be wrong as well. For versions of the
> standard prior to when PAD got adequately specified here, ERR would be
> more appropriate... except that the standard doesn't specify the set of
> I/O error conditions, so you couldn't count on that either.
At least in older versions of the standard you can get an end of
record error for formatted and/or unformatted, reading (or writing)
more than the specified record length.
-- glen
|
|
0
|
|
|
|
Reply
|
gah (12236)
|
4/27/2009 7:07:53 PM
|
|
In article <gt4vq9$1cv$1@naig.caltech.edu>,
glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:
>
>So, as of Fortran 2003 it is required to pad with blanks.
>For some older versions that requirement wasn't there.
As of Fortran 90, I believe.
>I do remember end of record errors from OS/360 Fortran, reading
>(or writing) fixed length records (often LRECL=80 for input,
>and LRECL=133 for output). The DEC Fortran 66 compilers pretty
>much had to pad, as programs would expect to read an input
>record with a format like 80A1, and users would not be exprected
>to add enough blanks to reach 80. No internal I/O in Fortran 66,
>but DEC supplied ENCODE/DECODE for it. I don't remember if they
>did padding for those.
That is so. It was one of the many reasons that porting VAX code
to IBM was murder. Our default format for MVS was VB, so we had
trouble, too.
Regards,
Nick Maclaren.
|
|
0
|
|
|
|
Reply
|
nmm12 (898)
|
4/27/2009 7:12:42 PM
|
|
glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:
> Richard Maine <nospam@see.signature> wrote:
> > The code shown by the OP requires at least f90 (for several reasons, one
> > perhaps less than obvious at first glance). But it is at least possible
> > that the one compiler that did other than return a zero might still be
> > conforming to f90; I'd need to check more carefully.
>
> But if not, other than the reasons you indicate that the code
> requires F90, an F77 implementation could generate an error?
Yes.
> > EOR should not be a possibility in any case. That applies only to
> > nonadvancing reads. And EOF would be wrong as well. For versions of the
> > standard prior to when PAD got adequately specified here, ERR would be
> > more appropriate... except that the standard doesn't specify the set of
> > I/O error conditions, so you couldn't count on that either.
>
> At least in older versions of the standard you can get an end of
> record error for formatted and/or unformatted, reading (or writing)
> more than the specified record length.
Sorry, but no, that's just not so. As I said, EOR applies only to
non-advancing reads. That is true in every version of the standard that
has had an EOR. If you are talking about some nonstandard extension, or
perhaps about some >0 value of the iostat return (which would be an
error return) that's a different matter, but it has nothing to do with
any version of the Fortran standard.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
|
|
0
|
|
|
|
Reply
|
nospam47 (9742)
|
4/27/2009 7:25:32 PM
|
|
nmm1@cam.ac.uk wrote:
> In article <gt4vq9$1cv$1@naig.caltech.edu>,
> glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:
>>So, as of Fortran 2003 it is required to pad with blanks.
>>For some older versions that requirement wasn't there.
> As of Fortran 90, I believe.
>>I do remember end of record errors from OS/360 Fortran, reading
>>(or writing) fixed length records (often LRECL=80 for input,
>>and LRECL=133 for output).
(snip)
> That is so. It was one of the many reasons that porting VAX code
> to IBM was murder. Our default format for MVS was VB, so we had
> trouble, too.
Did you ever use FIO999? That is how I used to do internal I/O
in the OS/360 days. A call to FIO999 would patch the Fortran
library routines (statically linked) such that calls to a
specified unit, often 999, would go to a supplied array instead
of to an actual I/O device. You supplied the unit, the array,
the record length, and the number of records. Not so portable,
but it did work.
-- glen
|
|
0
|
|
|
|
Reply
|
gah (12236)
|
4/27/2009 7:29:46 PM
|
|
Richard Maine <nospam@see.signature> wrote:
(snip, I wrote)
>> At least in older versions of the standard you can get an end of
>> record error for formatted and/or unformatted, reading (or writing)
>> more than the specified record length.
> Sorry, but no, that's just not so. As I said, EOR applies only to
> non-advancing reads. That is true in every version of the standard that
> has had an EOR. If you are talking about some nonstandard extension, or
> perhaps about some >0 value of the iostat return (which would be an
> error return) that's a different matter, but it has nothing to do with
> any version of the Fortran standard.
What do you call the error that happens when you read more
than was written to a record in an unformatted file? Most systems,
even if the standard doesn't, will call that an end of record error,
and abbreviate it EOR.
I agree that it isn't well described in the standard, but
it does (and did) happen.
-- glen
|
|
0
|
|
|
|
Reply
|
gah (12236)
|
4/27/2009 7:54:06 PM
|
|
In article <gt513a$1cv$3@naig.caltech.edu>,
glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:
>
>>>So, as of Fortran 2003 it is required to pad with blanks.
>>>For some older versions that requirement wasn't there.
>
>> As of Fortran 90, I believe.
>
>>>I do remember end of record errors from OS/360 Fortran, reading
>>>(or writing) fixed length records (often LRECL=80 for input,
>>>and LRECL=133 for output).
>(snip)
>
>> That is so. It was one of the many reasons that porting VAX code
>> to IBM was murder. Our default format for MVS was VB, so we had
>> trouble, too.
>
>Did you ever use FIO999? That is how I used to do internal I/O
>in the OS/360 days. A call to FIO999 would patch the Fortran
>library routines (statically linked) such that calls to a
>specified unit, often 999, would go to a supplied array instead
>of to an actual I/O device. You supplied the unit, the array,
>the record length, and the number of records. Not so portable,
>but it did work.
No, but I did comparable hacking :-) I am a machine code hacker from
way back, so usually find it quicker and more reliable to do my own
hacking than rely on someone else's.
Regards,
Nick Maclaren.
|
|
0
|
|
|
|
Reply
|
nmm12 (898)
|
4/27/2009 7:54:35 PM
|
|
glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:
> Richard Maine <nospam@see.signature> wrote:
> (snip, I wrote)
>
> >> At least in older versions of the standard you can get an end of
> >> record error for formatted and/or unformatted, reading (or writing)
> >> more than the specified record length.
>
> > Sorry, but no, that's just not so. As I said, EOR applies only to
> > non-advancing reads. That is true in every version of the standard that
> > has had an EOR. If you are talking about some nonstandard extension, or
> > perhaps about some >0 value of the iostat return (which would be an
> > error return) that's a different matter, but it has nothing to do with
> > any version of the Fortran standard.
>
> What do you call the error that happens when you read more
> than was written to a record in an unformatted file? Most systems,
> even if the standard doesn't, will call that an end of record error,
> and abbreviate it EOR.
>
> I agree that it isn't well described in the standard, but
> it does (and did) happen.
Sure it does, but that is not the end-of-record condition described in
the standard and is thus completely unrelated to the discussion. That
would be an error condition. If you want to use the term "end-of-record"
to describe that particular error condition, then fine, but you need to
qualify it as being an error condition. You can't just take a term from
the standard, use it in a context about the standard (you even said "in
older versions of the standard") and then expect people to understand
that you didn't actually mean the term in the standard.
That reminds me a little bit of a phase my daughter went through when
"nothing she said was ever wrong" because she had her own language in
which all the words meant something different and whatever she said was
correct in her language. :-) No, I'm not saying that you have the
"nothing I say is ever wrong" part; posters with that attitude tend to
be in my kill file (and you obviously aren't). I'm just noting the use
of a term to mean something other than what the standard says it means.
The standard itself even addresses general terminology issues like that.
Somewhere way up front, it says that terms are often given a specific
technical meaning in the standard and when so, that meaning is to be
used instead of some other general English meaning for the same term.
If you tell someone that an EOR condition will result from something,
they are going to be perfecty justified in testing for it with an EOR=,
which isn't going to work if you mean an error condition. And in the
case at hand, where the OP asks whether his code could generate an EOR,
the correct answer is no.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
|
|
0
|
|
|
|
Reply
|
nospam47 (9742)
|
4/27/2009 8:28:04 PM
|
|
|
10 Replies
46 Views
(page loaded in 0.097 seconds)
Similiar Articles: Converting number to std::string ("itoa()" ) - comp.lang.c++ ...The question about itoa is a FAQ (even literally ... Unix version 6, which was obsoleted by the standard I/O ... itoa()" ) - comp.lang.c++ ... convert integer to string ... integer overflow in atoi - comp.lang.c... which converts string to an integer. So ... or 0x2A05F200 are too ... C style question - comp.lang.c The only guarantee is that it is "an unsigned integer ... String to int ... Controlling File Descriptor Flush - comp.unix.solaris... impact is too great) using read() and write(). Mixing standard I/O ... comp.os.linux.questions ... Return the integer ``file descriptor'' that is used by ... string may ... Reading an unformatted file - comp.lang.fortran... SELECTED_REAL_KIND(p= 6) INTEGERS are just "INTEGER". ... The standard provides no guarantee of last-bit accuracy. ... It has been too long since I used pgf90 for me to ... perl + regex bug? - comp.lang.perl.miscBasically, I'm trying to grab an integer out of a string, and then ... A short description about what has happened by the ... interactive regular expressions If it's too much ... Adding simple database, excel export, and reports with D4 Pro ...From your questions over the last few ... property DataSL : TStringList read FDataSL; property Time2x : string index integer ... I know this has been "too much ... Something bad happened to my gfortran installation - comp.lang ...... not be replacing the [C_]SIZEOF until it is too ... SIZEOF(A)) string > ! =A0 character(16) string > ! =A0 integer L ... I recall an effort to scour the standard for the ... Converting character to float. - comp.lang.fortranThe standard allows for exceptions ... decimal point character and read the value as a integer. ... Now theory requires you to read in the money field as a character string ... std::map< MyString, MyString > comparison operator? - comp.lang ...So the question is, what does <string> implement that <MyString> needs in ... into a message (which is tough for you to read ... Before you get too happy, I strongly recommend ... problem with mixed c and fortran code - comp.lang.fortran ...... but a character string. However a struct too big to ... to the Fortran > standard. Thus the more meaningful question to me ... slightly harder to read font in the standard; and ... Integer (Java 2 Platform SE 5.0)Standard Ed. 5.0 PREV CLASS NEXT CLASS: FRAMES ... Returns the value of this Integer as a short. static int ... Decodes a String into an Integer. Accepts decimal, hexadecimal ... Stroustrup: C++ Style and Technique FAQ - AT&T | Cell Phones, U ...... for questions about the use of C++ and its standard library. ... coding standard? How do I read a string from input? How do I convert an integer to a ... are probably too ... 7/16/2012 8:50:10 AM
|