### 7.1.2.2 Implied-DO Lists in I/O Statements

An implied-DO list is an I/O list element that acts as though it were a part of an I/O statement within a DO loop. It takes the following form:

    (list, i = e1,e2[,e3])

list
  Is an I/O list.
i
  Is an integer or real variable.
e1,e2,e3
  Are arithmetic expressions.

The variable i and the parameters e1, e2, and e3 have the same forms and the same functions that they have in the DO statement (see Section 5.4). The list immediately preceding the DO loop parameter is the range of the implied-DO loop. Elements in that list can refer to i, but they must not change the value of i.

Use an implied-DO list to do the following:

- Specify iteration of part of an I/O list

- Transfer part of an array

- Transfer array elements in a sequence different from the order of subscript progression

If the I/O statement containing an implied-DO list terminates abnormally (with an END= or ERR= transfer or with an IOSTAT value other than zero), the loop control variable becomes undefined.

Examples

The following two WRITE statements have the same effect:

    WRITE (3,200) (A,B,C, I=1,3)

    WRITE (3,200) A,B,C,A,B,C,A,B,C

In the following example, the I/O list consists of an implied-DO list containing another implied-DO list nested within it:

    WRITE (6) (I, (J,P(I),Q(I,J), J=1,L), I=1,M)

Together, the implied-DO lists write a total of (1+3*L)*M fields, varying the Js for each value of I.

In a series of nested implied-DO lists, parentheses indicate the nesting (see Section 5.4.1.2). Execution of the innermost lists is repeated most often; for example:

          WRITE (6,150) ((FORM(K,L), L=1,10), K=1,10,2)

    150   FORMAT (F10.2)

Because the inner DO loop is executed 10 times for each iteration of the outer loop, the second subscript, L, advances from 1 through 10 for each increment of the first subscript, K. This is the reverse of the order of subscript progression. K is incremented by 2, so only the odd-numbered rows of the array are output.

The entire list of an implied-DO list is transmitted before the control variable is incremented; for example:

    READ (5,999) (P(I), (Q(I,J), J=1,10), I=1,5)

In this case, P(1), Q(1,1), Q(1,2) ...,Q(1,10) are read before I is incremented to 2.

When processing multidimensional arrays, you can use a combination of fixed subscripts and subscripts that vary according to an implied-DO list; for example:

    READ (3,5555) (BOX(1,J), J=1,10)

This statement assigns input values to BOX(1,1) through BOX(1,10) and then terminates without affecting other elements of the array.

The value of the control variable can also be output directly; for example:

    WRITE (6,1111) (I, I=1,20)

This statement prints the integers 1 through 20.

Previous Page Next Page Table of Contents