Skip to content

Commit 473c42a

Browse files
authored
Merge pull request #94 from marshallward/namelist_delim
Namelist delimiter proposal
2 parents c208668 + 4b87ead commit 473c42a

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
:To: J3
2+
:From: Marshall Ward
3+
:Subject: Require delimiters for character arrays in namelist output
4+
:Date: 19 November 2019
5+
6+
.. sectnum::
7+
8+
Proposal for Fortran Standard: 202y
9+
10+
11+
Introduction
12+
============
13+
14+
According to the current standard, a WRITE statement can write a namelist file
15+
that does not conform to the namelist specification. This happens when the
16+
namelist group contains a character array and the DELIM specifier has a value
17+
of NONE. In particular, this is the default behavior of a WRITE statement
18+
whose input is a namelist.
19+
20+
Our proposal is to require delimiters when using WRITE to write a namelist to a
21+
file, by either requiring a value of DELIM which is namelist-compliant, or by
22+
overriding a value of NONE when the input is a namelist.
23+
24+
25+
Motivation
26+
==========
27+
28+
The namelist format is described in section 13.11 of the standard, and
29+
13.11.3.3p7 requires that character arrays in namelist groups must be delimited
30+
with single or double quotes.
31+
32+
When the next effective item is of type character, the input form consists
33+
of a sequence of zero or more rep-chars whose kind type parameter is implied
34+
by the kind of the corresponding list item, delimited by apostrophes or
35+
quotes.
36+
37+
Any namelist whose character arrays are non-delimited is non-conformant. Any
38+
parsing of this output is therefore considered to be unformatted, and the
39+
interpretation is at the discretion of the interpreter.
40+
41+
Without delimiters, many character arrays become unparseable. If a character
42+
array contains any lexical tokens, then it is likely that non-delimited values
43+
will be misinterpreted as part of the namelist object structure. For example,
44+
any character array containing a slash ``/`` may abruptly terminate the
45+
current namelist group. Note 13.36 also recognizes the challenges of
46+
distinguishing between non-delimited character arrays and object names.
47+
48+
The standard acknowledges the limitations of non-delimited character array
49+
parsing, and specifically directs the interpreter to ignore the value of DELIM
50+
when reading a namelist (12.5.6.8).
51+
52+
The scalar-default-char-expr shall evaluate to APOSTROPHE, QUOTE, or NONE.
53+
The DELIM= specifier is permitted only for a connection for formatted
54+
input/output. It specifies the delimiter mode (12.6.2.8) for list-directed
55+
(13.10.4) and namelist (13.11.4.2) output for the connection. This mode has
56+
no effect on input.
57+
58+
However, despite the acknowledgement of the issues above, the default behavior
59+
of a WRITE command is to produce non-delimited character arrays. From
60+
13.11.4.2p1,
61+
62+
Values in namelist output records are edited as for list-directed output
63+
(13.10.4).
64+
65+
This is done despite the fact that list-directed output follows different I/O
66+
rules for character arrays. From 13.10.3.1p7 (my emphasis),
67+
68+
When the next effective item is of type character, the input form consists
69+
of a **possibly** delimited sequence of zero or more rep-chars whose kind
70+
type parameter is implied by the kind of the effective item.
71+
72+
The namelist specification 13.11.3.3p7 deliberately omits "possibly" from its
73+
description.
74+
75+
In other words, list-directed output permits non-delimited arrays, whereas
76+
namelists do not. In addition, the default value of DELIM is to revert back to
77+
its value in the OPEN call. From 12.5.6.8p1,
78+
79+
If this specifier is omitted in an OPEN statement that initiates a
80+
connection, the default value is NONE.
81+
82+
The default behavior of a WRITE call using namelist data is therefore to
83+
produce an output which is non-conformant with the namelist standard.
84+
85+
86+
Proposal
87+
========
88+
89+
We propose one of the following additions to the *io-control-spec-list*,
90+
detailed in 12.6.2.1.
91+
92+
A. If *namelist-group-name* appears, then a DELIM= specifier with the value
93+
of either APOSTROPHE or QUOTE shall also appear.
94+
95+
Option A would take the current recommended advice to always use DELIM when
96+
writing namelist output and turn it into an explicit rule. However, it would
97+
cause currently compliant code to be non-compliant, and may require
98+
modifications if used by future interpreters.
99+
100+
B. If *namelist-group-name* appears and a DELIM= specifier has the value of
101+
NONE, then this value is ignored and the data transfer uses a value of
102+
APOSTROPHE.
103+
104+
Option B would change the behavior of existing standard-compliant interpreters,
105+
in that non-delimited character arrays would be replaced with
106+
apostrophe-delimited arrays. But existing source code would otherwise remain
107+
compliant and continue to compile on both older and newer interpreters.

0 commit comments

Comments
 (0)