To: J3 J3/19-156 From: Steve Lionel Subject: Control of leading zero in formatted numeric output Date: 2019-February-14 Reference: 18-007r1, 18-268, 18-120r3, 18-010 Introduction ------------ At meeting 215, J3 agreed to add "leading zero format control" to its work list for Fortran 202x. Please see 18-268 from meeting 217 for additional background. Requirements ------------ - Add control edit descriptors, analogous to the SS, SP and S edit descriptors, allowing the programmer to specify whether a leading zero is to appear in output for the F, E, D and G formats in the cases where it is currently optional. The requirement of the leading zero when otherwise no digits would appear is to remain. As with the existing S control descriptor, one of the new descriptors selects the implementation-defined behavior, which remains the default. - Continuing the analogy with SS, SP and S, and the SIGN= OPEN/INQUIRE specifier, add a new specifier to OPEN and INQUIRE to allow specification or inquiry of the current mode. Like SIGN=, this is to be a "changeable mode" (12.5.2p1). List-directed and namelist- directed output are to use the current "leading zero" mode. Specification ------------- 1. Add the following control edit descriptors: LZS, LZP, LZ. The LZS, LZP, and LZ edit descriptors temporarily change (12.5.2) the leading zero mode for the connection. The edit descriptors LZS, LZP, and LZ set the leading zero mode corresponding to the LEADING_ZERO= specifier values SUPPRESS, PRINT, and PROCESSOR_DEFINED, respectively. The leading zero mode controls optional leading zero characters in numeric output fields. When the leading zero mode is PRINT, the processor shall produce a leading zero in any position that normally contains an optional leading zero. When the leading zero mode is SUPPRESS, the processor shall not produce a leading zero in such positions. When the leading zero mode is PROCESSOR_DEFINED, the processor has the option of producing a leading zero or not in such positions, subject to 13.7.2(5) [rule about filling field with asterisks and optional characters]. The LZS, LZP, and LZ edit descriptors affect only F and E editing during the execution of an output statement. The LZS, LZP, and LZ edit descriptors have no effect during the execution of an input statement. 2. Add the data transfer statement specifier LEADING_ZERO The specifier value shall evaluate to PRINT, SUPPRESS, or PROCESSOR_DEFINED. The LEADING_ZERO= specifier temporarily changes (12.5.2) the leading zero mode for the connection. If the specifier is omitted, the mode is not changed. 3. Add the OPEN specifier LEADING_ZERO=. The specifier value shall evaluate to one of PRINT, SUPPRESS, or PROCESSOR_DEFINED. The LEADING_ZERO= specifier is permitted only for a connection for formatted input/output. It specifies the leading zero mode for this connection. It is a changeable mode (12.5.2). If this specifier is omitted in an OPEN statement that initiates a connection, the default value is PROCESSOR_DEFINED. 4. Add the INQUIRE specifier LEADING_ZERO to retrieve the leading zero mode for a connected unit. Straw Vote ---------- There are several plausible choices for the "P" keyword value. For SIGN=, the word is PLUS which makes no sense here. What is the committee's preference? Choosing a different initial letter may hinder understanding of the control edit descriptors. - PRESENT - PRINT - PROVIDE - PRODUCE (this is the word used in the normative text for SS/SP/S) - something else Edits to 18-007r1 ----------------- {add remark to Introduction in the bullet item for Input/Output} [xiii] add: "The LEADING_ZERO specifier in the OPEN and INQUIRE statements, and the LZP, LZS and LZ control edit descriptors, provide control of optional leading zeros during formatted output." {add LEADING_ZERO to the OPEN statement] [220:10+, 12.5.6.2, Syntax of the OPEN statement] add after IOSTAT=: " or LEADING_ZERO = scalar-default-char-expr " [222:7+, 12.5.6.11+] add: "12.5.6.11+ LEADING_ZERO= specifier in the OPEN statement The scalar-default-char-expr shall evaluate to one of PRINT, SUPPRESS, or PROCESSOR_DEFINED. The LEADING_ZERO= specifier is permitted only for a connection for formatted input/output. It specifies the leading zero mode (13.8.3+, 12.6.2.14) for this connection. It is a changeable mode (12.5.2). If this specifier is omitted in an OPEN statement that initiates a connection, the default value is PROCESSOR_DEFINED. " {add LEADING_ZERO to data transfer statement control list} [225:17+, 12.6.2.1p1, Control information list > Syntax)] add after IOSTAT=: " or LEADING_ZERO = scalar-default-char-expr " {Prohibit LEADING_ZERO= in a READ statement} [225:28, 12.6.2.1p1] In C1212, replace "A DELIM= or SIGN= specifier" with "A DELIM=, LEADING_ZERO=, or SIGN= specifier" {Require format or namelist if LEADING_ZERO= specified} [226:18, 12.6.2.1p1] In C1227, insert ", LEADING_ZERO=" after "BLANK=" {Specify limits on specifier value interpretation.} [226:27, 12.6.2.1p4] Insert ", LEADING_ZERO=" after "DELIM=" {Add description of specifier for data transfer statement} [228:30+, 12.6.2.9+] Insert a new subsection: "12.6.2.9+ LEADING_ZERO= specifier in a data transfer statement The scalar-default-char-expr shall evaluate to PRINT, SUPPRESS, or PROCESSOR_DEFINED. The LEADING_ZERO= specifier temporarily changes (12.5.2) the leading zero mode (13.8.3+, 12.5.6.11+) for the connection. If the specifier is omitted, the mode is not changed. " {Add LEADING_ZERO= to INQUIRE} [247:10+, 12.10.2.1, Inquiry specifiers > Syntax] add after IOSTAT=: " or LEADING_ZERO = scalar-default-char-expr " [249:16+, 12.10.2.14+] after ID=, insert a new subsection: "12.10.2.14+ LEADING_ZERO= specifier in the INQUIRE statement The scalar-default-char-variable in the LEADING_ZERO= specifier is assigned the value PRINT, SUPPRESS, or PROCESSOR_DEFINED, corresponding to the leading zero mode in effect for a connection for formatted input/output. If there is no connection, or if the connection is not for formatted input/output, the scalar-default-char-variable is assigned the value UNDEFINED." {Add LZP, LZS, LZ edit descriptors} {The editor is welcome to rearrange the order of specifiers if desired - I am not able to discern the pattern of the current order.} [258:27+, 13.3.2p2, Edit descriptors], after "or :" insert: " or leading-zero-edit-desc" [259:0+, 13.3.2p3] before R1317 (sign-edit-desc) insert: "R1316+ leading-zero-edit-desc is LZS or LZP or LZ" [259:14, 13.3.2p4] In the list of edit descriptors, insert ", LZS, LZP, LZ" [272:29+, 13.8.3+] After the subsection on colon editing, insert the new subsection: "13.8.3+ LZS, LZP and LZ editing The LZS, LZP, and LZ edit descriptors temporarily change (12.5.2) the leading zero mode (12.5.6.11+, 12.6.2.9+) for the connection. The edit descriptors LZS, LZP, and LZ set the leading zero mode corresponding to the LEADING_ZERO= specifier values SUPPRESS, PRINT, and PROCESSOR_DEFINED, respectively. The leading zero mode controls optional leading zero characters in numeric output fields. When the leading zero mode is PRINT, the processor shall produce a leading zero in any position that normally contains an optional leading zero. When the leading zero mode is SUPPRESS, the processor shall not produce a leading zero in such positions. When the leading zero mode is PROCESSOR_DEFINED, the processor has the option of producing a leading zero or not in such positions, subject to 13.7.2(5) [rule about filling field with asterisks and optional characters]. The LZS, LZP, and LZ edit descriptors affect only F and E editing during the execution of an output statement. The LZS, LZP, and LZ edit descriptors have no effect during the execution of an input statement." ==END==