Fortran branching statement confusion

In summary, the code in line d) checks to see if IEGEN is equal to J. If it is, the program code jumps to line 14. If IEGEN is not equal to J, the code continues on to line 15.
  • #1
msmolen
6
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
  • #2
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
  • #3
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
  • #4
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.
 
  • #5
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
 
  • #6
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.
 
  • #7
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.
 

1. What is a branching statement in Fortran?

A branching statement in Fortran is a control flow statement that allows the program to make decisions and execute different parts of code based on certain conditions. It is used to alter the normal sequence of execution in a program.

2. What are the different types of branching statements in Fortran?

There are three types of branching statements in Fortran: IF statements, SELECT CASE statements, and DO loops. IF statements allow the program to execute a block of code if a condition is met. SELECT CASE statements allow the program to choose from multiple cases based on a given expression. DO loops allow the program to repeat a block of code a certain number of times or until a condition is met.

3. How do I properly use branching statements in my Fortran program?

To use branching statements in Fortran, you must first declare the statement, followed by a condition or expression to be evaluated. Then, you must specify the code to be executed if the condition is met. It is important to properly format and nest the statements to ensure the correct execution of your program.

4. Can I combine multiple branching statements in my Fortran program?

Yes, you can combine multiple branching statements in your Fortran program. This is often done to create more complex decision-making processes or to handle multiple conditions. However, it is important to use proper syntax and to avoid nesting statements too deeply to prevent confusion and errors.

5. Are there any common errors or pitfalls associated with branching statements in Fortran?

One common error with branching statements in Fortran is forgetting to include an ELSE statement or a default case in SELECT CASE statements. This can result in unexpected behavior or errors during program execution. It is also important to properly debug and test your code to ensure that the correct branch is being executed.

Similar threads

  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
7
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
9
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
12
Views
1K
Back
Top