-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Currently there is a somewhat paradoxical issue related to namelist support, where a namelist produced by WRITE()
and using the default DELIM
value of None
does not conform to the namelist specification when it contains a character array.
A namelist as described in F2018 requires that all character arrays be delimited with single or double quotes (13.11.3.3 p7):
When the next effective item is of type character, the input form consists of a sequence of zero or more rep-chars whose kind type parameter is implied by the kind of the corresponding list item, delimited by apostrophes or quotes.
However, the default value of DELIM=None
will produce a namelist without delimiters (i.e. space-delimited). From 13.11.4.2 p1:
Values in namelist output records are edited as for list-directed output (13.10.4).
If we go back to 13.10.4, it highlights three forms of character array output based on DELIM, with NONE being the default. In other words, the default is incompatible with the namelist format.
Note 1 of 13.11.4.2 clarifies this point:
Namelist output records produced with a DELIM= specifier with a value of NONE and which contain acharacter sequence might not be acceptable as namelist input records.
In practice, this is often not a problem, and a robust parser can usually resolve the non-delimited strings if whitespace can act as a delimiter. But it becomes a more problematic, if not impossible, if the string contains a lexical token, such as &
, =
, or /
. For example, strings containing paths are almost guaranteed to cause problems.
To summarize, a namelist containing character arrays when written with DELIM=NONE
does not conform to the namelist specification, and a compiler can not read its own namelist if DELIM
is not set to either QUOTE
or APOSTROPHE
.
Currently, gfortran ignores this requirement and defaults to using quote ("
) delimiters. Intel Fortran does not, and will produce a namelist that it cannot read.
While this particular problem can be avoided by requiring the programmer to use DELIM
for all namelist output (e.g. DELIM='QUOTE'
), it will inevitably cause problems for the less experience developer, and could lead to output with errors.
I'd like to propose that this problem be address in some way. Two possible solutions:
-
Require that that
DELIM
be set for a namelist input, andDELIM='QUOTE'
orDELIM=
APOSTROPHE) when writing a namelist. If
WRITEis called with a
NMLargument and without
DELIM`, then it is an error. -
Follow GFortran and silently use
DELIM='QUOTE'
(orAPOSTROPHE
) when the output is a namelist.
There may be others possible solutions.
This is not a problem that needs to be solved, since users could just be trained to use DELIM
when writing namelists. But I believe that this change would be an improvement in usability and would help to avoid future errors.
This was prompted by the following discussion on the Intel forums:
https://software.intel.com/en-us/forums/intel-fortran-compiler/topic/831685#comment-1947391