LionsFan
LionsFan

Reputation: 119

Data block Fortran 77 clarification

I am trying to access a data block, the way it is define is as follows

      DATA NAME /'X1','X2','X3','X4','X5','X6','X7','X8','X9','10','11',00028650
     1'12','13','14','15','16','17','18','19','20','21','22','23','24'/ 00028660

The code is on paper. Note this is an old code, the only thing i am trying to do is understand how the array is being indexed. I am not trying to compile it.

The way it is accessed is as follows

I = 0
Loop
   I = I + 1
   write (06,77) (NAME(J,I),J=1,4)  //this is inside a write statement. 
end loop                            //77 is a format statement. 

Not sure how it is being indexed, if you guys can shed some light that would be great.

Upvotes: 1

Views: 121

Answers (1)

francescalus
francescalus

Reputation: 32366

The syntax (expr, intvar=int1,int2[,int3]) widely refers to an implied DO loop. There are several places where such a thing may occur, and an input/output statement is one such place.

An implied DO loop evaluates the expression expr with the do control integer variable intvar sequentially taking the values initially int1 in steps of int3 until the value int2 is reached/passed. This loop control is exactly as one would find in a do loop statement.

In the case of the question, the expression is name(j,i), the integer variable j is the loop variable, taking values between the bounds 1 and 4. [The step size int3 is not provided so is treated as 1.] The output statement is therefore exactly like

write(6,77) name(1,i), name(2,i), name(3,i), name(4,i)

as we should note that elements of the implied loop are expanded in order. i itself comes from the loop containing this output statement.

name here may refer to a function, but given the presence of a data statement initializing it, it must somehow be declared as a rank-2 (character) array. The initialization is not otherwise important.

Upvotes: 1

Related Questions