A variable format expression is a numeric expression enclosed in angle brackets (< >) that can be used in a FORMAT statement or in character format specifications.
The numeric expression can be any valid Fortran expression, including function calls and references to dummy arguments.
If the expression is not of type integer, it is converted to integer type before being used.
If the value of a variable format expression does not obey the restrictions on magnitude applying to its use in the format, an error occurs.
Variable format expressions cannot be used with the H edit descriptor, and they are not allowed in character format specifications.
Variable format expressions are evaluated each time they are encountered in the scan of the format. If the value of the variable used in the expression changes during the execution of the I/O statement, the new value is used the next time the format item containing the expression is processed.
Examples
Consider the following statement:
FORMAT (I<J+1>)
When the format is scanned, the preceding statement performs an I (integer) data transfer with a field width of J+1. The expression is reevaluated each time it is encountered in the normal format scan.
Consider the following statements:
DIMENSION A(5)
DATA A/1.,2.,3.,4.,5./
DO 10 I=1,10
WRITE (6,100) I
100 FORMAT (I<MAX(I,5)>)
10 CONTINUE
DO 20 I=1,5
WRITE (6,101) (A(I), J=1,I)
101 FORMAT (<I>F10.<I-1>)
20 CONTINUE
END
On execution, these statements produce the following output:
1
2
3
4
5
6
7
8
9
10
1.
2.0 2.0
3.00 3.00 3.00
4.000 4.000 4.000 4.000
5.0000 5.0000 5.0000 5.0000 5.0000
For More Information:
For details on the synchronization of I/O lists with formats, see Section 11.8.