HP 3000 Manuals

Format Specifications [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation


HP FORTRAN 77/iX Reference

Format Specifications 

A format specification is a list of format descriptors and edit
descriptors, enclosed in parentheses.  It is equivalent to a FORMAT
statement without the label and FORMAT keyword.

Format Specification Syntax 

( descriptor_list )

Descriptor List Syntax 

{[repeat_spec] format_descriptor  }
{[repeat_spec] ( descriptor_list )} [[,]...]
{edit_descriptor                  }

-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
|       Item        |        Description/Default         |            Restrictions            |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| edit_descriptor   | An edit descriptor, as described   | None.                              |
|                   | in Table 4-3.                      |                                    |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| format_descriptor | A format descriptor, as described  | None.                              |
|                   | in Table 4-2.                      |                                    |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------

repeat_spec must be an unsigned positive integer constant or a variable
format descriptor whose value is positive.

The format descriptors describe how the data appears and the edit
descriptors specify editing information.  For example, in the following
format specification:

     (I3,3X,3F12.3)

the format descriptor I3 specifies an integer number with a field width
of three (the integer takes up a total of three character positions), the
edit descriptor 3X specifies that three character positions are to be
skipped, and the format descriptor 3F12.3 specifies three real numbers,
each with a field width of 12 and three significant digits to the right
of the decimal point.  A PRINT statement using this format specification
could be of the form:

     PRINT '(I3,3X,3F12.3)',i,a,b,c

The relationships are shown in Figure 4-1 .

               |                |                |                |                |
Format         |       I3       |       3X       |     F12.3      |     F12.3      |     F12.3
Specifiers     |                |                |                |                |
               |                |                |                |                |
---------------------------------------------------------------------------------------------------
               |                |                |                |                |
Output         |       i        |                |       a        |       b        |       c
Variables      |                |                |                |                |
               |                |                |                |                |
---------------------------------------------------------------------------------------------------
               |                |                |                |                |
Output Record  |      345       |  Delta Delta   |  65376453.324  |  Delta Delta   |     Delta
               |                |     Delta      |                |     Delta      |  4765321.321
               |                |                |                |   14321.265    |
               |                |                |                |                |
---------------------------------------------------------------------------------------------------
               |                |                |                |                |
Field Widths   |       3        |       3        |       12       |       12       |       12
               |                |                |                |                |
---------------------------------------------------------------------------------------------------

          Figure 4-1.  Output Formatting 

Format specifications can be supplied in FORMAT statements or written as
character expressions in input/output statements.

Format Specifications in Format Statements 

A format specification can be placed in a FORMAT statement that is
referenced by a corresponding READ, WRITE, or PRINT statement.  For the
complete syntax definition, refer to "FORMAT Statement (Nonexecutable)"
.

FORMAT Statement Syntax 

label FORMAT format_specification 

-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
|       Item        |        Description/Default         |            Restrictions            |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| label             | Required statement label.          | None.                              |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| format_specificationFormat specification, defined      | None.                              |
|                   | above.                             |                                    |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------

                 Examples                                      Notes 

---------------------------------------------------------------------------------------

    READ (5,10) a,i,d,e                     The format descriptors A2, I3, D8.2, and
10 FORMAT(A2,I3,D8.2,F12.2)                 F12.2 in the FORMAT statement correspond
                                            with the list variables a, i, d, and e in
                                            the READ statement.  List element a
                                            corresponds with the format descriptor A2,
                                            i with I3, d with D8.2, and e with F12.2.

A FORMAT statement can be used by several input/output statements.  Make
sure that each variable in the input/output list corresponds with its
respective format descriptor in the format specification.

Format Specifications in Input/Output Statements 

The format specification can be contained in the input/output statement
as a character expression.

                 Examples                                      Notes 

---------------------------------------------------------------------------------------

READ (4,'(A3,3X,F10.2)') a,z                The variables a and z are read according to
                                            the format specification (A3,3X,F10.2).

CHARACTER*6 a                               The three integers i, j, and k are printed
DATA a /'(3I3) '/                           according to the format specification
PRINT a,i,j,k                               (3I3).  The variable d is written as a
WRITE (6,'(F10.2)') d                       fixed-point number according to the format
                                            specification (F10.2).

Care must be taken when the format specification in an input/output
statement contains an apostrophe or a quotation mark.  Whenever an
apostrophe (') appears within an apostrophe edit descriptor, it must be
represented by two consecutive apostrophes.  Similarly, if a quotation
mark (") appears in a quotation mark edit descriptor, it must be
represented by two consecutive quotation marks.

Each of these, in turn, must be represented by two apostrophes or
quotation marks if the format is a character literal contained in an
input/output statement.  Notice, therefore, that four consecutive
apostrophes are required in the second example below.

                 Examples                                      Notes 

---------------------------------------------------------------------------------------

WRITE (6,'(3X,''THIS IS THE END'')')        Writes the following record:

                                                 Delta Delta Delta THIS IS THE END

WRITE (6,'(''Isn''''t it true!'')')         Writes the following record:

                                                 Isn't it true!

WRITE (6,'("Isn''t it true!")')             Writes the same record as the previous
                                            example.



MPE/iX 5.0 Documentation