Error reading namelist

Error reading namelist


I have a bizarre error which is shown by the skeleton code below.

Basically, I have a character variable which I have placed with a namelist. I initilaise the string and write the namelist to a file. I rewind the file and read the namelist. It works fine if the length of the character string is 122 but if I put it to 123 (as in the code) it fails with IOSTAT=18 which is 'too many values for NAMELIST variable'.

I am using Intel Fortran XE in VS2010

In the full program the character string will be much longer so I did some trial and error to see what was the critical point and as far as i know, 122 has no significance whatsoever.

I have tried setting CARRIAGECONTROL='NONE' and BLOCKSIZE=123' on the OPEN statement but doesn't make any difference.


Code also works fine with gfortran.

Any ideas?


! Program to test namelist read


CHARACTER(LEN=123) :: CString
CHARACTER(LEN=150) :: Message





DO I=1,123
CString(I:I) = 'A'




write(6,*) 'ios ',ios
if(ios /= 0) write(6,*) 'Message: ',Message
write(6,*) CString


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

Did you look at the file produced ( and see that it looks as you expect?

Also, did you try closing and reopening the file (just to make sure everything is written).

Yes, the file is as expected. It appears that the input is being truncated at 122 characters.

My suspicion is that there is some kind of record length parameter which I need to override.

The standard says

NOTE 10.40
Namelist output records produced with a DELIM= specifier with a value of NONE and which contain a
character sequence might not be acceptable as namelist input records.

The problem here is that the default for NAMELIST and list-directed output is DELIM='NONE' which means that character strings are not delimited. With both kinds of formatting, it is processor-dependent on where any line breaks occur, and when reading in a long string that spans records, an undelimited string won't be read correctly.

The fix here is to add DELIM="QUOTE" (or "APOSTROPHE") to the OPEN of unit 10.

Retired 12/31/2016

Thanks Steve, you're a star. I guessed it would be something like that but couldn't work out what.


Leave a Comment

Please sign in to add a comment. Not a member? Join today