What does this Fortran code mean:
IF (J1-3) 20, 20, 21
21 J1 = J1 - 3
20 IF (J2-3) 22, 22, 23
23 J2 = J2 - 3
22 CONTINUE
I've seen in old project and I don't have any idea what this IF with numbers (labels) means.
The IF level of a statement S is the value n1-n2, where n1 is the number of block IF statements from the beginning of the program unit up to the end, including S; n2 is the number of END IF statements in the program unit up to, but not including, S. The IF -level of every statement must be zero or positive.
The computed GO TO statement selects one statement label from a list, depending on the value of an integer or real expression, and transfers control to the selected one.
Fortran 77 syntax & Fortran 90 syntax & Meaning .lt. < less than .le. <= less than or equal to .eq. == equal to .ge. >= greater than or equal to .gt. >
A statement label is a sequence of one to five digits, one of which must be nonzero, that you can use to identify statements in a Fortran scoping unit. In fixed source form, a statement label can appear anywhere in columns 1 through 5 of the initial line of the statement.
This is an arithmetic if
statement from FORTRAN 77. Adapted from the FORTRAN 77 specification (emphasis mine):
The form of an arithmetic
IF
statement is:
IF (e) s1 , s2 , s2
where:
e
is an integer, real, or double precision expression
s1
,s2
, ands3
are each the statement label of an executable statement that appears in the same program unit as the arithmeticIF
statement. The same statement label may appear more than once in the same arithmeticIF
statement.Execution of an arithmetic
IF
statement causes evaluation of the expressione
followed by a transfer of control. The statement identified bys1
,s2
, ors3
is executed next as the value ofe
is less than zero, equal to zero, or greater than zero, respectively.
For the example in your question, from the last sentence above,
J1-3 < 0
statement 20 will be executedJ1-3 = 0
statement 20 will also be executedJ1-3 > 0
statement 21 will be executedEdit: A modern and much more readable way to write this would be:
if (J1-3 > 0) J1 = J1 - 3
if (J2-3 > 0) J2 = J2 - 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With