This Is Not Your Father’s FORTRAN

I learned to program FORTRAN IV in the spring of 1968 while working as an engineering technician in water resources. One of the engineers knew of my interest in computers and asked if I would like to learn FORTRAN. He needed to calculate the biological oxygen demand in streams but didn’t have any interest in programming. I jumped at the chance.

415I2ZfVyqL._SX258_BO1,204,203,200_This was the days of big iron when the term computer meant a room full of heavily air-conditioned equipment. The State University of New York at Buffalo had an IBM 704 but they soon upgraded to a CDC 6400. To help pay for it they were inviting people to attend a seminar on FORTRAN so they could use the system. My job was with a small State of NY office and getting approval for me to attend was surprisingly easy.

Off I went for 6 weeks of training on one night a week. I still have my black “A Guide to Fortran IV Programming” by [Daniel McCracken]. For years, this was the FORTRAN bible, commonly referred to as just “McCracken”.

The programming went well and somewhere out there is a very old paper with a reference to the results it generated about the Chadakoin River flowing through Jamestown, NY.

This is FORTRAN’s strength – scientific calculations. It’s name says it: FORmula TRANslation.

Origins and FORTRAN IV

[John W. Backus] suggested to IBM a language to replace assembly language. Development began in 1953 for the IBM 704 and the project reached fruition in 1957. Not only was it the first general purpose high-level language, just beating out COBOL and LISP, but its compiler optimized the code since it needed to compete head-on with assembly language. It was the C compiler of its day in that regard.

That was not the only reason it attained success. Reducing the number of punched cards needed for a program by a factor of 20 over assembly helped considerably.

In those days, you needed to use a key punch to create a deck of punch cards. To be really good you had to know how to create a programming card that would let you skip through the fields on a FORTRAN card, or how to edit a card by duplicating it and holding one of the cards in place while you typed in new characters. Because of my fascination with computers I’d taken a key punching and automation machines class in high school so I was all set.

A FORTRAN card begins with a field of 5 characters. If the first character was a ‘C’ is was a comment card. Otherwise the characters were either blank or a line number. The line number provided the destination for GOTOs.

fortran cardThe sixth character could be anything except a ‘0’, which meant the card was a continuation of the previous card. A good practice was to use characters in sequence so you could tell the order of continuation.

Columns 7 to 72 were for program statements. The remainder, from 73 to 80, were not used by the compiler. The intent was to put sequence numbers in those cards so when the deck inevitably was dropped, or the card reader ate it, you could sort the cards into proper order again. A box of cards contained 2,000 cards and trays about 5,000. I’ve seen programmers literally cry when a card or tray dropped with cards that were not sequenced. I worked as an operator at SUNY at Buffalo on that CDC 6400 and loaded programs and data that spanned multiple trays of cards.

The character set for FORTRAN was:


A .. Z 0 .. 9 = + - * / ( ) , . $

A space, interestingly enough, was not a character. They were totally ignored. A variable named XYZ was valid in that form, as X YZ, or as XY Z.

Variable names were limited to 6 characters and had to start with a letter. The letter I-N as the first letter implicitly meant the variable was an integer. All other letters meant a real number. This could be overridden by explicitly typing a name:

INTEGER ABC, XYZ
REAL IMREAL
LOGICAL TRUE, FALSE

The other data types were COMPLEX, CHARACTER, and DOUBLE PRECISION.

Arrays were declared with the DIMENSION statement:

DIMENSION XY(100), AB(2000, 3) 

Data initialization used DATA:

DATA A, B, C, D, E, F /0, 1, 2, 5*3/

One of the interesting control structures was the arithmetic IF statement. The value in the statement was tested for being greater than, equal to, or less than zero. Depending on the result the statement jumped to one of the three line numbers following the statement:

IF (NONZERO) 100, 200, 300 

There was an IF statement that tested for .TRUE., as FORTRAN deemed the value. IF statements could not be nested.

There was only one loop statement, the DO, which could be nested:

DO 200 I = 0, 10, 3
C do some calculations, I starts at zero,
C increments by 3, and exits when it exceeds 10
C The next line is the end of the loop
200 CONTINUE

FORTRAN IV did have SUBROUTINEs and FUNCTIONs that were entered using a CALL statement and exited with a RETURN.

Here is a list of the other program statements allowed in FORTRAN IV:

EQUIVALENCE
GOTO, GOTO, ASSIGN, assigned GOTO
DO
FORMAT
READ, READ INPUT TAPE, WRITE, WRITE OUTPUT TAPE, PRINT, and PUNCH
READ TAPE, READ DRUM, WRITE TAPE, and WRITE DRUM
LOGICAL
END FILE
REWIND
BACKSPACE
PAUSE
STOP
FREQUENCY
END
COMMON

See if you can decipher this FORTRAN IV program for calculating the area of a triangle.

