------- 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