Format Descriptors [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation
HP FORTRAN 77/iX Reference
Format Descriptors
The descriptors in a format specification must be separated by a comma
except before and after a slash (/) edit descriptor, a colon (:) edit
descriptor, or between a scaling (P) edit descriptor and an immediately
following D, E, F, or G edit descriptor. For example, if a slash
descriptor is used to indicate a new line of output or a new record on
input, the comma that would separate the descriptors is not necessary.
The specification:
3I,F4.0,/I5,F12.6
is equivalent to:
3I,F4.0/I5,F12.6
Format descriptors can be preceded by a repeat specification (for
example, the 3 in 3F12.4).
Format and edit descriptors can include another set of format or edit
descriptors, or both, enclosed in parentheses; this is called
nesting. The nested format specification can be preceded by a repeat
specification.
For example, the information shown on the input record in Figure 4-2
could be accessed with a FORMAT statement like the following:
10 FORMAT (I3,F7.4,3(F7.2,I3),F12.4)
A READ statement using the FORMAT statement could be:
READ 10,i,a,b,j,d,k,e,m,f
Format | I3 | F7.4 | F7.2 | I3 | F7.2 | I3 | F7.2 | I3 | F12.4
Speci- | | | | | | | | |
fiers | | | | | | | | |
| | | | | | | | |
-----------------------------------------------------------------------------------------------------------
| | | | | | | | |
Input | i | a | b | j | d | k | e | m | f
Vari- | | | | | | | | |
ables | | | | | | | | |
| | | | | | | | |
-----------------------------------------------------------------------------------------------------------
| | | | | | | | |
Input | Delta 26 | 26.4336 | Delta | Delta 24 | 2373.86 | 439 | Delta | Delta | Delta
Record | | | 342.26 | | | | 649.79 | Delta 4 | Delta
| | | | | | | | | Delta
| | | | | | | | | 4395.4972
| | | | | | | | |
-----------------------------------------------------------------------------------------------------------
| | | | | | | | |
Field | 3 | 7 | 7 | 3 | 7 | 3 | 7 | 3 | 12
Widths | | | | | | | | |
| | | | | | | | |
-----------------------------------------------------------------------------------------------------------
Figure 4-2. Input Formatting
The READ statement would read values for i and a, then repeat the nested
format specification (F7.2,I3) three times to read values for b and j,
for d and k, and for e and m, and, finally, read a value for f.
The format descriptors are summarized in Table 4-2 ; the edit
descriptors, in Table 4-3 . A detailed explanation of the descriptors
follows the tables.
Table 4-2. Format Descriptors
------------------------------------------------------------------------------------------------
| | | |
| Data Type | Format | Additional Explanation |
| | Descriptor | |
| | | |
------------------------------------------------------------------------------------------------
| | | |
| INTEGER*2, INTEGER*4 | I[w[.m]] | None |
| | | |
------------------------------------------------------------------------------------------------
| | | |
| REAL*4, REAL*8, REAL*16 | F[w.d] | Fixed-point format descriptor |
| COMPLEX*8, COMPLEX*16 | | |
| | | |
------------------------------------------------------------------------------------------------
| | | |
| REAL*4, REAL*8, REAL*16 | D[w.d] | Floating-point format descriptor |
| COMPLEX*8, COMPLEX*16 | E[w.d[Ee]] | |
| | | |
------------------------------------------------------------------------------------------------
| | | |
| REAL*4, REAL*8, REAL*16 | G[w.d[Ee]] | Fixed- or floating-point format |
| COMPLEX*8, COMPLEX*16 | | descriptor |
| | | |
------------------------------------------------------------------------------------------------
| | | |
| On input: INTEGER*2, INTEGER*4 | @[w[.m]] | Octal |
| On output: any type | K[w[.m]] | |
| | O[w[.m]] | |
| | | |
------------------------------------------------------------------------------------------------
| | | |
| On input: INTEGER*2, INTEGER*4 | Z[w[.m]] | Hexadecimal |
| On output: any type | | |
| | | |
------------------------------------------------------------------------------------------------
| | | |
| LOGICAL*1, LOGICAL*2, LOGICAL*4 | L[w] | None |
| | | |
------------------------------------------------------------------------------------------------
| | | |
| REAL*4, REAL*8, REAL*16 | M[w.d] | Monetary format; fixed-point |
| | | |
------------------------------------------------------------------------------------------------
| | | |
| REAL*4, REAL*8, REAL*16 | N[w.d] | Numeration format; fixed-point |
| | | |
------------------------------------------------------------------------------------------------
| | | |
| Character, Hollerith, or any other | A[w] | Character or Hollerith data is |
| type (treated as character) | | left-justified in memory and |
| | | external format |
| | | |
------------------------------------------------------------------------------------------------
| | | |
| Character, Hollerith, or any other | R[w] | Character or Hollerith data is |
| type (treated as character) | | right-justified in memory and |
| | | external format |
| | | |
------------------------------------------------------------------------------------------------
Table 4-3. Edit Descriptors
---------------------------------------------------------------------------------------------
| | |
| Edit Descriptor | Function |
| | |
---------------------------------------------------------------------------------------------
| | |
| BN | Ignore blanks. |
| | |
| BZ | Treat blanks as zeros. |
| | |
| nHstring | Hollerith literal editing |
| | |
| "string" | Literal editing. |
| | |
| 'string' | Literal editing. |
| | |
| NL | Restore newline. |
| | |
| NN | No newline. |
| | |
| $ | No newline; same as NN. |
| | |
| kP | Scale factor. |
| | |
| Q | Number of characters remaining in current |
| | input record. |
| | |
| SP | Output optional plus signs. |
| | |
| SS | Inhibit optional plus sign output. |
| | |
| S | Processor determines sign output; same as |
| | SS. |
| | |
| Tc | Skip to column c. |
| | |
| TLt | Skip t positions to the left. |
| | |
| TRt | Skip t positions to the right. |
| | |
| xX | Skip x positions to the right. |
| | |
| / | Begin new record. |
| | |
| : | Terminate format if I/O list is empty. |
| | |
---------------------------------------------------------------------------------------------
Numeric Format Descriptors
The numeric format descriptors specify the input/output fields of
integer, real, and complex data types. The following rules apply to all
numeric format descriptors:
* The field width, w, specifies the total number of characters that
a data field occupies, including any leading plus or minus sign,
decimal point, or exponent.
* On input, leading blanks are not significant. Trailing and
embedded blanks are treated as null characters unless the BZ edit
descriptor is encountered or the unit was connected with
BLANK='ZERO' specified. A field of all blanks is considered to be
a 0.
* On output, the data item is right-justified in the field. If the
item length is less than the field width, leading blanks are
inserted in the field. If the item is longer than the field width
for certain descriptors, the entire field is filled with dollar
signs, as specified in the output examples of the particular
descriptors.
* A complex list item is treated as two real items, and a double
complex list item as two double precision items.
* If a numeric list item is used with a numeric descriptor of a
different type, the value is converted as needed.
Integer Format Descriptor (I)
The I[w[.m]] format descriptor defines a field for an integer number.
The corresponding input/output list item must be a numeric type. The
optional m value specifies a minimum number of digits to be output. If m
is not shown, a default value of one is assumed. The m value is ignored
on input.
On input, the Iw format descriptor causes the interpretation of the next
w positions of the input record; the number is converted to match the
type of the list element currently using the descriptor. A plus sign is
optional for positive values. A decimal point must not appear in the
field.
Input Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Input Field | Value Stored |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| I4 | Delta 1 Delta Delta | 1 |
| | | |
| I5 | Delta Delta Delta Delta | 0 |
| | Delta | |
| | | |
| I2 | -1 | -1 |
| | | |
| I4 | -123 | -123 |
| | | |
| I3 | Delta 12 | 12 |
| | | |
| I2 | 123 | 12 |
| | | |
----------------------------------------------------------------------------------------------
On output, the Iw or Iw.m format descriptor causes output of a numeric
variable as a right-justified integer value (rounding takes place if
necessary). The field width, w, should be one greater than the expected
number of digits, to allow for a minus sign for negative values. If m =
0, a 0 value is output as all blanks.
Output Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Internal Value | Output Field |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| I4 | +452.25 | Delta 452 |
| | | |
| I2 | +6234 | ** |
| | | |
| I3 | -11.92 | -12 |
| | | |
| I5 | -52 | Delta Delta -52 |
| | | |
| I3 | -124 | *** |
| | | |
| I10 | 123456.5 | Delta Delta Delta Delta |
| | | 123457 |
| | | |
| I6.3 | 3 | Delta Delta Delta 003 |
| | | |
| I3.0 | 0 | Delta Delta Delta |
| | | |
| I3.3 | -123 | *** |
| | | |
----------------------------------------------------------------------------------------------
Real Format Descriptors (D, E, F, G)
The D[w.d], E[w.d[Ee]], F[w.d], and G[w.d[Ee]] format descriptors define
fields for real or complex numbers. (Note that two descriptors must be
specified for a complex value.) The input/output list item corresponding
to a D, E, F, or G descriptor must be a numeric type.
On input, all of these format descriptors work identically.
The input field for these descriptors consists of an optional plus or
minus sign followed by a string of digits that may contain a decimal
point. If the decimal point is omitted in the input string, the number
of digits equal to d from the right of the string are interpreted to be
to the right of the decimal point. If a decimal point appears in the
input string and conflicts with the format descriptor, the decimal point
in the input string takes precedence. This basic form can be followed by
an exponent in one of the following forms:
* A signed integer constant.
* An E followed by an integer constant.
* A D followed by an integer constant.
All three exponent forms are processed the same way. The following are
examples of valid input fields:
Input Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Input Field | Value Stored |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| F6.5 | 4.51E4 | 45100.0 |
| | | |
| G4.2 | 51-3 | .00051 |
| | | |
| E8.3 | 7.1 Delta E Delta 5 | 710000. |
| | | |
| D9.4 | Delta Delta Delta 45E+35 | .0045*1035 |
| | | |
| BZ,F7.1 | 54E34 Delta | -5.4 x 10340 (overflow |
| | | error) |
| | | |
| F12.10 | 34 | 3.4*10-9 |
| | | |
----------------------------------------------------------------------------------------------
The BZ edit descriptor equates blanks to zeros. It is described in
"Blank Interpretation Edit Descriptors (BN, BZ)" .
The appearance of the output field depends on whether the format
descriptor specifies a fixed- or floating-point format.
Floating-Point Format Descriptors (D, E)
The D[w.d] and E[w.d[Ee]] format descriptors define a floating-point
field on output for real and complex values. The value is rounded to d
digits. The exponent part consists of e digits. If Ee is omitted, the
exponent occupies two positions. The field width, w, should follow the
general rule:
w >= d + 7
or, if Ee is used,
w >= d + e + 5
to provide positions for a leading blank, the sign of the value, the
decimal point, d digits, the letter E, the sign of the exponent, and the
exponent.
Output Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Internal Value | Output Field |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| D10.3 | +12.342 | Delta Delta .123E+02 |
| | | |
| E10.3E3 | -12.3454 | -.123E+002 |
| | | |
| E12.4 | +12.340 | Delta Delta Delta .1234E+02 |
| | | |
| D12.4 | -.00456532 | Delta Delta -.4565E-02 |
| | | |
| D10.10 | 99.99913 | ********** |
| | | |
| E11.5 | +999.997 | Delta .10000E+04 |
| | | |
| E10.3E4 | .624*10-30 | .624E-0030 |
| | | |
----------------------------------------------------------------------------------------------
Fixed-Point Format Descriptor (F)
The F[w.d] format descriptor defines a fixed-point field on output for
real and complex values. The value is rounded to d digits to the right
of the decimal point. The field width, w, should be four greater than
the expected length of the number, to provide positions for a leading
blank, the sign, the decimal point, and a roll-over digit for rounding if
needed.
Output Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Internal Value | Output Field |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| F5.2 | +10.567 | 10.57 |
| | | |
| F3.1 | -254.2 | *** |
| | | |
| F6.3 | +5.66791432 | Delta 5.668 |
| | | |
| F8.2 | +999.997 | Delta 1000.00 |
| | | |
| F8.2 | -999.998 | -1000.00 |
| | | |
| F7.2 | -999.997 | ******* |
| | | |
| F4.1 | 23 | 23.0 |
| | | |
----------------------------------------------------------------------------------------------
Fixed- or Floating-Point Format Descriptor (G)
The G[w.d[Ee]] format descriptor defines a fixed- or floating-point
field, as needed, on output for real and complex values. The G format
descriptor is interpreted as an Fw.d descriptor for fixed-point form or
as an Ew.d[Ee] descriptor for floating-point form according to the
magnitude of the data. If the magnitude is less than 0.1 or greater than
or equal to 10**d (after rounding to d digits), the Ew.d[Ee] format
descriptor is used; otherwise the Fw.d format descriptor is used. When
Fw.d is used, trailing blanks are included in the field where the
exponent would have been. The field occupies w positions; the fractional
part consists of d digits, and the exponent part consists of e digits.
If Ee is omitted, the exponent occupies two positions. The field width,
w, should follow the general rule for floating-point descriptors:
w >= d + 7
or, if Ee is used,
w >= d + e + 5
to provide for a leading blank, the sign of the value, d digits, the
decimal point, and, if needed, the letter E, the sign of the exponent,
and the exponent.
-------------------------------------------------------------------------------------------------
| | | | |
| Descriptor | Internal Value | Interpreted As | Output Field |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| G10.3 | +1234 | E10.3 | Delta Delta .123E+04 |
| | | | |
| G10.3 | -1234 | E10.3 | Delta -.123E+04 |
| | | | |
| G12.4 | +12345 | E12.4 | Delta Delta Delta |
| | | | .1235E+05 |
| | | | |
| G12.4 | +9999 | F8.0,4X | Delta Delta Delta |
| | | | 9999. Delta Delta |
| | | | Delta Delta |
| | | | |
| G12.4 | -999 | F8.1,4X | Delta Delta -999.0 |
| | | | Delta Delta Delta |
| | | | Delta |
| | | | |
| G7.1 | +.09 | E7.1 | Delta .9E-01 |
| | | | |
| G5.1 | -.09 | E5.1 | ***** |
| | | | |
| G12.1 | +9999 | E12.2 | Delta Delta Delta |
| | | | Delta Delta .1E+05 |
| | | | |
| G8.2 | +999 | E8.2 | Delta .10E+04 |
| | | | |
| G7.2 | -999 | E7.2 | ******* |
| | | | |
| G8.2 | 0 | E8.2 | Delta 00E+00 |
| | | | |
-------------------------------------------------------------------------------------------------
Character Format Descriptors (A, R)
The A[w] and R[w] format descriptors define fields for character and
noncharacter data. The size of the list variable (byte length)
determines the maximum effective value for w. If w is not specified, the
size of the field is equal to the size of the input/output variable.
As an extension to the ANSI 77 standard, any data type can be used with
the A and R descriptors.
Using the A and R format descriptors for input and output, w can be equal
to, less than, or greater than the specified byte size of the input or
output variable. If w is equal to the length of the variable, the
character data field is the same as the variable. If w is less than or
greater than the length of the variable, there are eight possibilities
for the character data field, summarized in Table 4-4 .
The R format descriptor is an extension to the ANSI 77 standard.
Table 4-4. Contents of Character Data Fields
----------------------------------------------------------------------------------------------
| | | |
| Input Descriptor | Length of Input Variable | Result |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| A[w] | w < len | Left-justified in variable, |
| | | followed by blanks. |
| | | |
| | w > len | Taken from right part of |
| | | field. |
| | | |
| R[w] | w < len | Right-justified in variable, |
| | | preceded by binary zeros. |
| | | |
| | w > len | Taken from right part of |
| | | field. |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| Output Descriptor | Length of Output Variable | Result |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| A[w] | w < len | Taken from left part of |
| | | variable. |
| | | |
| | w > len | Right-justified in variable, |
| | | preceded by blanks. |
| | | |
| R[w] | w < len | Taken from right part of |
| | | variable. |
| | | |
| | w > len | Right-justified in variable, |
| | | preceded by blanks. |
| | | |
----------------------------------------------------------------------------------------------
In the following examples, Delta or Delta represents a blank and _
represents a byte of binary zeros.
Input Examples
-------------------------------------------------------------------------------------------------
| | | | |
| Descriptor | Input Field | Internal | Value Stored |
| | | Length | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| A3 | XYZ | 3 | XYZ |
| | | | |
| R3 | XYZ | 4 | _XYZ |
| | | | |
| A5 | ABC Delta Delta | 10 | ABC Delta Delta Delta |
| | | | Delta Delta Delta |
| | | | Delta Delta |
| | | | |
| R9 | RIGHTMOST | 4 | MOST |
| | | | |
| A5 | CHAIR | 5 | CHAIR |
| | | | |
| R8 | CHAIR Delta Delta | 8 | CHAIR Delta Delta |
| | Delta | | Delta |
| | | | |
| A4 | ABCD | 2 | CD |
| | | | |
-------------------------------------------------------------------------------------------------
Output Examples
-------------------------------------------------------------------------------------------------
| | | | |
| Descriptor | Internal Value | Internal | Output Field |
| | | Length | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| A6 | ABCDEF | 6 | ABCDEF |
| | | | |
| R4 | ABCDEFGH | 4 | EFGH |
| | | | |
| A4 | ABCDE | 5 | ABCD |
| | | | |
| A8 | STATUS | 6 | STATUS Delta Delta |
| | | | |
| A4 | NEXT | 4 | NEXT |
| | | | |
| R8 | STATUS | 6 | Delta Delta STATUS |
| | | | |
-------------------------------------------------------------------------------------------------
Numeric Data with Character Format Descriptors.
The A and R character format descriptors can be used with integer and
real data types.
If you specify the NOSTANDARD compiler directive, the data is output in
reverse order, starting at the right and progressing to the left.
Example
PROGRAM demo
! Output numeric data with character format using an external write.
INTEGER*4 i4
i4 = 4Habcd
WRITE(6,100) i4
100 FORMAT(a)
STOP
END
If you specify the NOSTANDARD compiler directive, dcba is output. If it
is not specified, abcd is output.
For more information refer to "NOSTANDARD Directive" .
Logical Format Descriptor (L)
The L[w] format descriptor defines a field for logical data. The
input/output list item corresponding to a L descriptor must be a logical
type.
On input, the field width is scanned for optional blanks followed by an
optional decimal point, followed by a T for true or an F for false. The
first nonblank character in the input field (excluding the optional
decimal point) determines the value to be stored in the declared logical
variable. If the first nonblank character is not a T or an F, an error
occurs.
Input Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Input Field | Value Stored |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| L5 | Delta Delta Delta T Delta | .TRUE. |
| | | |
| L2 | F1 | .FALSE. |
| | | |
| L4 | Delta x Delta T | Error |
| | | |
| L5 | Delta RT Delta | Error |
| | | |
| L7 | TFALSE Delta | .TRUE. |
| | | |
| L7 | .FALSE. | .FALSE. |
| | | |
----------------------------------------------------------------------------------------------
On output, a T or an F is right-justified in the output field depending
on whether the value of the list item is true or false.
Output Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Internal Value | Output Fields |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| L5 | .FALSE. | Delta Delta Delta Delta F |
| | | |
| L4 | .TRUE. | Delta Delta Delta T |
| | | |
| L1 | .TRUE. | T |
| | | |
| L2 | .FALSE. | Delta F |
| | | |
----------------------------------------------------------------------------------------------
The logical value true or false is determined by the least significant
bit of the most significant byte of the internal representation.
Octal Format Descriptors (@, K, O)
As an extension to the ANSI 77 standard, the @[w[.m]], K[w[.m]], and
O[w[.m]] format descriptors define a field for octal data. These
descriptors provide conversion between an external octal number and its
internal representation. On output, list elements may be of any type,
though character variables are output only as the octal equivalent of
their ASCII representation (no length descriptor). Variables to receive
octal input must be integer types.
On input, the presence of too many digits for the integer variable (or
list element) to receive produces undefined results. Legal octal digits
are 0 through 7. Plus and minus signs are not permitted on input nor
printed on output. If any nonoctal digit appears, an error occurs.
On output, if w is greater than the number of converted octal digits
(including blanks between words but excluding leading zeros), the octal
digits are right-justified in the output field. Blanks are inserted at
the boundaries of machine words in internal representation. If w is less
than the number of converted octal digits, the field is filled with
asterisks. This primarily affects the output of negative values.
Because negative values are output without a sign, their high-order bits
are nonzero and cause the field to be filled with asterisks if w is less
than the number of octal digits in the entire output value.
The optional m value specifies a minimum number of digits to be output,
forcing leading zeros as necessary up to the first non-zero digit. The m
is ignored on input.
Input Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Input Field | Value Stored |
| | (Octal) | (Octal) |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| @6 | 123456 | 123456 |
| | | |
| 2K4 | 00360005 | 000036 and 000005 |
| | | |
| O5 | 12934 | Error |
| | | |
| @6 | 17777B | Error |
| | | |
| K9 | -37000000 | Error |
| | | |
----------------------------------------------------------------------------------------------
Output Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Internal Value | Output Field |
| | (Decimal) | (Octal) |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| K6 | 99 | Delta Delta Delta 143 |
| | | |
| O2 | 99 | ** |
| | | |
| @8 | -1 (INTEGER*4) | ******** |
| | | |
| @6 | 32767 | Delta 77777 |
| | | |
----------------------------------------------------------------------------------------------
Hexadecimal Format Descriptor (Z)
As an extension to the ANSI 77 standard, the Z[w[.m]] format descriptor
defines a field for hexadecimal data. This descriptor provides
conversion between an external hexadecimal number and its internal
representation. On output, list elements may be of any type, though
character variables are output only as the hexadecimal equivalent of
their ASCII representation (without a length descriptor). Variables to
receive hexadecimal input must be an integer type.
On input, the presence of too many digits for the integer variable (or
list element) to receive produces undefined results. Legal hexadecimal
digits are 0 through 9 and A through F. Plus and minus signs are not
permitted on input, nor printed on output. If any nonhexadecimal digit
appears, an error occurs.
On output, if w is greater than the number of converted hexadecimal
digits (including blanks between words but excluding leading zeros), the
hexadecimal digits are right-justified in the output field. Blanks are
inserted at the boundaries of machine words in internal representation.
If w is less than the number of converted hexadecimal digits, the field
is filled with asterisks. This primarily affects the output of negative
values. Because negative values are output without a sign, their
high-order bits are nonzero and cause the field to be filled with
asterisks if w is less than the number of hexadecimal digits in the
entire output value.
The optional m value specifies a minimum number of digits to be output,
forcing leading zeros as necessary up to the first non-zero digit. The m
is ignored on input.
Input Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Input Field | Value Stored |
| | (Hexadecimal) | (Hexadecimal) |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| Z6 | 123ABC | 123ABC |
| | | |
| 2Z4 | 009F0005 | 00009F and 000005 |
| | | |
| Z5 | 12G34 | Error |
| | | |
| Z6 | Z111111 | Error |
| | | |
| Z9 | 37000000 | Error |
| | | |
----------------------------------------------------------------------------------------------
Output Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Internal Value | Output Field |
| | (Decimal) | (Hexadecimal) |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| Z6 | 99 | Delta Delta Delta Delta 63 |
| | | |
| Z2 | 299 | ** |
| | | |
| Z7 | -1 (INTEGER*4) | ******* |
| | | |
| Z6 | 32767 | Delta Delta 7FFF |
| | | |
----------------------------------------------------------------------------------------------
Variable Format Descriptor (<expression>)
Variable format descriptors, having the form <expression>, allow the
values of integer variables, integer constant names, and character
constants to be used in format specifications. Integer variable format
descriptors may be used wherever an integer may appear, except they
cannot be used to specify the number of characters in a Hollerith
descriptor. Character-constant variable format descriptors may be used
anywhere in the format specification between the opening and closing
parentheses. The following is an example of a variable format
descriptor:
I<isize>
In this example, the I format descriptor performs an integer data
transfer with a field width equal to the value of isize when the format
is used.
Variables may be INTEGER*2 or INTEGER*4. The value of a variable format
descriptor must be of a valid magnitude for its use in the format;
otherwise an error occurs.
Variable format descriptors are only permitted in FORMAT statements and
in constant format specifications used in I/O statements. They are not
allowed in run-time formats (that is, those that are prepared in arrays
or character expressions at run-time).
If a variable is used, its value is reevaluated each time it is
encountered in the normal format scan. If the value of a variable used
in a descriptor changes during execution of the I/O statement, the new
value is used the next time the format item containing the descriptor is
processed.
Example
The following program illustrates the use of variable format descriptors:
PROGRAM varfmt1
INTEGER n
PARAMETER (n = 3)
REAL x(n,n)
C Data for two-dimensional array x(n,n):
DATA x / 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 /
C Print out the constants 1 through 3 in variable width fields.
DO 10 j = 1,3
PRINT 100,j
100 FORMAT (1x, I<j>)
10 CONTINUE
C Print out the lower diagonal elements of matrix x.
DO 20 i = 1,n
PRINT 101, (x(i,k), k = 1,I)
101 FORMAT (1x, <I>F5.1)
20 CONTINUE
END
Output (Delta is a blank):
Delta 1 Format specification (1x,I<j>) became (1x,I1)
Delta Delta 2 Format specification (1x,I<j>) became (1x,I2)
Delta Delta Delta 3 Format specification (1x,I<j>) became (1x,I3)
Delta Delta Delta 1.0 Format specification (1x,<I>F5.1) became (1x,1F5.1)
Delta Delta Delta 2.0 Delta Delta 5.0 Format specification (1x,<I>F5.1) became (1x,2F5.1)
Delta Delta Delta 3.0 Delta Delta 6.0 Delta Delta 9.0 Format specification (1x,<I>F5.1) became (1x,3F5.1)
Monetary Format Descriptor (M)
The M[w.d] format descriptor defines a field for a real number without an
exponent (fixed-point) written in monetary form.
On output, the M format descriptor causes output of a numeric value in
ASCII character fixed-point form, right-justified with commas and a
dollar sign. The least significant digit (position d) is rounded. If
needed, a leading minus sign is printed before the dollar sign.
In addition to the number of numeric digits, the field width w must allow
for the number of commas expected plus four characters to hold the sign,
the dollar sign, the decimal point, and a rollover digit (if necessary).
If w is greater than the number of positions required for the output
value, the output is right-justified in the field with blank spaces to
the left. If w is less than the number of positions required, the output
value of the entire field is filled with asterisks.
On input, the M format descriptor causes interpretation of the next w
positions of the input record as a real number without an exponent. The
field width is expected (but not required) to have a dollar sign and
commas embedded in the data as described for M output (the dollar sign
and commas are ignored). If commas are used, the usage must be
consistent; that is, commas must occur every three digits of the
nonfractional part of the input value. The number is converted to an
internal representation value for the variable (list element) currently
using the format descriptor.
Input Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Input Field | Value Stored |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| M10.3 | Delta Delta Delta $12.340 | 12.340 |
| | | |
| M10.3 | Delta Delta $12.3402 | 12.3402 |
| | | |
| M13.3 | Delta Delta Delta Delta | 80175.397 |
| | 80175.397 | |
| | | |
| M12.2 | -$80,175.397 | -80175.397 |
| | | |
| M12.2 | Delta Delta Delta 99999.996 | 99999.996 |
| | | |
----------------------------------------------------------------------------------------------
Output Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Internal Value | Output Field |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| M10.3 | +12.3402 | Delta Delta Delta $12.340 |
| | | |
| M10.3 | -12.3404 | Delta Delta -$12.340 |
| | | |
| M13.3 | +80175.3965 | Delta Delta $80,175.397 |
| | | |
| M12.2 | +99999.996 | Delta $100,000.00 |
| | | |
| M12.2 | -99999.996 | -$100,000.00 |
| | | |
| M11.2 | -99999.995 | *********** |
| | | |
----------------------------------------------------------------------------------------------
Numeration Format Descriptor (N)
The N[w.d] field descriptor defines a field for a real number without an
exponent (fixed-point) written in numeration form (that is, with commas,
which are then ignored, in the input field).
On output, the N field descriptor causes output of a numeric value in
ASCII character fixed-point form, right-justified with commas. The least
significant digit is rounded. If needed, a leading minus sign is printed
before the most significant digit.
In addition to the number of numeric digits, the field width w must allow
for the number of commas expected, plus three characters to hold the
sign, the decimal point, and a rollover digit (if necessary). If w is
greater than the number of positions required for the output value, the
output is right-justified in the field with blank spaces to the left. If
w is less than the number of positions required for the output value, the
entire field is filled with asterisks.
On input, the N field descriptor causes interpretation of the next w
positions of the input record as a real number without an exponent. The
field width is expected (but not required) to have commas embedded in the
data as described for N output (the commas are ignored). If commas are
used, the usage must be consistent; that is, commas must occur every
three digits of the dollar part of the input value. The number is
converted to an internal representation value for the variable (list
element) currently using the field descriptor.
Input Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Input Field | Value Stored |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| N10.3 | Delta Delta Delta Delta | 12.340 |
| | 12.340 | |
| | | |
| N10.3 | Delta Delta Delta 12.3402 | 12.3402 |
| | | |
| N13.3 | Delta Delta Delta Delta | 80175.397 |
| | 80175.397 | |
| | | |
| N12.2 | Delta Delta Delta 80175.397 | 80175.397 |
| | | |
| N12.2 | Delta Delta 99,999.996 | 99999.996 |
| | | |
| N13.2 | Delta Delta -10,000.317 | -10000.317 |
| | | |
----------------------------------------------------------------------------------------------
Output Examples
----------------------------------------------------------------------------------------------
| | | |
| Descriptor | Internal Value | Output Field |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| N10.3 | +12.3402 | Delta Delta Delta Delta |
| | | 12.340 |
| | | |
| N10.3 | -12.3404 | Delta Delta Delta -12.340 |
| | | |
| N13.3 | +80175.3965 | Delta Delta Delta 80,175.397 |
| | | |
| N12.2 | -80175.396 | Delta Delta -80,175.40 |
| | | |
| N12.2 | +99999.996 | Delta Delta 100,000.00 |
| | | |
| N10.2 | -99999.995 | ********** |
| | | |
----------------------------------------------------------------------------------------------
MPE/iX 5.0 Documentation