Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

namelist and modules and scope

231 views
Skip to first unread message

urba...@comcast.net

unread,
Oct 15, 2019, 10:15:53 PM10/15/19
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,
/


FortranFan

unread,
Oct 15, 2019, 11:01:30 PM10/15/19
to
On Tuesday, October 15, 2019 at 10:15:53 PM UTC-4, urba...@comcast.net wrote:

>
> I would be interested in seeing what other compilers produce.
> ..


The code shown in the original post is non-conforming, it makes use of a GNU extension.

The standard for Fortran via constraint "C8103 (R868) The namelist-group-name shall not be a name accessed by use association" does not allow the following and requires processors to issue a diagnostic:

program demo_get_namelist
use tryit, only : .. args ..
..
namelist /args/ x,y,z


The use of the gfortran compiler option -std=xxx where xxx is not 'GNU' nor 'legacy' might be more revealing for OP: https://gcc.gnu.org/onlinedocs/gfortran/Fortran-Dialect-Options.html#Fortran-Dialect-Options
0 new messages