[Next] [Up/Previous] [Home] [Other]

FORTRAN

Initially, FORTRAN was devised for the IBM 704 computer. This was a computer built using vacuum tubes. It had a strong resemblance to its predecessor, the IBM 701, in terms of its physical appearance.

But it differed in two very important ways from its predecessor.

The IBM 701 computer did have random-access memory, but this memory was in the form of Williams tubes, the reliability of which was limited. The IBM 704, on the other hand, used core memory, which was, in practice, reliable enough that you could simply use it and forget about it (despite not being absolutely perfect).

The IBM 701 computer performed arithmetic on 36-bit integers, but its instructions were simple ones that were each 18 bits long. The IBM 704 had a much more complex instruction set, which included instructions to perform floating-point arithmetic, and so its instructions occupied a full 36-bit word.

Because it already had built-in floating-point instructions, it did not need to supplement its assembly language with a simplistic system aimed at making it easier to write programs that performed floating-point operations without coding one subroutine call after another, a category to which a few of the higher-level languages that preceded FORTRAN belonged.

Instead, because of the presence of floating-point hardware, the development team working on FORTRAN felt it to be very important to develop a compiler that would produce optimized machine code. Using a higher-level language, then called "automatic programming", was a new idea at that time, and therefore overcoming skepticism about its merits was a major consideration.

A FORTRAN program might have looked like this:

      FREQUENCY 14(50),24(100,1,100),34(100,1,100),44(100,1,100),
     * 54(100,1,100)
C     PROGRAM TO CALCULATE THE APPARENT POSITION OF A PLANET OR
C     ASTEROID, GIVEN ITS ELEMENTS, AS SEEN FROM EARTH
C     THIS PROGRAM PRODUCES AN APPROXIMATE ANSWER, AS IT DOES NOT
C     ATTEMPT TO TAKE PERTURBATIONS INTO ACCOUNT
      RTD = 57.29578
      DTR = 1.0/RTD
   10 FORMAT( 4F12.5 )
C     READ IN THE ELEMENTS OF THE ORBIT OF THE EARTH
      READ 10, EANIN, EANPD, EECCE, ELOPE
C     THE FOLLOWING STATEMENT IS NOT NEEDED
C     ESMAX = 1.0
C     READ IN THE ELEMENTS OF THE ORBIT OF THE OTHER PLANET
      READ 10, PANIN, PANPD, PECCE, PLOAN
      READ 10, PINCL, PARGPH, PSMAX
   20 FORMAT( 2I5 )
C     READ IN STARTING DAY AND NUMBER OF DAYS
      READ 20, IBEG, IEND
      START = FLOATF( IBEG )
      EMAN = EANIN + EANPD * START
      PMAN = PANIN + PANPD * START
C     PRECALCULATE SQRT((1+E)/(1-E)) FOR EACH BODY
      EANCV = SQRTF((1.0+EECCE)/(1.0-EECCE))
      PANCV = SQRTF((1.0+PECCE)/(1.0-PECCE))
C     PRECALCULATE THE SINE AND COSINE OF THE INCLINATION
      SININ = SINF(PINCL)
      COSIN = COSF(PINCL)
   11 FORMAT( 1H , I5, 1H , F12.5, F12.5 )
   14 DO 7 I = IBEG, IEND, 1
      AMAN = PMAN
      AECCE = PECCE
      ASMAX = PSMAX
      AANCV = PANCV
      ASSIGN 15 TO ITARR
      GO TO 108
   15 PTANO = ATANO
      PDIST = ADIST
      AMAN = EMAN
      AECCE = EECCE
      ASMAX = 1.0
      AANCV = EANCV
      ASSIGN 25 TO ITARR
      GO TO 108
   25 ETANO = ATANO
      EDIST = ADIST
      ELON = ETANO * RTD + ELOPE
   24 IF ( ELON - 180.0 ) 65,55,55
   55 ELON = ELON - 360.0
   65 ELON = ELON * DTR
      EX = EDIST * SINF(ELON)
      EY = EDIST * COSF(ELON)
      PARGTA = PTANO * RTD + PARGPH
   34 IF ( PARGTA - 180.0 ) 85,75,75
   75 PARGTA = PARGTA - 360.0
   85 PARGTA = PARGTA * DTR
C     DETERMINE THE POSITION OF THE PLANET IN ITS OWN
C     ORBITAL PLANE
      PX1 = PDIST * COSF(PARGTA)
      PY1 = PDIST * SINF(PARGTA)
C     MOVE TO THE ECLIPTIC PLANE
      PY2 = PY1 * COSIN
      PZ2 = PY1 * SININ
C     THEN CONVERT TO POLAR TO OBTAIN CONVENTIONAL
C     COORDINATES
      X = PX1
      Y = PY2
      PROJR = SQRTF(X*X+Y*Y)
      ASSIGN 95 TO IREPOR
      GO TO 208
      PLONG = DTR*(THETA+PLOAN)
      PX3 = PROJR * COSF(PLONG)
      PY3 = PROJR * SINF(PLONG)
      X = PX3 - EX
      Y = PY3 - EY
      DIST = SQRTF(X*X+Y*Y)
      ECLAT = ATANF(PZ2/DIST)
      ASSIGN 185 TO IREPOR
      GO TO 208
  185 PRINT 11, I,THETA,ECLAT
      EMAN = EMAN + EANPD
      PMAN = PMAN + PANPD
    7 CONTINUE
      STOP
C
C     SUBROUTINE TO FIND THE TRUE ANOMALY FROM THE MEAN
C     ANOMALY
  108 RMAN = AMAN * DTR
