help reading a namelist

help reading a namelist

Here is the test.in input file (UNIT=1) the code is supposed to read in:
$CONS
NPOINT= 23
ABC(1)= 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8,
2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8
U(1)= 0.0 0.05 0.10 0.35 0.65 1.00 1.50 2.00 2.75 3.40 4.25 5.50, 6.30 7.60 9.00 10.60 12.50 14.50 17.00 20.00 23.75 29.25 39.75
G= 34.0
GSL= -36.3
GFSL= -48.5
A3DB= 3.38
e3db= 3.38
B6= 41.0
B9= 41.0
B10(1)= 8*41.0
$END

Here is the function that calls the namelist:
SUBROUTINE SETUP(G)
NAMELIST /CONS/NPOINT,ABC,U,G,GSL,GFSL,A3DB,E3DB,B6,B9,B10
COMMON /ANTENNA/NPOINT,ABCX,UX,B5,B6X,B8,B9X,B10X,GSL,GFSL
COMMON /KLOPT2/AVG,GSL2,GFSL2,A3DB,E3DB
DIMENSION ABC(35),ABCX(35),U(35),UX(35),B10(9),B10X(9)

READ(1,CONS)

The read statement causes an error but the (1,CONS) seems right, the UNIT = 1 and CONS is the namelist.

Can anyone help me figure out why this is causing an error?
The error says:
end-of-file during read, UNIT 1, file test.in

13 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Try starting all the lines in column 2. NAMELIST is a bit funky this way, column 1 is for carriage control - most of the time!

Steve

Steve

Thanks for the suggestion but it didn't seem to help.
I also tried to change the command

READ(1,NML=CONS)

It also didn't seem to do anything. I also replaced the
$END in the namelist file with a / like the examples have but no change. There is another line in the code that has the following for another namelist:

READ(1,NML=DATA1,END=1000)

I don't know what the END=1000 does though?

I don't see anything obviously wrong - the $CONS/$END syntax is non-standard, but supported. The error is indicating that it can't find the CONS namelist specification in your input file. The END=1000 says to branch to line 1000 if it gets to an end-of-file - perhaps you do need that to say what happens if there's no more groups in the file?

Steve

Steve

Hi,
I'd read the manual again. I have assumed that A(1)=999 would read in only one value, A(1), and not the entire array as dimensioned. If this works for you as you have written, I also observe that the repeat count for B(1) is 8, but B is dimensioned 9 in your example. That might hit the end-of-file before B(9) is read, as requested.
Keith

I still haven't found a solution. Thanks for all the suggestions here is what I have right now starting with the .in file that has the namelist (I changed the B10(1) to B10(8) but it doesn't seem right and spaced it in 2). And the READ statement:

$CONS
NPOINT= 23
ABC(1)= 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8,
2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8
U(1)= 0.0 0.05 0.10 0.35 0.65 1.00 1.50 2.00 2.75 3.40
4.25 5.50,
6.30 7.60 9.00 10.60 12.50 14.50 17.00 20.00 23.75
29.25 39.75
G= 34.0
GSL= -36.3
GFSL= -48.5
A3DB= 3.38
E3DB= 3.38
B6= 41.0
B9= 41.0
B10(8)= 8*41.0
/

SUBROUTINE SETUP(G)
NAMELIST /CONS/NPOINT,ABC,U,G,GSL,GFSL,A3DB,E3DB,B6,B9,B10
COMMON /ANTENNA/NPOINT,ABCX,UX,B5,B6X,B8,B9X,B10X,GSL,GFSL
COMMON /KLOPT2/AVG,GSL2,GFSL2,A3DB,E3DB
DIMENSION ABC(23),ABCX(23),U(23),UX(23),B10(8),B10X(8)

READ(1,NML=CONS)

