Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

namelist read for internal file with delim='apostrophe' (?)

Lee_B_1
Beginner
564 Views

There doesn't seem to be any way to set the character delimiter if doing a namelist read from an internal file.  I see from.https://software.intel.com/en-us/node/678700 that the default delimiter is 'none'.  This prevents proper error checking, and seems contrary to Note 10.36 in the J3/10-007 copy of the 2008 standard.  Here's an example:

program abc
  character(len=32) :: fs
  character(len=1) :: xx(8)
  integer :: ios
  namelist /foo/ xx
  fs = "&foo xx = 34 /" ! Assign an integer value to the character variable.
  read(fs, nml=foo, iostat=ios)
  print *, 'xx(1)=', xx(1)
  print *, 'xx(2)=', xx(2)
  print *, 'xx(3)=', xx(3)
  print *, 'ios=', ios
end

Running the example produces this output:

$> ifort --version
ifort (IFORT) 17.0.2 20170213
Copyright (C) 1985-2017 Intel Corporation.  All rights reserved.

$> ifort foo.f90 && ./a.out
 xx(1)=3
 xx(2)=
 xx(3)=
 ios=           0

This is consistent with the Rules for Namelist Reads link given above, but it's sure wierd.

0 Kudos
3 Replies
Steve_Lionel
Honored Contributor III
564 Views

The DELIM= value applies only to output, not input.  On input, character sequences are required to be delimited according to the standard.

As an extension, Intel Fortran allows nondelimited character sequences on input, subject to certain restrictions.  What happens here is this:

The string "34" (no delimiters in your input) is read and is assigned to xx(1). Since xx(1) is only a single character, you get just the 3. The next token is a slash that terminates namelist input, so the remaining elements don't get assigned.

If you wanted the 4 to go to xx(2), you'd have to express it as:

fs = "&foo xx = '3','4' /" 

It is not possible to write delimited character sequences to an internal file using NAMELIST I/O.

0 Kudos
Lee_B_1
Beginner
564 Views

Thank you very much for your reply.  My own posting was not very clear with respect to what I actually would like the compiler to do.  What I would like is for the compiler to give me an error if I send a bare integer to a namelist read for any kind of character input variable.  (What Intel Fortran calls a nondelimited character sequence is what I call a bare integer.)  If I were reading the namelist from an external file, I think (haven't checked) I could set delim='apostrophe' in the OPEN statement.  But no such luck for an internal file.

Anyway, it's just a comment that in this case, the Intel extension seems to do exactly what I don't want, and there doesn't seem to be any way to turn it off.  I would much prefer just following the letter of the standard.  Thank you again for for your attention to my comment.

0 Kudos
Steve_Lionel
Honored Contributor III
564 Views

I understand, but extensions are a fact of life in the Fortran world. While the compiler has an option to complain about certain kinds of extensions, the run-time environment does not. Namelist/list-directed is designed to be exceptionally flexible and is not a good choice when error detection is required. I'll also comment that the design of namelist is such that only namelist output with DELIM='APOSTROPHE' or 'QUOTE' is reliable for reading back in.

0 Kudos
Reply