Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran branching statement confusion

  1. May 12, 2014 #1
    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.
  2. jcsd
  3. May 12, 2014 #2


    Staff: Mentor

    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.
    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.
  4. May 12, 2014 #3


    User Avatar
    Science Advisor
    Homework Helper

    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 (Text):

    IF ( I - J ) 12 , 11 , 12
    which would look like this in C:
    Code (Text):

    IF ( I == J )
       U ( I , J ) = 1;
       U ( I , J ) = 0;
    14  CONTINUE
    And the first test would be equivalent to
    Code (Text):

    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: May 12, 2014
  5. May 12, 2014 #4


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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.
  6. May 12, 2014 #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
  7. May 12, 2014 #6


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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.
  8. May 13, 2014 #7
    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook