Fortran Fortran branching statement confusion

  • Thread starter Thread starter msmolen
  • Start date Start date
  • Tags Tags
    Confusion Fortran
AI Thread Summary
The discussion revolves around translating a FORTRAN program from "Multivariate Morphometrics" into PERL, specifically focusing on understanding certain FORTRAN code segments. The initial confusion stems from an arithmetic IF statement, which directs program flow based on the value of the variable IEGEN. If IEGEN is negative or positive, the program branches to line 15; if zero, it goes to line 10, where it begins a loop to build an array. The key point of confusion is line d), which checks if I equals J. It is suggested that this line may contain a typo and should instead use an expression like "IF (I - J)" to determine equality, which would correctly set values in the array U. The conversation highlights the evolution of programming languages and the potential for misunderstandings in older code syntax. The participants also reflect on the historical context of programming, including the use of punch cards, illustrating the challenges of maintaining and interpreting legacy code.
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 descision metric in line d)? In the IF I = J descision, 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.
 
Technology 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 descision metric in line d)? In the IF I = J descision, 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 1 person
msmolen said:
But what is the descision metric in line d)? In the IF I = J descision, 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 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.
 

Similar threads

Replies
3
Views
2K
Replies
12
Views
2K
Replies
4
Views
2K
Replies
5
Views
5K
Replies
5
Views
2K
Replies
2
Views
2K
Replies
1
Views
3K
Replies
2
Views
1K
Back
Top