urba...@comcast.net
unread,Oct 15, 2019, 10:15:53 PM10/15/19You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
I had questions on whether a NAMELIST could be declared public in a module
and if so, how it would be referred and extended. The following program
runs with gfortran 7.4.0 and lets the program extend the namelist but the
module does not see the extension. According to the standard should this build?
If so, what is the expected scope of the extensions? Should a NAMELIST be allowed to be public? If so, should it be able to be extended by another unit, at least in the scope of the unit? That is, is this behavior standard?
I would be interested in seeing what other compilers produce.
Notice how the main program extended the NAMELIST but the contained procedures
superseded it, which seems contradictory.
module tryit
implicit none
!!private
logical :: help=.false.,version=.false.
namelist /args/ help
namelist /args/ version
public help, version, args, get_args, get_args2
contains
subroutine get_args()
write(*,nml=args)
end subroutine get_args
subroutine get_args2()
integer :: added_in_module=2
namelist /args/ added_in_module
write(*,nml=args)
end subroutine get_args2
end module tryit
program demo_get_namelist
use tryit, only : get_args, help, version, args, get_args2
implicit none
! extend namelist?
real :: x=111.1, y=222.2, z=333.3
namelist /args/ x,y,z
write(*,*)'from the program'
write(*,nml=args)
call contained()
write(*,*)'from the program after contained'
write(*,nml=args)
write(*,*)'from the module'
call get_args()
write(*,*)'from the module with /ARGS/ declared'
call get_args2()
contains
subroutine contained
integer :: added =1
namelist /args/ added
write(*,*)'from contained'
write(*,nml=args)
end subroutine contained
end program demo_get_namelist
OUTPUT:
from the program
&ARGS
HELP=F,
VERSION=F,
X= 111.099998 ,
Y= 222.199997 ,
Z= 333.299988 ,
/
from contained
&ARGS
ADDED= 1,
/
from the program after contained
&ARGS
HELP=F,
VERSION=F,
X= 111.099998 ,
Y= 222.199997 ,
Z= 333.299988 ,
/
from the module
&ARGS
HELP=F,
VERSION=F,
/
from the module with /ARGS/ declared
&ARGS
ADDED_IN_MODULE= 2,
/