Here's test code:
program testcase
implicit none
integer :: ios, lu
type derived
integer :: a
end type derived
type (derived) :: d
namelist /test/ d
lu = 3
open (lu, file = 'test.dat', status='old', iostat=ios)
read (lu, nml = test, iostat=ios)
if (ios /= 0) then
write (*, *) 'error!'
else
write (*, *) 'good!', d % a
endif
end program testcase
This program reads an input file test.dat which contains a namelist for test whose type is a derived type derived.
When I try next content for test.dat it works fine(it prints good! 7):
&test
d%a = 7
/
However, with next content, I get an error:
&test
d % a = 7
/
Equal sign must follow namelist object name d
What's different is the whitespaces around % sign for component access in derived type.
I've tested with GNU Fortran(gfortran) 5.3.0. I also heard from my colleague that same problem occurred with latest Intel Fortran compiler. He also insisted that the old version of Intel Fortran compiler worked fine with both cases.
Is this behavior is normal? That is, does the standard forbid whitespaces around % in namelist input file, while whitespaces around % are allowed in source code?
Or, is this a bug of compiler or implementation of standard library?
gfortranv4.4.7 gives an error if there are spaces around the%character, whereas intel fortran compiler (v12.1.3 and v16.0.3) correctly read the namelist. - chw21