This third and last part of format scanning concerns about the presence of grouping. Of course, all rules discussed in Scanning a Format: I and Scanning a Format: II also apply. The new rule is the following:
When Fortran rescans the format, it starts with the right-most left parenthesis, including its repetition indicator. The right-most left parenthesis is the opening left parenthesis if there is no grouping in the format.
The best way to explain the above rule is using several examples.
This format contains a group. Therefore, when the first pass uses all edit descriptors (i.e., 1X,I3,F5.2,I3,F5.2,A), Fortran must reuse this format. Since there is a grouping, Fortran reuses the format starting with the right-most left parenthesis. In this case, the reuse starts with 2(. Therefore, the subsequent available edit descriptors are I3,F5.2,I3,F5.2 followed by A. If the format rescan is required again, Fortran reuses the format at 2(. Consequently, the above format is equivalent to the following:(1X, 2(I3,F5.2),A)
Why is there a /? Good question! Recall that once the end of a format is reached and there are unread or unprinted variables, Fortran will advance to the next input or output line. This was discussed in Scanning a Format: I. Therefore, after using 1X,I3,F5.2,I3,F5.2,A, the end of format is reached and Fortran advances to the next input or output line. This is equivalent to say that the current input or output is terminated, which is the job of /!(1X, I3, F5.2, I3, F5.2, A / I3, F5.2, I3, F5.2, A / I3, F5.2, I3, F5.2, A / .......)
Since format rescan starts at 2(, the above format is equivalent to(1X, 2(I5),A)
However, format (1X,2I5,A) is equivalent to(1X, I5, I5, A / I5, I5, A / I5, I5, A / ......)
Thus, the effect of (1X,2I5,A) is totally different from that of (1X,2(I5),A).(1X, I5, I5, A / 1X, I5, I5, A / 1X, I5, I5, A / .....)
It is equivalent to the following:(1X, 3(I2,I3),F5.0, 2(1X,I3))
Why? This is because format rescan always starts at the right-most left parenthesis and in this case it is 2(. Therefore, only 2(1X,I3) is repeated in the rescanning process.(1X, I2, I3, I2, I3, F5.0, 1X, I3, 1X, I3 / 1X, I3, 1X, I3 / 1X, I3, 1X, I3 / .......)
This one is equivalent to the following:(1X, I1, (I2, I3))
Since format rescanning starts at (I2 and since this grouping has no repetition indicator, I2,I3 is repeated only once. However, if the given format becomes:(1X, I1, I2, I3 / I2, I3 / I2, I3 / ......)
On the surface, removing the pair of parenthesis does nothing because its repetition indicator is one. But, in fact, the above is equivalent to(1X, I1, I2, I3)
Which is a totally different format! Grouping without the repetition indicator is a commonly used technique. Please refer to the programming examples.(1X, I1, I2, I3 / 1X, I1, I2, I3 / ......)