FORTAN Code: A Very Old Language for Numerical Computing

Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more

If you have any experience with programming, you can learn Fortran in a couple of hours. It is an amazingly easy language, yet very powerful.

And to give you some idea of that power, consider this: it first appeared in 1957 and is still used today to solve some of the most complicated problems in modern science and engineering.

A Very Brief History of Fortran

In order to understand the history of Fortran, we have to go back to the earliest modern computers.

Assembly Language

In the 1940s, the computers were all programmed with assembly language — giving the computer direct instructions. For example, imagine you wanted to add two integers on 1954’s cutting edge computer the IBM 704. You would have to write something like this (pdf):

CLA 100
ADD 101

CLA tells the computer to clear the Accumulator Register and add to it the value stored at memory location 100. Then the ADD command tells the computer to add the value stored at memory location 101 to the value stored at the Accumulator Register.

This is already complicated and we haven’t even discussed how to store the values at memory locations 100 and 101!

Enter FORTRAN

Clearly, this kind of coding is laborious and incredibly prone to error. So in late 1953 — shortly before the IBM 704 was to be released — computer scientist John W Backus submitted a proposal to create a high level language that would allow programmers to write simple statements like I = 10 + J.

Then the compiler could convert this into the many lines of assembly language the computer required. And by late 1956, the first FORTRAN manual (pdf) was released. And six months later, the first compiler to convert Fortran into assembly language was released.

FORTRAN was not the first high level programming language. But it was the first one to be widely used. And there are good reasons for that.

Fortran Evolution

Although the first Fortran compiler was released in 1957, the language continued to grow and evolve.

FORTRAN II

Released in 1958, FORTRAN II introduced subroutines and functions. These were critical facilities because they allowed for the development of well structured code.

These features allowed programs to call the same blocks of code to be called multiple times without repeating the code or using GOTO calls. The main differences between these two things is that subroutines did not return variables like functions did.

FORTRAN IV / FORTRAN 66

FORTRAN IV was a very important milestone. In particular, it removed machine-dependent features and introduced logical (Boolean) features to the language.

But FORTRAN IV was more important because it became more or less the standard FORTRAN for the programming community. This was most due to the fact that FORTRAN 66 was released right after FORTRAN IV.

And FORTRAN 66 was the first version to haven an official American National Standards Institute (ANSI) version.

FORTRAN 77

Because of its timing, FORTRAN 77 is the version most people think of when they think of the language. It added a number of important functions.

For example, although FORTRAN IV had IF statements (including three-way IF statements), it wasn’t until FORTRAN 77 that ELSE and ELSE IF functions were allowed. It also greatly advanced file I/O and character processing abilities.

Fortran 90

This represented a huge change in the language as can be seen simply by the fact that the name of the language was no longer printed with all capital letters. It allowed Fortran commands to be written in lower case and implemented free-form source input.

But it also implemented much more sophisticated features like operator overloading. At the same time, it did not remove any features, so that Fortran 77 programs still worked exactly as they had before.

Fortran 2015

There have been a number of updates to the language since Fortran 90: Fortran 95, Fortran 2003, Fortran 2008, and the upcoming Fortran 2015. All of these are minor updates.

Nothing substantial has happened to the language since Fortran 90, or even FORTRAN 77 since its code will still generally compiles without change.

Why Do People Use Fortran?

If you want to perform numerical calculations, there really isn’t a better language. Because it has been around so long, Fortran compilers have been optimized to perform calculations.

But perhaps the best reason to use Fortran is that there is an enormous amount of existing code for the sorts of things that scientific programmers do all the time.

Consider this: Numerical Recipes: The Art of Scientific Computing has been an essential book for all scientific programmers for decades. When it first came out in 1986, it was written with all Fortran examples.

There was no mention of this fact on the cover. It was just assumed. It took three years before a special edition of the book came out with Pascal code. It took six years before a C language version came out.

What Makes Fortran So Easy?

Basic Fortran only does simple things. All the aspects of it like loops and if-then statements are so integrated in other languages that it is unlikely that you will have any trouble picking it up.

The only thing about it that might be a bit difficult is that Fortran requires a highly structured input format — or at least Fortran 66 and Fortran 77 did. Fortran 90 and onward is far more flexible.

But if you are working with Fortran, chances are that you will dealing with the older versions of the code.

Fortran 77 Example


      program sequence
c Lines that start with c (or *) are comments
* This program will print out a simple arithmetic series
      integer n, i
      n = 0
      do 10 i = 1, 5
        n = n + i
        write(*,*) "The ", i, "number in this series "
     +"is: ", n
  10  continue
      stop
      end

There are a few things to notice here:

  • Regular code must start on the seventh column (that is, with six spaces before it).

  • If a “c” or an “*” is placed in the first column, it is a comment and not compiled.

  • Columns 1-5 can be used for statement labels — similar to old style BASIC.

  • If a character is placed in column 6, it means that the code from the previous line is continued. This is important because statements can only be placed from the 7th to the 72th column.

The output should be pretty clear:

The 1 number in this series is 1
The 2 number in this series is 3
The 3 number in this series is 6
The 4 number in this series is 10
The 5 number in this series is 15

Learning Fortran

You have a few alternatives in how you learn Fortran.

Fortran Tutorials

Fortran really is a very simple language to learn if all you need to do is create programs for solving numerical problems. Clearly, it is not the choice of people writing graphical user interfaces.

But for scientists and engineers, Fortran is often the best tool for the job. With these tutorials, you will probably be able to be ready to write your own useful programs within a couple of hours.

Fortran Books

There are a surprising number of books about the Fortran programming language. You may find these the quickest and easiest way to get started with the language.

Fortran Compilers

There are a number of compilers available. See Wikipedia’s list of Fortran compilers. A few deserve special discussion:

  • GNU Fortran: the official Fortran compiler (compatible with Fortran 95) that is part of the GNU Compiler Collection.

  • G95: a free Fortran 95 compiler that is in active development and is implementing parts of Fortran 2003 and 2008.

  • MinGW: a port of the GNU Compiler Collection (including Fortran) for the purpose of creating Microsoft Windows applications.

Fortran Tools

Conclusion

Even though it is very old, Fortran remains a valuable tool for programmers — especially those working in science and engineering. At the same time, it is an easy language to use. So either as a first language, or as another tool to add to your arsenal, it is worth checking out.

Frank Moraes

About Frank Moraes

Frank has worked in the tech industry since the early 1990s — as a writer, programmer, and manager. He’s an insatiable blogger and “Don Quixote” fanatic. In his spare time, Frank writes experimental plays — usually involving puppets like Grumpy Squirrel in his image.

Comments

Thanks for your comment. It will show here once it has been approved.

Your email address will not be published. Required fields are marked *