HP OpenVMS Systems Documentation
HP Fortran for OpenVMS
This chapter contains information on the following topics:
A format appearing in an input or output (I/O) statement specifies the form of data being transferred and the data conversion (editing) required to achieve that form. The format specified can be explicit or implicit.
The format specification contains edit descriptors, which can be data edit descriptors, control edit descriptors, or string edit descriptors.
List-directed formatting is specified with an asterisk (*); namelist formatting is specified with a namelist group name.
List-directed formatting can be specified for advancing sequential files and internal files. Namelist formatting can be specified only for advancing sequential files.
format-listIs a list of one or more of the following edit descriptors, separated by commas or slashes (/):
Data edit descriptors: I, B, O, Z, F, E, EN, ES, D, G, L, and A. Control edit descriptors: T, TL, TR, X, S, SP, SS, BN, BZ, P, :, /, $, \, and Q . String edit descriptors: H, ' c ' , and "c", where c is a character constant.
- Between a P edit descriptor and an immediately following F, E, EN, ES, D, or G edit descriptor
- Before a slash (/) edit descriptor when the optional repeat specification is not present
- After a slash (/) edit descriptor
- Before or after a colon (:) edit descriptor
A FORMAT statement must be labeled.
Named constants are not permitted in format specifications.
If the associated I/O statement contains an I/O list, the format specification must contain at least one data edit descriptor or the control edit descriptor Q.
Blank characters can precede the initial left parenthesis, and additional blanks can appear anywhere within the format specification. These blanks have no meaning unless they are within a character string edit descriptor.
When a formatted input statement is executed, the setting of the BLANK
specifier (for the relevant logical unit) determines the interpretation
of blanks within the specification. If the BN or BZ edit descriptors
are specified for a formatted input statement, they supersede the
default interpretation of blanks. (For more information on BLANK
defaults, see Section 12.6.4.)
For formatted input, use the comma as an external field separator. The
comma terminates the input of fields (for noncharacter data types) that
are shorter than the number of characters expected. It can also
designate null (zero-length) fields.
For formatted input, use the comma as an external field separator. The comma terminates the input of fields (for noncharacter data types) that are shorter than the number of characters expected. It can also designate null (zero-length) fields.
The first character of a record transmitted to a line printer or terminal is typically used for carriage control; it is not printed. The first character of such a record should be a blank, 0, 1, $, +, or ASCII NUL. Any other character is treated as a blank.
A format specification cannot specify more output characters than the external record can contain. For example, a line printer record cannot contain more than 133 characters, including the carriage control character.
Table 11-1 summarizes the edit descriptors that can be used in format specifications.
|A||A[w]||Transfers character or Hollerith values.||(Section 11.3.6)|
|B||Bw[.m]||Transfers binary values.||(Section 188.8.131.52)|
|BN||BN||Ignores embedded and trailing blanks in a numeric input field.||(Section 184.108.40.206)|
|BZ||BZ||Treats embedded and trailing blanks in a numeric input field as zeros.||(Section 220.127.116.11)|
|D||Dw.d||Transfers real values with D exponents.||(Section 18.104.22.168)|
|E||Ew.d[Ee]||Transfers real values with E exponents.||(Section 22.214.171.124)|
|EN||ENw.d[Ee]||Transfers real values with engineering notation.||(Section 126.96.36.199)|
|ES||ESw.d[Ee]||Transfers real values with scientific notation.||(Section 188.8.131.52)|
|F||Fw.d||Transfers real values with no exponent.||(Section 184.108.40.206)|
|G||Gw.d[Ee]||Transfers values of all intrinsic types.||(Section 220.127.116.11)|
|H||nHch[ch...]||Transfers characters following the H edit descriptor to an output record.||(Section 11.5)|
|I||Iw[.m]||Transfers decimal integer values.||(Section 18.104.22.168)|
|L||Lw||Transfers logical values: on input, transfers characters; on output, transfers T or F.||(Section 11.3.5)|
|O||Ow[.m]||Transfers octal values.||(Section 22.214.171.124)|
|P||kP||Interprets certain real numbers with a specified scale factor.||(Section 11.4.5)|
|Q||Q||Returns the number of characters remaining in an input record.||(Section 11.4.9)|
|S||S||Reinvokes optional plus sign (+) in numeric output fields; counters the action of SP and SS.||(Section 126.96.36.199)|
|SP||SP||Writes optional plus sign (+) into numeric output fields.||(Section 188.8.131.52)|
|SS||SS||Suppresses optional plus sign (+) in numeric output fields.||(Section 184.108.40.206)|
|T||Tn||Tabs to specified position.||(Section 220.127.116.11)|
|TL||TLn||Tabs left the specified number of positions.||(Section 18.104.22.168)|
|TR||TRn||Tabs right the specified number of positions.||(Section 22.214.171.124)|
|X||nX||Skips the specified number of positions.||(Section 126.96.36.199)|
|Z||Zw[.m]||Transfers hexadecimal values.||(Section 188.8.131.52)|
|$||$||Suppresses trailing carriage return during interactive I/O.||(Section 11.4.8)|
|:||:||Terminates format control if there are no more items in the I/O list.||(Section 11.4.7)|
|/||[r]/||Terminates the current record and moves to the next record.||(Section 11.4.6)|
|\||\||Continues the same record; same as $.||(Section 11.4.8)|
|' c ' 1||' c '||Transfers the character literal constant (between the delimiters) to an output record.||(Section 11.5)|
In data transfer I/O statements, a format specifier ([FMT=]format) can be a character expression that is a character array, character array element, or character constant. This type of format is also called a run-time format because it can be constructed or altered during program execution.
The expression must evaluate to a character string whose leading part is a valid format specification (including the enclosing parentheses).
If the expression is a character array element, the format specification must be contained entirely within that element.
If the expression is a character array, the format specification can continue past the first element into subsequent consecutive elements.
If the expression is a character constant delimited by apostrophes, use two consecutive apostrophes ( '' ) to represent an apostrophe character in the format specification; for example:
PRINT '("NUM can''t be a real number")'
Similarly, if the expression is a character constant delimited by quotation marks, use two consecutive quotation marks ("") to represent a quotation mark character in the format specification.
To avoid using consecutive apostrophes or quotation marks, you can put the character constant in an I/O list instead of a format specification, as follows:
PRINT "(A)", "NUM can't be a real number"
The following shows another character format specification:
WRITE (6, '(I12, I4, I12)') I, J, K
In the following example, the format specification changes with each iteration of the DO loop:
SUBROUTINE PRINT(TABLE) REAL TABLE(10,5) CHARACTER*5 FORCHR(0:5), RPAR*1, FBIG, FMED, FSML DATA FORCHR(0),RPAR /'(',')'/ DATA FBIG,FMED,FSML /'F8.2,','F9.4,','F9.6,'/ DO I=1,10 DO J=1,5 IF (TABLE(I,J) .GE. 100.) THEN FORCHR(J) = FBIG ELSE IF (TABLE(I,J) .GT. 0.1) THEN FORCHR(J) = FMED ELSE FORCHR(J) = FSML END IF END DO FORCHR(5)(5:5) = RPAR WRITE (6,FORCHR) (TABLE(I,J), J=1,5) END DO END
The DATA statement assigns a left parenthesis to character array element FORCHR(0), and (for later use) a right parenthesis and three F edit descriptors to character variables.
Next, the proper F edit descriptors are selected for inclusion in the format specification. The selection is based on the magnitude of the individual elements of array TABLE.
A right parenthesis is added to the format specification just before the WRITE statement uses it.
Format specifications stored in arrays are recompiled at run time each time they are used. If a Hollerith or character run-time format is used in a READ statement to read data into the format itself, that data is not copied back into the original array, and the array is unavailable for subsequent use as a run-time format specification.
This section describes the forms for data edit descriptors and the
individual descriptors, themselves. It also describes general rules for
numeric editing and default widths for data edit descriptors.
11.3.1 Forms for Data Edit Descriptors
rIs a repeat specification. The range of r is 1 through 2147483647 (2**31--1). If r is omitted, it is assumed to be 1.
cIs one of the following format codes: I, B, O, Z, F, E, EN, ES, D, G, L, or A.
wIs the total number of digits in the field (the field width). If omitted, the system applies default values (see Section 11.3.7). The range of w is 1 through 2147483647 (2**31--1). For I, B, O, Z, and F, the range can start at zero.
mIs the minimum number of digits that must be in the field (including leading zeros). The range of m is 0 through 32767 (2**15--1).
dIs the number of digits to the right of the decimal point (the significant digits). The range of d is 0 through 32767 (2**15--1).
The number of significant digits is affected if a scale factor is specified for the data edit descriptor.
EIdentifies an exponent field.
eIs the number of digits in the exponent. The range of e is 1 through 32767 (2**15--1).
Fortran 95/90 (and the previous standard) allows the field width to be omitted only for the A descriptor. However, HP Fortran allows the field width to be omitted for any data edit descriptor.
The r, w, m, d, and e must all be positive, unsigned, integer literal constants; or variable format expressions; no kind parameter can be specified. They must not be named constants.
Actual useful ranges for r, w, m, d, and e may be constrained by record sizes (RECL) and the file system.
The data edit descriptors have the following specific forms:
|Integer:||Iw[.m], Bw[.m], Ow[.m], and Zw[.m]|
|Real and complex:||Fw.d, Ew.d[Ee], ENw.d[Ee], ESw.d[Ee], Dw.d, and Gw.d[Ee]|
The d must be specified with F, E, D, and G field descriptors even if d is zero. The decimal point is also required. You must specify both w and d, or omit them both.
20 FORMAT (E12.4,E12.4,E12.4,I5,I5,I5,I5) 20 FORMAT (3E12.4,4I5)
Leading blanks in the external field are ignored. If BLANK= ' NULL ' is in effect (or the BN edit descriptor has been specified) embedded and trailing blanks are ignored; otherwise, they are treated as zeros. An all-blank field is treated as a value of zero.
|Type of Unit or File||Default|
|An explicitly OPENed unit||BLANK= ' NULL '|
|An internal file||BLANK= ' NULL '|
|A preconnected file 1||BLANK= ' NULL '|
A minus sign must precede a negative value in an external field; a plus sign is optional before a positive value.
In input records, constants can include any valid kind parameter. Named constants are not permitted.
If the data field in a record contains fewer than w characters, an input statement will read characters from the next data field in the record. You can prevent this by padding the short field with blanks or zeros, or by using commas to separate the input data. The comma terminates the data field, and can also be used to designate null (zero-length) fields. For more information, see Section 11.3.8.
The field width w must be large enough to include any leading plus or minus sign, and any decimal point or exponent. For example, the field width for an E data edit descriptor must be large enough to contain the following:
A positive or zero value (zero is allowed for I, B, O, Z, and F descriptors) can have a plus sign, depending on which sign edit descriptor is in effect. If a value is negative, the leftmost nonblank character is a minus sign.
If the value is smaller than the field width specified, leading blanks are inserted (the value is right-justified). If the value is too large for the field width specified, the entire output field is filled with asterisks (*).