C     THE EQUATION
C     ECCENTRIC ANOMALY - ECCEN * SIN( ECCENTRIC ANOMALY )
C     EQUALS MEAN ANOMALY
C     IS USED TO FIND THE ECCENTRIC ANOMALY FROM THE MEAN
C     ANOMALY BY ASSUMING THE ECCENTRICITY IS SMALL, SO
C     THE MEAN ANOMALY IS A GOOD FIRST APPROXIMATION TO
C     THE ECCENTRIC ANOMALY
      REAN1 = RMAN
   35 REAN2 = RMAN + AECCE * SINF( REAN1 )
   44 IF ( ABSF( REAN2 - REAN1 ) - 0.00001 ) 45,45,35
   45 SHEA = SINF(0.5*REAN2)
      CHEA = COSF(0.5*REAN2)
      ATANO = 2.0 * ATANF(AANCV*SHEA/CHEA)
      ADIST = ASMAX * (1.0 - AECCE * COSF(REAN2)
C     RETURN FROM THIS SUBROUTINE
      GO TO ITARR,(15,25)
C
C     SUBROUTINE TO CONVERT FROM RECTANGULAR TO POLAR
C     COORDINATES
  208 SX = SIGNF(1.0,X)
      SY = SIGNF(1.0,Y)
      AX = ABSF(X)
      AY = ABSF(Y)
   54 IF (AY-AX) 105,115,125
  105 THETA = RTD * ATANF(AY/AX)
      GO TO 135
  115 THETA = 45.0
      GO TO 135
  125 THETA = 90.0 - RTD * ATANF(AX/AY)
  135 IQUAD = XINTF(3.0+SY+0.5*SX)
C     THE VALUE OF IQUAD IS
C     INT(1.5) OR 1 IF SX AND SY ARE BOTH -1, OR
C     1 IF X IS NEGATIVE AND Y IS NEGATIVE
C     2 IF X IS POSITIVE AND Y IS NEGATIVE
C     3 IF X IS NEGATIVE AND Y IS POSITIVE
C     4 IF X IS POSITIVE AND Y IS POSITIVE
      GO TO (145,155,165,175),IQUAD
  145 THETA = THETA - 180.0
      GO TO 175
  155 THETA = 0.0 - THETA
      GO TO 175
  165 THETA = 180.0 - THETA
C     RETURN FROM THIS SUBROUTINE
  175 GO TO IREPOR,(95,185)

In this example, I've cheated a bit. The manual for the original FORTRAN describes built-in functions (such as FLOATF and ABSF, used above), but while it mentions that library functions can be included on the FORTRAN master tape, it does not say if any functions are included as standard; I used the SINF, COSF, and ATANF functions that would be included as standard with the version of FORTRAN II that was available for the IBM 704 rather than writing my own trig function routines.

Also, the STOP statement actually halts the computer, and indicates the program is finished by not permitting the program to be restarted. The computer would be restarted to begin work on the next problem.

Of course, a real program to calculate planetary positions would output multiple results per line, and would work with calendar dates instead of simply an integer number of days from the date for which the true anomaly is given. (There would also be provision for the true anomaly being given for different dates for the two planets involved.) These complications have been omitted to keep this example, already large enough to be realistic, from becoming too complicated.

Although the integer arithmetic instructions on the IBM 704 worked with 36-bit integers, its index registers were only 15 bits wide. Thus, fixed-point variables in the original FORTRAN language varied from -32767 to +32767 in value only.

A fixed-point variable was indicated by a name starting with a letter from I through N; variables whose name began with any other letter were floating-point.

An array subscript did not have to be only a constant or a variable, but it could not be any expression; it had to be of a form which was, at its most general, something like 5*J-3; a constant times a variable, plus or minus a constant.

Line numbers ranged from 1 to 32767 only as well.

Variable names were from one to six letters long; the first character had to be a letter, and the remaining characters could also be numbers.

The name of a function is from four to seven characters in length, however. The last letter of the function's name is F, to indicate that it is the name of a function, and a conflict of names, which is not permitted, results if a variable is given the same name as a function without the ending F. The names of arrays (subscripted variables) cannot end in F, but ordinary variables can have names ending in F, because they are syntactically distinct.

The console of the IBM 704 computer included six sense switches, and four sense lights, which were present for communicating with programs while they were running. Special statements were included in the original FORTRAN language to communicate with them:

      IF (SENSE SWITCH 3) 10,20

would branch to statement 10 if sense switch 3 was on, and statement 20 if sense switch 3 was off. An IF (SENSE LIGHT n) statement of the same general form also existed.

The statement

      SENSE LIGHT 3

turned on sense light 3, and the statement

      SENSE LIGHT 0

turned off all the sense lights.

A version of the original FORTRAN language was made available, under the name FOR TRANSIT, for the IBM 650 computer. Variable names were limited to five characters in length instead of six, and line numbers could only be four digits long. Because of limitations in the way in which the card reader on the IBM 650 worked, depending on whether or not a "special character device" was present at an installation, instead of the text of a statement being limited to columns 7 to 72 of a punched card, it was limited either to columns 7 to 26 or to 7 to 36 of the card.

FORTRAN for the IBM 650 also had the restriction to columns 7 through 36 and four-digit statement numbers.

The IBM 1620 computer had a version of FORTRAN II written for it which omitted the ending F from the end of subroutine names, like FORTRAN IV, but which otherwise followed the lines of the original FORTRAN language, including not having the FUNCTION and SUBROUTINE statements.

GOTRAN was also devised for the IBM 1620; it did not allow more than one operation in an expression, and thus was too restricted to be considered a dialect of FORTRAN.

Copyright (c) 2007 John J. G. Savard


[Next] [Up/Previous] [Home] [Other]