Mystified by statement in old FORTRAN code

KevinKillion
01-15-2011, 02:11 AM
Help! I am trying to port an old statistical routine, and have run into a hard roadblock. (This is not about NR specifically, but I own three of the NR books, so please look kindly upon me!)

The problem is in "KYST", an old program to do multidimensional scaling. Here is an excerpt of where I'm tearing my hair out:

SUBROUTINE CONFIG(N,ND)
C
DIMENSION DATA(1800),WW(1800),IJ(1800),X(100,6)
DIMENSION STORE(494),RWMEAN(100),ROOTS(6),XBEST(100,6)
REAL MEAN
COMMON /KYST1/ DATA,WW,X,IJ
COMMON /KYST2/ STORE,RWMEAN,ROOTS,XBEST
C
ISUB(I1,I2)=((I2-1)*(I2-2))/2+I1
MEAN=0.0
FN=N
C
DO 130 J=1,N
RWMEAN(J)=0.0
DO 129 I=1,N
IF(I-J) 126,129,127
126 IJC=ISUB(I,J)
GO TO 128
127 IJC=ISUB(J,I)
128 RWMEAN(J)=DATAIN(IJC)**2+RWMEAN(J)
129 CONTINUE
...
...
...

(Posting here removes the FORTRAN-style formatting for the first 6 card columns; in the original the statements start in card column 7 and the statement numbers are where they should be.)

Here's the problem: What on earth is that line that starts "ISUB(I1,I2)=..."??????? It looks like ISUB is an array, but it isn't defined anywhere in the source code. Moreover, the variables I1 and I2 aren't defined or assigned anywhere, and yet they are used in the first assignment in this routine! Worse, the values in ISUB are used later, in the statements numbered as 126 and 127. (It almost looks like some kind of one-line subroutine definition, but I've never heard of anything like that in FORTRAN, yes?)

If you want to see the full source listing, it is at:
http://www.netlib.org/mds/kyst2a.f

Many thanks for any help!!!
Kevin Killion

davekw7x
01-15-2011, 07:51 AM
...Here is an excerpt of where I'm tearing my hair out...It almost looks like some kind of one-line subroutine definition... That is not an assignment statement. It's called a statement function. Such things have been around since the days of FORTRAN II (This was the 1960's, when the FORTRAN was completely managed by IBM. None of this Standards Committee stuff. It was an acronym, not a proper noun, so we used all upper-case letters, and versions were numbered with Roman Numerals, like world wars).

One reference on statement functions:http://www.obliquity.com/computer/fortran/function.html
A reference that gives an example using a statement function in a Fortran 90 program that actually looks like Fortran 90 and not FORTRAN II:http://docs.hp.com/en/B3908-90002/ch07s05.html

Posting here removes the FORTRAN-style formatting for the first 6 card columns Put code tags around the code, not quote tags:

When composing a post, highlight the code (not the narrative, just the program statements), and click the "#" icon near the top of the edit window. Use the "Preview Post" button to see if it looks right.

C THE FOLLOWING IS A STATEMENT FUNCTION:
ISUB(I1,I2)=((I2-1)*(I2-2))/2+I1

Note that in the time-honored tradition of all Fortrans, if you don't declare data types for variables, identifiers starting with I, J, K, L, M, and N are implicitly INTEGERs and others are REALs. Nowadays we like to declare all variables explicitly, and maybe even throw in "implicit none" at the beginning of the program so that misspellings of variable names may caught by the compiler, but you shouldn't be confused if some (or all) variables are not declared, especially in legacy programs.

Regards,

Dave

KevinKillion
01-15-2011, 09:37 AM
Many, thanks, Dave! I thought I was goin' nuts there. My first computing job was in programming FORTRAN long ago, but I don't recall that juicy little landmine (as befits your wry observation that FORTRAN was numbered in Roman numerals, like world wars).