I changed the dimension of ABC, ABCX, U, UX, B10 & B10X to the number of points in the namelist and used kdkeefer's suggestion for B10 to change to 8?
If you know of any simple readlist examples I can stick into this file just to see if it is reading the right thing that would be great anything simple would work that I could cut and paste right above this line of code.

Since you haven't provided a complete program, I took what you posted and built a program around it, as follows:

program test
real g

open (unit=1,file='in.dat',form='formatted')

call setup(g)
end program test

SUBROUTINE SETUP(G)
NAMELIST /CONS/NPOINT,ABC,U,G,GSL,GFSL,A3DB,E3DB,B6,B9,B10
COMMON /ANTENNA/NPOINT,ABCX,UX,B5,B6X,B8,B9X,B10X,GSL,GFSL
COMMON /KLOPT2/AVG,GSL2,GFSL2,A3DB,E3DB
DIMENSION ABC(23),ABCX(23),U(23),UX(23),B10(8),B10X(8)

READ(1,NML=CONS)
write (*,nml=cons)
return
end subroutine setup

I then took your data file and created it as in.dat, built with CVF 6.6B and ran it.

Initially, it complained "too many values for NAMELIST variable", which is true - that B10(8) really should be B10(1) - you're reading values into elements 1-8. If I made that change, it ran fine.

So.. It looks as if your problem is in code you haven't shown us.

Steve

Steve

THANK YOU ALL

first: form='formatted' did something that I don't understand but it works.
second: I rewrote my test.in file and it helped.

So for now I am done. I wish VF had a better help menu on the namelist section.

Thanks again.

FORM='FORMATTED' wouldn't have changed anything.

You say you "rewrote" the input file - I suspect that was the actual fix, though the one you posted worked fine for me.

Steve

Steve

When I last used NAMELIST (years ago) I found that the data sets were not portable.
For example, one machine's compiler required the use of '$' and another objected and
required a '&' as a prefix to the NAMELIST name and the END statement.

I concur with the 'start in column 2' recommendation.
But I am also curious to see that the individual entries
do not have to be seperated by a comma, ',',
as well as not requiring a comma between data for each NAMELIST variable.

When I used NAMELIST, the number of data values HAD to match the dimension
of the variable in the NAMELIST
definition, so that a 200-element array had to be filled like

$name
 ARRAY1=1,2,198*0,
 ARRAY2=100*0,3,4,98*0,
$END

NAMELIST appears to have changed over time, but may still be implementation-dependent,
so that perhaps now my NAMELIST data files will not be accepted and will crash. This would be a real pain, as I also
output data (using variable formats)
in the form of NAMELIST data files, after
changing/adding data values!
IMHO,I think you need to be aware that your NAMELIST
data may still have some portability problems.

Before F90, NAMELIST was an extension, but was usually implemented as starting with $GROUPNAME and ending with $END. F90 standardized it so that a group started with &GROUPNAME and ended with / (not &END). Nowadays, I think the standard form is the most portable.

The column 1 or 2 issue is muddy in the standard - if you stick to column 2 and don't continue strings across lines, you'll be fine everywhere.

Within the group, list-directed input rules apply, so spaces as separators are fine.

Steve

Steve

Thanks, Steve, for your comments.
Is it not also still the case that with NAMELIST output,
EVERY element of an array is output seperately, so that you regularly finish up with large data files?
I found it annoying that an array with a few non-zero elements could be input as follows

$name
array1=1,2,3,97*0
/

would be output, after making changes, as

$name
array1 =  10,  20,  30,  0,  50,  0,  0,
(and so on until every element has been output)
/

It is not necessarily the case. As in list-directed output, the "processor" (the Fortran run-time environment) has the option of using repeat counts for repeated values. CVF does., but Intel Fortran doesn't today (it will in the future). For example, I built the following:

integer array(10)
namelist /foo/ array
array = 0
array(1) = 1
write (*,foo)
end

And got this output with CVF:

 &FOO
 ARRAY   =           1, 9*0
 /

Steve

Steve

Login to leave a comment.