I was asking that variables be ignored that were not in the NAMELIST
group; not that all the variables in a program unit be exposed; but that
would indeed be a terrific option as well!
I can understand how difficult that would be in a compiled language but
it must be feasible (perhaps at a very high performance cost) as debuggers
allow it; as well as changing values via expressions. Allowing expressions
in NAMELIST input would be another great future; as well as conditionals
that I think would be another game-changer for NAMELIST input.
But I was just suggest that if I had a number of programs that already
read and shared NAMELIST files having GRP2 in them and I then changed on
program to have a new variable “N” that I would not have to change all the
programs to have N to continue using the same files.
The work-around in some cases is to put N into a new NAMELIST group so the
file has two groups instead of one in it, which is less than ideal and at
least in the past used to have problems with some compilers that did not
support multi-group and multi-case NAMELIST files.
An artificial single-file program that illustrates what I wish would run
successfully:
program testit
implicit none
real x; namelist /grp1/ x; namelist /grp2/ x
real y; namelist /grp1/ y; namelist /grp2/ y
integer n; namelist /grp1/ n
integer :: io, iostat
character(len=256) :: iomsg
x = tiny(0.0)
y = huge(0.0)
n = digits(0.0)
open (newunit=io, &
& status='scratch', &
& form='formatted', &
& access='sequential', &
& iostat=iostat, &
& iomsg=iomsg, &
& action='readwrite')
if(iostat.ne.0)then
write(*,'(*(g0))')'<ERROR>',iomsg
stop 1
endif
write (io, nml=grp1)
write (*, nml=grp1)
rewind (io, iostat=iostat)
x=-0.0
y=-0.0
write (*, nml=grp1)
!read (io, nml=grp1) ! this would work
read (io, nml=grp2) ! file has x,y,z values but just want to read x,y
write (*, nml=grp1)
end program testit
so the suggestion for allow_extra = .true.
would do what I want; albeit I would probably use it with all NAMELIST group I/O!