Fortran branching statement confusion

  • Context: Fortran 
  • Thread starter Thread starter msmolen
  • Start date Start date
  • Tags Tags
    Confusion Fortran
Click For Summary

Discussion Overview

The discussion revolves around understanding specific FORTRAN branching statements within a program for computing Canonical Correlates, as published in a book on Multivariate Morphometrics. Participants are attempting to clarify the logic behind certain lines of code, particularly focusing on the use of conditional statements and potential typos in the code as they consider translating it into PERL.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant interprets the first IF statement as branching based on the value of IEGEN, suggesting that it directs control to specific lines based on whether IEGEN is negative, zero, or positive.
  • Another participant agrees with the interpretation of the first IF statement but questions the logic of the second IF statement, asking how it could yield -1, 0, or +1 when checking if I equals J.
  • A different participant suggests that the second IF statement might be a typo and proposes that it should read IF (I - J), which would clarify the intended logic of checking equality.
  • There is a discussion about the historical context of relational operators in FORTRAN, with one participant noting that the operators have been present since the 1960s and that the old syntax should still be recognized.
  • Another participant reflects on the evolution of programming practices, sharing anecdotes about the challenges of using punch cards for program storage and the potential for missing information in program listings.

Areas of Agreement / Disagreement

Participants express differing interpretations of the code, particularly regarding the second IF statement. There is no consensus on the correct interpretation or the presence of a typo, indicating that multiple competing views remain.

Contextual Notes

Participants note the possibility of typos in the original FORTRAN code, particularly in the second IF statement, which could affect the understanding of the program's logic. The discussion also highlights the historical context of programming languages and practices.

Who May Find This Useful

Individuals interested in FORTRAN programming, code translation, or the historical context of programming languages may find this discussion relevant.

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

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K