erom
Joined: 26 Oct 2009 Posts: 4 Location: Los Angeles, CA. USA
|
Posted: Mon Jun 14, 2010 8:25 pm Post subject: NAMELIST in a MODULE error |
|
|
On an intel microchannel quad cpu 64 bit windows 7
The last downlodable version of SilverFrost Fortran,
- which installed flawless from default administrator protected 32 bit,
builds, debugs, and runs all ok here.
The NAMELIST statement works ok in a MAIN program, the first
example program; The NAMELIST statement does not seem to work in a
MODULE, the second example. .n.g. why ...
Metcalf and Reid seem to say that all module declarations are
replicated in to the program unit/s that USE the module.
PROGRAM NAMELIST_TEST
IMPLICIT NONE
INTEGER :: n
REAL :: x
CHARACTER(len=32) :: word001
NAMELIST /dphotdef/ n , x, word001 ! Declare a namelist
WRITE(*,*) 'Start the namelist_test'
WRITE(*,*) 'Read and print the namelist'
WRITE(*,*)
OPEN ( unit =3, file = 'dphotdefval.dat' )
READ(unit=3,NML=dphotdef) ! Read the namelist
WRITE(*,*)
WRITE(*,NML=dphotdef)
WRITE(*,*)
WRITE(*,*) 'done namelist_test'
END PROGRAM NAMELIST_TEST
A text file named dphotdefval.dat exists in the working directory and
contains:
! test namelist. A comment line
!
&DPHOTDEF ! do not edit the & in this line
n=1, ! integer. an inline comment. comma can be deleted optional
x=1.234567890123456789e000, ! real
word001="abc namelist" ! charter
/ ! do not edit the / in this line
! trailing comment line/s
!
On execution the test returns:
Start the namelist_test
Read and print the namelist
&DPHOTDEF
N = 1
X = 1.23457
WORD001 = 'abc namelist '
/
done namelist_test
Press RETURN to close window . . .
Ok fine so far.
Now the build consists of 2 program units, a MAIN and a MODULE
PROGRAM NAMELIST_TEST
USE namelistmodule
CALL namelistvars
END PROGRAM NAMELIST_TEST
MODULE namelistmodule
IMPLICIT NONE
NAMELIST /dphotdef/ n , x, word001
INTEGER :: n
REAL :: x
CHARACTER(len=32) :: word001
CONTAINS
SUBROUTINE namelistvars
OPEN ( unit=10, file = 'dphotdefval.dat' )
READ(unit=10, NML=dphotdef)
CLOSE(unit=10)
WRITE(*,NML=dphotdef)
END SUBROUTINE namelistvars
END MODULE namelistmodule
Builds ok,
execution returns :
Run-time Error
*** Error 204, Invalid identifier in namelist input group
00401000 NAMELISTMODULE!NAMELISTVARS [+00b7]
00401180 main [+0042]
This last example runs just fine on Intel Linux FORTRAN 11.1-072
Last edited by erom on Tue Jun 15, 2010 8:27 pm; edited 2 times in total |
|