Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

NAMELIST

brunocalado
Beginner
2,560 Views
[cpp]REAL (KIND=8), ALLOCATABLE	:: A(:)
REAL (KIND=8), ALLOCATABLE	:: B(:)

NAMELIST /vars/ A, B
[/cpp]

I'm trying to read a file with A and B, but when I read a get the folowing message:

forrtl: severe (18): too many values for NAMELIST variable, unit 11, file /test,


How can I use NAMELIST to read allocatable arrays?



0 Kudos
1 Solution
Steven_L_Intel1
Employee
2,560 Views
My guess is that you did not allocate the arrays first. If you are expecting a NAMELIST read to do the allocation, you are mistaken.

C:Projects>type t.f90
REAL(8), ALLOCATABLE, DIMENSION(:) :: A,B

NAMELIST /vars/ A,B

ALLOCATE (A(2), B(3))

A = 1.0
B = 2.0

READ (*,vars)

WRITE (*, vars)

END
C:Projects> ifort /nologo t.f90
C:Projects t.exe
&vars A = 4,B = 5,6 /
&VARS
A = 4.00000000000000 , 1.00000000000000 ,
B = 5.00000000000000 , 6.00000000000000 , 2.00000000000000

/

You will need the latest 11.1 for this, as some earlier versions did not allow ALLOCATABLE arrays in NAMELIST at all.

View solution in original post

0 Kudos
2 Replies
TimP
Honored Contributor III
2,560 Views
With no example of your source code or data file, it is nearly pointless to attempt an answer. From the fragment you have shown, I would say don't try non-standard extensions until you have it working with a standard-compliant example.
0 Kudos
Steven_L_Intel1
Employee
2,561 Views
My guess is that you did not allocate the arrays first. If you are expecting a NAMELIST read to do the allocation, you are mistaken.

C:Projects>type t.f90
REAL(8), ALLOCATABLE, DIMENSION(:) :: A,B

NAMELIST /vars/ A,B

ALLOCATE (A(2), B(3))

A = 1.0
B = 2.0

READ (*,vars)

WRITE (*, vars)

END
C:Projects> ifort /nologo t.f90
C:Projects t.exe
&vars A = 4,B = 5,6 /
&VARS
A = 4.00000000000000 , 1.00000000000000 ,
B = 5.00000000000000 , 6.00000000000000 , 2.00000000000000

/

You will need the latest 11.1 for this, as some earlier versions did not allow ALLOCATABLE arrays in NAMELIST at all.
0 Kudos
Reply