C AREA OF A TRIANGLE - HERON'S FORMULA
C INPUT - CARD READER UNIT 5, INTEGER INPUT, ONE BLANK CARD FOR END-OF-DATA
C OUTPUT - LINE PRINTER UNIT 6, REAL OUTPUT
C INPUT ERROR DISPAY ERROR MESSAGE ON OUTPUT
 501 FORMAT(3I5)
 601 FORMAT(4H A= ,I5,5H B= ,I5,5H C= ,I5,8H AREA= ,F10.2,12HSQUARE UNITS)
 602 FORMAT(10HNORMAL END)
 603 FORMAT(23HINPUT ERROR, ZERO VALUE)
     INTEGER A,B,C
  10 READ(5,501) A,B,C
     IF(A.EQ.0 .AND. B.EQ.0 .AND. C.EQ.0) GO TO 50
     IF(A.EQ.0 .OR. B.EQ.0 .OR. C.EQ.0) GO TO 90
     S = (A + B + C) / 2.0
     AREA = SQRT( S * (S - A) * (S - B) * (S - C) )
     WRITE(6,601) A,B,C,AREA
     GO TO 10
  50 WRITE(6,602)
     STOP
  90 WRITE(6,603)
     STOP
     END

Code from https://en.wikibooks.org/wiki/Fortran/Fortran_examples.

GOTO the Future

Despite its age Fortran, as it is now called, continues to survive and possibly even prosper at its job of scientific and engineering calculations. It is true that C++ is now making inroads, but it has a long way to go before it is the king of calculations.

One reason Fortran does well is the extensive collection of legacy code from the previous decades. You don’t rewrite code that took man decades to produce, is debugged, and known to work well. Even the open-source community recognizes this since the GNU compiler suite, usually known for C and C++, includes a modern Fortran compiler. This isn’t really surprising because after the first phases of compilation are completed the generation of the machine code is common to all of the suites’ languages. Those first phases are the easy part.

The language has been regularly updated by the standards committees, including the ANSI standards group once it came into existence. FORTRAN IV came out in 1962. It was followed by updates in ’66, ’77, ’90, ’95, 2003, and 2008. Work is currently proceeding on Fortran 2015 to be released in 2018.

Along the way it lost its fixed format lines and became free form like other modern languages. It also lost its line numbers. The arithmetic IF met its demise.

Today the language carries most of the features you’d expect: do-while, recursion, select-case (switch-case equivalent), dynamic memory allocation, and even object-oriented capabilities.

One capability added is the ability to handle matrix operations. This is sensible given its usage for scientific calculations. Still, Fortran today is relying more and more on libraries written in C/C++, so much so that the specifications include compatibility guidelines for using those languages.

It’s Not Dead, Jim

The language isn’t dead, although it doesn’t show up on the popularity charts. A quick search on LinkedIn found 9 jobs in Houston, and many more around the US, with the requirement of knowing Fortran. Most also wanted C/C++ which reflects how the three languages are commingling. I would expect most of those who use Fortran aren’t using it for hacking so GitHub doesn’t see many uploads, which seems to be a main measure of popularity.

Additionally, Fortran is a niche language and I mean that in a positive sense. Where Fortran is used, it is the language to use. That is, of course, high performance and scientific computing. A few specifics are weather forecasting, climate modeling, and computational physics, astronomy, chemistry, and economics. It’s used by investment houses for financial modeling. According to [Adam Fabio] Fortran based air-control systems are still in use. Think about that the next time you fly.

Is Fortran a career path to recommend to your college age children or friends? Probably not. Although they may need to learn it for careers in the fields mentioned above. It’s not likely to show up as a language used for Arduinos, but you may be able to install in on a Raspberry Pi.

Fortran is still out there doing what it does best: crunching numbers.

Here’s a promise. I’ll write up the first hacker who notifies Hackaday on the tip line that they created a Fortduino.

109 thoughts on “This Is Not Your Father’s FORTRAN

  1. Oh my! I’ve wandered into the middle of a group of the younger generation. I was going to compose a dissertation on my life in the wonderful world of FORTRAN but decided than no one would really be interested.. Suffice it to say I began my time in the world of FORTRAN at the end of the days of punched paper tape. All of these stories bring back memories (some horror, some amusing). Anyway, enjoy the computers and don’t let anyone but in line ahead of you at the keypunch. Especially at 3:30 in the morning.

  2. Thank you for bring up the memories of my first foray into programming. I remember sometimes the KP 29 key punch machine at our school would not have ink and so the code wouldn’t be visible, and we had to read and interpret the holes to make sure the syntax was correct. In addition to the FORTRAN code, I’m trying to remember the JCL commands we needed to add in the beginning for the program to be executed on our school’s IBM 360 computer.

Leave a Reply to Silvio ArditoCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.