------- Comment #6 from urbanjost at comcast dot net 2009-08-31 00:07 ------- Subject: Re: NAMELIST input with just a comment ("&NAME ! comment \") fails
Because of 10.11.3.3-4 I believe (1) of 10.10.1 is intended to mean "throughout" and not "preceding"; and that 10.10.1 (2) through (5) should then be read as serially defining a NAMELIST group object. I believe that lines before &NAME do not have to conform to NAMELIST format at all; and that anything after the / is ignored, so it could LOOK like a comment but does not have to. Because of 10.11.3.3 I think this should be legal: Anything I like, whatsoever ! something that LOOKS like a comment but is not &CMD! a comment ! another comment ! and another / !whatever, which happens to look like a comment That is, nothing counts until the line with "^[ *]&NAME" or after "/" (using regexp syntax) and that anything beginning with an exclamation not in a string literal is ignored up to and except for the EOL. So the above would be completely equivalent to &CMD / I think 10.10.1 item (1) is misleading because the rest of the list defines a NAMELIST group's allowable content in order; but that the extraneous blanks are intended to be ignored throughout except in string constants. I also think strings MUST be quoted on input; and the gfortran behavior for C=NAME when C refers to a character variable is acting suspicously. PS: Combining NAMELIST with GET_COMMAND_ARGUMENTS makes for a REALLY flexible command line parser (http://home.comcast.net/~urbanjost/CLONE/KRACKEN/namelist/index.html). The page is a work in progress; I was trying to show how a single program could use NAMELIST to have a consistent syntax for command line arguments, a configuration file, interactive parameter input, and file-based input; it is very promising because of it's simplicity and consistency, but I've hit quirks between compilers that has made me suddenly far more careful in my reading of the f2003 standard's sections on NAMELIST; and I'm convinced this not a request for an extension -- but I've been wrong before too. !! 10.11.3.3 Namelist group object list items !! !! 1 The name-value subsequences are evaluated serially, in left-to-right order. A namelist group object designator !! may appear in more than one name-value sequence. !! !! 2 When the name in the input record represents an array variable or a variable of derived type, the effect is as !! if the variable represented were expanded into a sequence of scalar list items, in the same way that formatted !! input/output list items are expanded (9.6.3). Each input value following the equals shall then be acceptable to !! format specifications for the type of the list item in the corresponding position in the expanded sequence, except !! as noted in this subclause. The number of values following the equals shall not exceed the number of list items !! in the expanded sequence, but may be less; in the latter case, the effect is as if sufficient null values had been !! appended to match any remaining list items in the expanded sequence. !! !! NOTE 10.35 !! For example, if the name in the input record is the name of an integer array of size 100, at most 100 values, !! each of which is either a digit string or a null value, may follow the equals; these values would then be !! assigned to the elements of the array in array element order. !! !! 3 A slash encountered as a value separator during the execution of a namelist input statement causes termination !! of execution of that input statement after transference of the previous value. If there are additional items in the !! namelist group object being transferred, the effect is as if null values had been supplied for them. !! !! 4 A namelist comment may appear after any value separator except a slash. A namelist comment is also permitted !! to start in the first nonblank position of an input record except within a character literal constant. !! !! 5 Successive namelist records are read by namelist input until a slash is encountered; the remainder of the record !! is ignored and need not follow the rules for namelist input values. ----- Original Message ----- From: "sgk at troutmask dot apl dot washington dot edu" <gcc-bugzi...@gcc.gnu.org> To: <urbanj...@comcast.net> Sent: Sunday, August 30, 2009 1:58 PM Subject: [Bug fortran/41192] NAMELIST input with just a comment ("&NAME ! comment \") fails > > > ------- Comment #3 from sgk at troutmask dot apl dot washington dot edu > 2009-08-30 17:58 ------- > Subject: Re: NAMELIST input with just a comment ("&NAME ! comment \") > fails > > On Sun, Aug 30, 2009 at 05:48:15PM -0000, kargl at gcc dot gnu dot org > wrote: >> >> >> ------- Comment #2 from kargl at gcc dot gnu dot org 2009-08-30 >> 17:48 ------- >> (In reply to comment #1) >> > Thanks for report , I will fix this. >> > >> >> It's not broken. >> > > Here's my analysis, which could be wrong. > > From the Fortran 2003 standard; > > 10.10.1 Namelist input > > Input for a namelist input statement consists of > (1) Optional blanks and namelist comments, > (2) The character & followed immediately by the namelist-group-name > as specified in the NAMELIST statement, > (3) One or more blanks, > (4) A sequence of zero or more name-value subsequences separated > by value separators, and > (5) A slash to terminate the namelist input. > > 10.10.1.6 Namelist Comments > > Except within a character literal constant, a "!" character after a > value separator or in the first nonblank position of a namelist input > record initiates a comment. > > In Section 10.9, one finds > > A value separator is > (1) A comma optionally preceded by one or more contiguous blanks > and optionally followed by one or more contiguous blanks, unless > the decimal edit mode is COMMA, in which case a semicolon is > used in place of the comma, > (2) A slash optionally preceded by one or more contiguous blanks > and optionally followed by one or more contiguous blanks, or > (3) One or more contiguous blanks between two nonblank values or > following the last nonblank value, where a nonblank value is > a constant, an r *c form, or an r * form. > > The namelist that appears to be causing an error in gfortran is > > &cmd > ! change no values > / > > The comment does not follow a value separator, so it comes down to > "or in the first nonblank position of a namelist input record initiates > a comment". Now, going back to 10.10.1, the first nonblank position > in a namelist input record would need to come before the &. That is, > the namelist should be > > ! change no values > &cmd > / > > This modification to the program suggests that my reading of the > Standard may be correct (although I have been known to get it wrong). > > program cmdline > > call process(' ', .false.) > call process('I=10 , J=20 K=30 ! change all three values', .false.) > call process(' ', .false.) > call process('! change no values', .true.) ! CAUSES ERROR IN GFORTRAN, > NOT > G95 > > contains > > subroutine process(string, invert) > implicit none > logical :: invert > character(len=*) :: string > character(len=132), save :: lines(3) > character(len=255) :: message > INTEGER :: I=1,J=2,K=3 > integer ios > NAMELIST /CMD/ I,J,K > save cmd > > if (invert .eqv. .true.) then > lines(2)='&cmd' > lines(1)=string > lines(3)='/' > else > lines(1)='&cmd' > lines(2)=string > lines(3)='/' > end if > > READ(lines,NML=CMD,IOSTAT=ios,IOMSG=message) > if(ios.ne.0)then > write(*,*)'E-R-R-O-R: PROCESSING COMMAND LINE, IOSTAT=',IOS > write(*,*)message > endif > write(*,NML=CMD) > > end subroutine process > > end program cmdline > > > -- > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41192 > > ------- You are receiving this mail because: ------- > You reported the bug, or are watching the reporter. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41192