Issue with namelist read

I’m facing a problem with a GPU port related to a reading of a buffer with namelist data. I made a simple example to point to the problem. This simple code fails on pgfortran 20.7

integer :: i,j, a, b
CHARACTER(LEN=132)    :: buff
namelist/nammpp/ i,j
namelist/namctl/ a,b

buff=' /  & nammpp i = 10 j =  4 $ / & namctl a = 5 b = 3 / '

print *, buff
read(buff,nml=nammpp)
print *, i
read(buff,nml=namctl)
print *, a,b
end

pgfortran sample.f90 ; ./a.out
/ & nammpp i = 10 j = 4 $ / & namctl a = 5 b = 3 /
FIO-F-228/namelist read/internal file/end of file reached without finding group.
In source file open1.f90, at line number 9

ifort sample.f90 ; ./a.out
/ & nammpp i = 10 j = 4 $ / & namctl a = 5 b = 3 /
10 4
5 3

After consulting with our Fortran folks here, we believe the program is not standard compliant given:

Fortran 2018 13.11.3.2 paragraph 4: “Successive namelist records are read by namelist input until a slash is encountered; the remainder of the record is ignored.”

Also since each read would start from the beginning of ‘buff’, ifort is presumably skipping over leading characters in the internal input until they arrive at the namelist group name that matches the READ statement. Though we don’t see any language in the standards that would sanction that behavior, if in fact that’s what they’re doing.

Note that gfortran 10.1 does not match ifort either:

% gfortran --version
GNU Fortran (GCC) 10.1.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

% gfortran test.f90 ; a.out
  /  & nammpp i = 10 j =  4 $ / & namctl a = 5 b = 3 /
  1914315712        5295
  1914317076        5295

However, I have added an RFE (TPR #29067) to see if we can support what appears to be an ifort extension.

-Mat

Thanks MatColgrove,
I made a work around, but it is not the ideal. The citation you made is applied to a namelist, i.e:

read(buff,nml=namctl)

should read from “& namctl” until the first “/”. In my view, the ifort is implementing the standard.

integer :: i,j, a, b, pos
CHARACTER(LEN=80) :: buff
namelist/nammpp/ i,j
namelist/namctl/ a,b

buff=’ / &nammpp i = 10 j = 4 $ / &namctl a = 5 b = 3 / ’
pos=index(buff,’&nammpp’)
read(buff(pos:),nammpp)
print *, i, j
pos=index(buff,’&namctl’)
read(buff(pos:),namctl)
print *, a,b
end

Ok, though our engineers seem to disagree. Do you have any pointers to the Fortran standard which supports your assertion that I can send them?

I review the Fortran 2018 Interpretation Document, you guys seem right. Actually, I did not see a citation to multiple groups in the same namelist. This is implemented externally on PGI, GNU, XLF, and Ifort.

$ cat input.txt
&nammpp
i = 10
j = 4
/
&namctl
a = 5
b = 3
/

$cat open5.f90
integer :: i,j, a, b
namelist/nammpp/ i,j
namelist/namctl/ a,b

open(10, FILE=‘input.txt’)
read(10,nammpp)
print *, i, j
read(10,namctl)
print *, a,b
end

$ ./a.out
10 4
5 3

But with an input.txt without newlines, only ifort gives the desired result.