Fortran branching statement confusion

  • Context: Fortran 
  • Thread starter Thread starter msmolen
  • Start date Start date
  • Tags Tags
    Confusion Fortran
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
6 replies · 2K views
msmolen
Messages
6
Reaction score
0
Folks:
I have a FORTRAN program published in Multivariate Morphometrics (Blackith and Reyment - 1971). In this book they list a FORTRAN program that computes Canonical Correlates. I don't have a FORTRAN compiler and I'm trying to translate this program into PERL. The one FORTRAN book that is helping me along is Problem Solving and Structured Programming in Fortran (Friedman and Koffman-1978).

The program has the following statement, which I can't figure out:

a) IF ( IEGEN ) 15 , 10 , 15
b) 10 DO 14 I = 1 , N
c) DO 14 J = 1 , N

d) IF ( I = J ) 12 , 11 , 12

e) 11 U ( I , J ) = 1
f) GO TO 14
g) 12 U ( I , J ) = 0
h) 14 CONTINUE
g) 15 NR = 0 (program code continues on.

I think that I understand line a) in that if IEGEN is -1, 0, +1 it branches to 15 , 10, or 15. The program seems to always enter with the value of 0 and so branches to line b) and builds an array.

But what is the decision metric in line d)? In the IF I = J decision, what is -1 , or 0, or +1?
If I = J the value would be equal to zero? But how does one get -1 or +1 out of this?

Any help for me to understand this statement would be greatly appreciated.
 
Physics news on Phys.org
msmolen said:
Folks:
I have a FORTRAN program published in Multivariate Morphometrics (Blackith and Reyment - 1971). In this book they list a FORTRAN program that computes Canonical Correlates. I don't have a FORTRAN compiler and I'm trying to translate this program into PERL. The one FORTRAN book that is helping me along is Problem Solving and Structured Programming in Fortran (Friedman and Koffman-1978).

The program has the following statement, which I can't figure out:

a) IF ( IEGEN ) 15 , 10 , 15
b) 10 DO 14 I = 1 , N
c) DO 14 J = 1 , N

d) IF ( I = J ) 12 , 11 , 12

e) 11 U ( I , J ) = 1
f) GO TO 14
g) 12 U ( I , J ) = 0
h) 14 CONTINUE
g) 15 NR = 0 (program code continues on.

I think that I understand line a) in that if IEGEN is -1, 0, +1 it branches to 15 , 10, or 15.
You're not too far off. If IEGEN is any negative number, control passes to line 15. If it's zero, control branches to line 10. Finally, if IEGEN is any positive number, control branches to line 15. In summary, if IEGEN is nonzero, control goes to line 15, and to line 10 if IEGEN is zero.

BTW, this form of IF statement is very old. I believe that it is obsolete in F90 and later. IIRC correctly it's called an "arithmetic if" statement.
msmolen said:
The program seems to always enter with the value of 0 and so branches to line b) and builds an array.

But what is the decision metric in line d)? In the IF I = J decision, what is -1 , or 0, or +1?
If I = J the value would be equal to zero? But how does one get -1 or +1 out of this?
To be honest, I don't know what this code does. To compare for equality, Fortran 77 used the .EQ. operator rather than '='.

It could be that the = operator in IF(I = J) 12, 11, 12 is intended to assign the value in J to the variable I. If so, if J was negative or positive, line 12 was executed. If J was zero, line 11 executed.
msmolen said:
Any help for me to understand this statement would be greatly appreciated.
 
  • Like
Likes   Reactions: 1 person
msmolen said:
But what is the decision metric in line d)? In the IF I = J decision, what is -1 , or 0, or +1?
If I = J the value would be equal to zero? But how does one get -1 or +1 out of this?

That looks wrong in any version of Fortran I have ever used. (Neither of Mark44's attempts at interpretation are valid fortran, but explaining why is probably "too much information").

I suspect it's a typo for
Code:
IF ( I - J ) 12 , 11 , 12
which would look like this in C:
Code:
IF ( I == J ) 
   U ( I , J ) = 1;
else
   U ( I , J ) = 0;
14  CONTINUE

And the first test would be equivalent to
Code:
IF (IEGEN == 0) {
   DO 14 I = 1 , N 
   ...
   14  CONTINUE
}
15  NR = 0 (program code continues on.

So the code does this:

"If IEGEN is 0, set U to an N x N identity matrix."
 
Last edited:
  • Like
Likes   Reactions: 1 person
The Relational Operators, .EQ., .NE., .GT., .LT., .GE., and .LE., have been incorporated into Fortran since the 1960s, not just Fortran 77. Now, these operators are expressed as ==, /=, >, <, >=, and <= in the modern versions of Fortran, but the old operators should still be recognized since F77 is also a subset of F90.

It's possible that statement d) in the OP has a typo: perhaps it should read IF (I - J) 12, 11, 12

Branching would occur as in the Arithmetic IF depending on how the expression I - J evaluated: Branching to statement label 11 would occur only for I - J = 0, or I = J, in other words.
 
Thanks for your suggestion and comments. I makes me wonder if we, at the cutting edge of a language, are going to be the questions of our peers in the future. Scary. Mike
 
msmolen said:
I makes me wonder if we, at the cutting edge of a language, are going to be the questions of our peers in the future. Scary. Mike

The future always has questions for the past. As the Germans say, "Immer schon!"

Program source code used to be stored on punch cards. You could get a program listing by dumping the card deck into a card reader and having the output from the reader directed to a printer. However, if a couple of cards went missing from the deck, the card reader wouldn't notice, and neither would the printer. The user would think his printout contained the entire program, but he couldn't be sure until personally reading the program listing or trying to run the program.
 
SteamKing said:
The future always has questions for the past. As the Germans say, "Immer schon!"

Program source code used to be stored on punch cards. You could get a program listing by dumping the card deck into a card reader and having the output from the reader directed to a printer. However, if a couple of cards went missing from the deck, the card reader wouldn't notice, and neither would the printer. The user would think his printout contained the entire program, but he couldn't be sure until personally reading the program listing or trying to run the program.
That's what the last 8 card columns were for. You punched a serial number in those columns (usually counting by 10s or 100s, to make room for edits). Then when you dropped your deck (more common than loosing a card), you could use the IBM 84 high speed card sorter (made famous by "Mannix") to put them back in order.