This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/33039] New: Read NAMELIST: reads wrong namelist name
- From: "slabinski dot victor at usno dot navy dot mil" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 9 Aug 2007 16:40:56 -0000
- Subject: [Bug fortran/33039] New: Read NAMELIST: reads wrong namelist name
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
This has probably already been submitted by Daniel Franke or Jerry DeLisle.
I am just trying to see if I can work this system.
FORTRAN NAMELIST Run Time Problem
The FORTRAN statement
READ(5, nml=CODE)
should read through the input file (connected to device number 5)
until it finds a namelist with the name 'CODE', and then read/process
that one namelist. On the next call to this read statement, the
program should read further into the input file to find the next
occurrence of the name 'CODE'.
This was the behaviour from the IBM and HP FORTRAN 77 compilers.
It is also the behaviour from the open source g77 compiler. A namelist
with name 'CODEone', 'CODEtwo', or 'CODEx' is treated as having a
different name, on the basis that the name ends at the trailing
'space' delimiter.
A gfortran compiled program appears to read these names and
conclude that since the first four letters match the requested name
'CODE', it has found the requested namelist. The program then treats
the remaining letters in the name as a variable name and complains
that 'one' and 'two' are not defined variables for this namelist.
In the case of reading the name 'CODEx', the gfortran program treats
the x as a variable name that it recognizes as a valid variable, but
complains that it is not followed by an equal sign.
It appears that the compiled program needs to read the whole
namelist name (up to the delimiting space) and then ask if this name
matches the request in the READ statement.
I include a short FORTRAN program 'namelist.f' that illustrates
the problem when used with the supplied input file 'namelist.in' .
The annotated output file 'namelist.out' gives the output (with errors)
I found using gfortran and g77 compilers. The problem occurs using
gcc-gfortran - 4.1.2-13.fc6.x86_64
libgfortran - 4.1.2-13.fc6.x86_64
running under Linux (Red Hat Fedora Core 6) and
gcc-gfortran - 4.1.2-12.i386
libgfortran - 4.1.2-12.i386
running under Linux (Red Hat Fedora Core 7).
Victor J. Slabinski
C********1*********2*********3*********4*********5*********6*********7**
C Test of namelist operation in Linux gfortran compiled program:
C Does the "namelist read" skip over namelists with other names or
C similar names? namelist.f
PROGRAM namelist
CHARACTER*25 CHAR
NAMELIST /CODE/ CHAR, X
NAMELIST /CODEtwo/ X
C
OPEN(5, file='namelist.in')
100 CHAR = 'Initialize string ***'
X = -777.
READ(5, nml=CODE, END=999)
WRITE(6,*) CHAR, X
GO TO 100
999 Itest = 95
write(6,*) 'Itest=',Itest
call exit(Itest)
STOP 'namelist'
END PROGRAM namelist
****************************************************************
File namelist.in with test NAMELIST inputs
&CODVJS char='VJS-Not a proper nml name', X=-0.5/
&CODEone char='CODEone input', X=-1.0 /
&CODEtwo char='CODEtwo inputs', X=-2.0/
&code char='Improper lower case name',X=-3.0/
&CODE char='Desired namelist sel', X=44./
&CODEx char='Should not read CODEx nml', X=-5./
$CODE char='Second desired nml', X=66.0 /
$CODE X=77.0, char='Reordered desired nml'/
**********************************************************************
Program output from NAMELIST reads with added, interpretive comments;
call on FORTRAN compiler also listed. namelist.out
**************************************
FORTRAN compiler call:
gfortran namelist.f -o namelist
Output from executing program 'namelist':
Cannot match namelist object name one !variable name 'one' is actually
part of nml name CODEone
CODEone input -1.000000 !output for namelist read that
should not have occurred
Cannot match namelist object name two !variable name 'two' is actually
part of nml name CODEtwo
CODEtwo inputs -2.000000 !output for namelist read that
should not have occurred
Improper lower case name -3.000000 !shows that nml name upper/lower
case does not matter
Desired namelist sel 44.00000
Equal sign must follow namelist object name x !variable name 'x' is
actually part of nml
name CODEx
Cannot match namelist object name har !words in nml string
namelist read: missplaced = sign !variable are now
Cannot match namelist object name should !treated as variable
Cannot match namelist object name not !names
Cannot match namelist object name read
Cannot match namelist object name codex
Cannot match namelist object name nml',
Initialize string *** -5.000000 !output for namelist read that
should not have occurred; note
that string variable 'char' never
changed value after initialization
Second desired nml 66.00000 !Note that input used '$' here, not
Reordered desired nml 77.00000 !standard '&', in front of nml name
STOP namelist
**************************************
FORTRAN compiler call:
g77 namelist.f -o namelist77
Output from executing program 'namelist77' SHOWS CORRECT OPERATION HERE:
[Note that "Skipping namelist" warning messages are not really necessary.]
Skipping namelist "CODVJS": seeking namelist "CODE".
Skipping namelist "CODEONE": seeking namelist "CODE".
Skipping namelist "CODETWO": seeking namelist "CODE".
Improper lower case name -3.
Desired namelist sel 44.
Skipping namelist "CODEX": seeking namelist "CODE".
EOF
--
Summary: Read NAMELIST: reads wrong namelist name
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: slabinski dot victor at usno dot navy dot mil
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33039