Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fortran IF statement with numbers/labels rather than another statement

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.

like image 859
Pavel Oganesyan Avatar asked Jun 20 '12 17:06

Pavel Oganesyan


People also ask

How do I write an IF condition in Fortran?

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.

How do I use GOTO statement in Fortran?

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.

What is .ge Fortran?

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. >

What is a statement label in Fortran?

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.


1 Answers

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, and s3 are each the statement label of an executable statement that appears in the same program unit as the arithmetic IF statement. The same statement label may appear more than once in the same arithmetic IF statement.

Execution of an arithmetic IF statement causes evaluation of the expression e followed by a transfer of control. The statement identified by s1, s2, or s3 is executed next as the value of e is less than zero, equal to zero, or greater than zero, respectively.

For the example in your question, from the last sentence above,

  • If J1-3 < 0 statement 20 will be executed
  • If J1-3 = 0 statement 20 will also be executed
  • If J1-3 > 0 statement 21 will be executed

Edit: 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
like image 55
Chris Avatar answered Oct 21 '22 22:10

Chris