Fortran - the Programming Language
Created | Updated Apr 22, 2012
Fortran is the oldest computer programming language still in regular use today, mainly for scientific and engineering purposes. For over 50 years, it has been the language of choice for computationally intensive applications such as weather forecasting and computational fluid dynamics, and is still the most popular language used on supercomputers, the fastest and most powerful computers available.
History
In the early days of computers, programming was a difficult process involving the entry of raw machine code as long series of numbers to carry out calculations. Assembly language1 simplified the process a bit but it still depended on the computer hardware in use and made running a program on different computers very difficult. Since computers were still the size of large rooms, relatively few people were able to program them.
In late 1953, a programmer at IBM, John Backus (1924-2007), submitted a proposal to make programming the IBM 704 mainframe computer2 simpler. Rather than writing in machine code or assembly language, Backus proposed the use of a programming language that was easier to write and understand and could later be converted into machine code for the computer to run. As he later said:
Much of my work has come from being lazy. I didn't like writing programs, and so, when I was working on the IBM 701 [predecessor to the IBM 704], writing programs for computing missile trajectories, I started work on a programming system to make it easier to write programs.
– John Backus, interview with IBM employee magazine Think, 1979
Together with a group of programmers, he came up with a draft specification and then a manual for The IBM Mathematical Formula Translating System. The group also needed to produce a compiler: this program would read the human-friendly language and convert it into machine code for the computer to use. Their first FORTRAN compiler for the IBM 704 was finally released in April 1957, taking two years rather than the predicted six months to develop.
While the programming community was initially sceptical that a high-level programming language and compiler would generate machine code that ran as fast as hand-coded assembly language, FORTRAN was able to reduce the number of statements required by a factor of 20. It quickly gained acceptance, particularly among scientists and engineers who started to use computers in their work.
By 1960, FORTRAN compilers were available for other IBM computers, the 709, 650, 1620, and 7090, and in response to demand, other computer manufacturers started making compilers for their own machines: over 40 compilers existed by 1963. FORTRAN thus sowed the seeds for portable computing, which meant that program code written on one machine could be used unchanged on another3.
Versions and Development
The first version of Fortran, FORTRAN, had 32 statements. Many of these were for use with now outdated devices such as paper tape readers, and are therefore not found in modern-day Fortran, while other aspects such as DO loops and IF statements still survive to this day, although these have been modified in later versions. A second version of Fortran, FORTRAN II, was available within a year of the original release and included additional statements as well as allowing users to define their own subroutines and functions. Later implementations of FORTRAN II added support for double precision4 and complex5 data types.
A third version, FORTRAN III, was developed shortly after FORTRAN II but was never publicly released as its major new feature – including assembly code inside a program – was machine-dependent. Instead, FORTRAN IV was developed in response to customer demand for greater portability and was released in 1962. As well as removing machine-dependent features such as tape reading, it also included Boolean data types6 and expressions as well as a logical IF statement as an alternative to the original arithmetic IF statement.
The most significant move to make Fortran portable was the decision by the American Standards Association7 to develop an 'American Standard Fortran'. In 1966, two standard Fortrans were defined: FORTRAN8 based on FORTRAN IV (which had become a de facto standard by then) and Basic FORTRAN based on FORTRAN II. The first of these definitions, FORTRAN, became known as FORTRAN 66 and was the first 'industry standard' Fortran. It included many features that still survive today, including arrays, internal and external (library) functions, and sequential and formatted input/output statements.
Since FORTRAN 66, several other versions of Fortran have been produced with more features and with different approaches to programming in mind. Additional features are frequently added to compilers that are not part of the current standard but are considered useful and are adopted in other Fortran compilers: these are often then picked up by ANSI and ISO9 and form part of the subsequent standard Fortran.
Of the versions that have been released since FORTRAN 66, FORTRAN 77 and Fortran 90 are perhaps the most influential. FORTRAN 77 provided more structured programming by removing the need for line numbers and added lexical comparisons of strings10. Many historical programs that are still in use today were written in this dialect and many programmers and scientists still encounter it. Fortran 90 finally allowed freer formatting of program code - a 72-character limit per line in previous dialects was a legacy of punch cards - and also provided modules to group subroutines and functions as well as dynamically allocatable arrays11.
More recent dialects have made more incremental changes. Fortran 90's successor, Fortran 95, was a minor revision of Fortran 90, which added a few extensions related to high-performance (parallel) computing and also removed some of the obsolete features highlighted by the Fortran 90 standard. Fortran 2003 builds on Fortran 95 and a number of subsequent extensions by including support for object-oriented programming, interoperability with C and better integration with the host operating system. A minor revision of Fortran 2003 - Fortran 2008 - was approved in 2010, which includes submodules inside other modules, improved sharing of arrays in parallel computing and several other smaller improvements. At the time of writing, both Fortran 2003 and Fortran 2008 are still in the process of being implemented in widely available Fortran compilers.
Example Fortran Code
Two example programs in Fortran are given here. The first simply prints 'Hello, world!' on the screen.
PROGRAM HelloWorldWRITE (*,*) 'Hello, world!'
END PROGRAM HelloWorld
The second program calculates and displays the surface area of a cylinder after the user enters its radius and height. It checks that enough information has been entered to calculate the surface area and, after printing the results, asks the user whether or not another calculation should be made. It also defines the value of pi as a fixed parameter and makes use of comments (lines starting with !) which the compiler ignores.
PROGRAM cylinderIMPLICIT none ! Require all variables to be explicitly declared
INTEGER :: ierr
CHARACTER(1) :: yn
REAL :: radius, height, area
REAL, PARAMETER :: pi = 3.141592653589793
interactive_loop: DO
! Ask user for radius and height and read them
WRITE (*,*) 'Enter radius and height.'
READ (*,*,iostat=ierr) radius,height
! If radius and height could not be read from input,
! then cycle through the loop
IF (ierr /= 0) THEN
WRITE (*,*) 'Error, invalid input.'
CYCLE interactive_loop
END IF
! Compute area: ** means "raise to a power"
area = 2 * pi * (radius**2 + radius*height)
! Write the input variables (radius, height)
! and output (area) to the screen
WRITE (*,'(1x,a7,f6.2,5x,a7,f6.2,5x,a5,f6.2)') &
'radius=',radius,'height=',height,'area=',area
yn = ' '
yn_loop: DO
WRITE (*,*) 'Perform another calculation? y[n]'
READ (*,'(a1)') yn
IF (yn=='y' .OR. yn=='Y') EXIT yn_loop
IF (yn=='n' .OR. yn=='N' .OR. yn==' ') EXIT interactive_loop
END DO yn_loop
END DO interactive_loop
END PROGRAM cylinder
Uses
As a programming language developed for carrying out calculations and frequently the language of choice for scientists and engineers, Fortran is often used for heavy-duty number crunching. Numerical modelling of complex systems is one frequent use for Fortran: either recreating known situations to gain better understanding of them and possibly make improvements or to predict the future or unknown behaviour of less well-known systems. Modelling calculations can involve weather and climate patterns, fluid flows, complex chemicals, living organisms, subatomic particles and economies. Fortran has also been used to analyse large amounts of experimental data and fit equations to them.
One of the earliest applications for Fortran was of a military nature – calculating missile trajectories for the US military – while NASA has used it to program the computers for many space missions and Jodrell Bank has used Fortran to program the positioning mechanism for its main radio telescope, the Lovell Telescope. It has also found more mundane and everyday uses, such as video games and air traffic control systems.
Fortran is the most frequently used programming language on supercomputers12, which carry out calculations as quickly as possible for applications such as weather forecasting. Even with the recent rise in popularity of C and C++, most programs running on supercomputers are still written in Fortran: current estimates suggest that about 80% of programs use Fortran compared with 20% for C (and less than 1% for C++). The programs used to benchmark computers and supercomputers are still also written in Fortran.
Legacy
Although not the first programming language to have been invented – the punched cards used by Jacquard looms, the order code used by Babbage's Analytical Engine, Konrad Zuse's conceptual language Plankalkül and the ENIAC coding system could all be described as such – Fortran is certainly the oldest one still in regular use. Other programming languages, such as Lisp, ALGOL, BASIC and C, have been influenced by Fortran – either from its successes or its perceived shortcomings – and all other imperative-based languages can consider Fortran as their original source.