What Is Fortran? Working, Applications, Benefits, and Challenges

Fortran is a 60-year-old compiled language that helps run complex mathematical operations in scientific computing.

Last Updated: July 6, 2023

Image illustrating a programmer working on Fortran implementation
  • Fortran is defined as a general-purpose compiled language used to run complex mathematical calculations and data operations, especially in the academic community, due to its performance and compatibility advantages.
  • Despite being 60+ years old, Fortran is among the top 20 computing languages in the world due to its relatively simple working and impressive capacity.
  • This article provides an overview of the Fortran programming language, discusses how it works, and lists its pros and cons.

What Is Fortran?

Fortran is a general-purpose, compiler-based programming language used to run complex mathematical calculations and data operations, especially in the academic community, due to its performance and compatibility advantages.

Pictorial Representation of Fortran Implementation

Pictorial Representation of Fortran Implementation

Source: PyPIOpens a new window

Fortran is a versatile programming language particularly well-suited for scientific computing applications. Due to its exceptional efficiency levels, this high-level programming language has retained its popularity for decades. Only a handful of languages, such as C++, can compete with the speed at which Fortran programs execute. Many programmers also prefer Fortran over C++ because it requires far less consideration for memory allocation and optimization.

Since its beginning in the 1950s, areas with a strong focus on computation have been dominated by Fortran. These computational domains consist of the following:

  • Geophysics and mathematical weather forecasts
  • Calculated fluid dynamics
  • Computing in chemistry and computational physics
  • Finite element research

Fortran is still a major programming language. As a result, most of the world’s quickest supercomputers have used it in their applications. Since its inception, it has undergone several iterations.

Each version of Fortran includes new extensions while maintaining compatibility with previous versions. With each new release, assistance with character-led processing of data, structured, array, and generic programming, to name a few, have been added.

Many other programming languages have been developed based on Fortran’s framework. The most prominent is BASIC, which is based on Fortran II and has enhanced logical structures and syntax.

How was Fortran developed?

Plankalkul, developed by Konrad Zuse, was the world’s first high-level programming language, though the initiative existed only on paper. John Backus created the first successful high-level programming language, Fortran. Backus, a Columbia University graduate with a bachelor’s degree in mathematics, devised Fortran in the early 1950s while working as a programmer at the IBM computer center.

This language was intended for use with the Selective Sequence Electronic Calculator (SSEC), an electromechanical machine with approximately 23,000 electromechanical relays and 13,000 vacuum tubes designed for complex calculations such as those required by NASA. Since the creation of the SSEC, operating it has been an arduous endeavor. This is because no one had established a suitable method to do it. John Backus spent three years attempting to program the SSEC.

During this time, he created a program initially referred to as speedcoding. The program was the first and only one of its kind to include a storage and manipulation mechanism for both very small and large numbers. IBM ultimately approved Backus’ proposal, financed a team, and released the IBM 704 computer, which would spur business versions of Fortran.

Eventually, Fortran would allow the computer to take a concise mathematical problem formulation and produce a fast 704 program for its functions.

See More: What Is COBOL Programming Language? Definition, Examples, Uses, and Challenges

Different versions of Fortran

Fortran has come a long way since its early days as a programming language for IBM 704. Its most notable versions are:

  1. Fortran
    In 1957, Backus released the very first enterprise-ready Fortran compiler after nearly three years in the works. Upon conclusion, the Fortran compiler’s magnetic tape contained approximately 250,000 lines of machine code. With each IBM 704 installation, a copy of the software and a 51-page manual was also offered.
  2. Fortran II
    IBM introduced Fortran II in 1958. The most significant enhancement was the addition of user-written functions and subroutines, which improved procedural programming. The number of statements in Fortran II increased, which included subroutine, function, return, call, and end.
  3. Fortran III
    In the same year Fortran II was released, IBM also released Fortran III with integrated assembly code and more capabilities. IBM never made the version available to consumers as a product. By 1960, several Fortran versions for IBM computers were available. As Fortran’s popularity grew, rival computer manufacturers began offering Fortran compilers on their machines.
  4. Fortran IV
    In 1961, in response to requests from the public, IBM began developing Fortran IV. Fortran IV eliminated Fortran II’s machine-dependent features and added new ones, such as the logical data type. In 1965, Fortran IV was required to adhere to the guidelines of the American Standards Association.
  5. Fortran 66
    In 1966, the American Standards Association (currently known as ANSI, wherein N stands for National) established a committee to create the American Standard Fortran. This process resulted in the birth of Fortran 66, the first market-standard variant of the language. Following Fortran 66’s official release, compiler vendors incorporated additional Fortran extensions.
  6. Fortran 77
    April 1978 marked the formal ratification of the latest Fortran standard at the time, designated Fortran 77. To resolve Fortran 66’s flaws, the newer version of the programming language consisted of more capabilities. The creation of a revised standard to replace Fortran 77 was delayed due to the rapid evolution of programming and computing services.
  7. Fortran 90
    The 1992 revision changed the spelling of its authorized title to Fortran from FORTRAN. Additionally, Fortran 90 included new features highlighting the major programming developments that occurred after the 1978 standard. Embedded remarks, components, free-form code inputs, identifiers, and recursive procedures were among the many features.
  8. Modern Fortran
    2003 marked the commencement of modern Fortran with support for object-oriented programming. In Fortran 2003, new functionalities such as input/output improvements, manipulation of data, and procedure pointers were added, among others.
  9. Fortran today
    In the year 2010, Fortran 2008 was released. It was an innocuous upgrade, and the succeeding version of the programming language, Fortran 2018, was made available in November 2018. It was a major update that added new features to the previous iteration. This recently developed programming language is still utilized by mathematicians and scientists worldwide.

Importance of Fortran

Fortran was an important milestone in computer software, similar to how the microprocessor had been a major advancement in hardware. It shifted the parameters for interactions between computers and humans to a higher level, offering a more human-comprehensible language.

Backus and his group created a programming language resembling a combination of English abbreviations and algebra. Fortran resembled algebraic formulas regularly utilized by engineers and scientists. Once trained adequately, they were free of the dependence on a programmer’s ability to translate their scientific and engineering queries into a language that a computer could comprehend. As such, it paved the way for business users to leverage technology independently, which is common today.

Fortran remains relevant in disciplines requiring high-performance computing in computational science. Examples of notable Fortran programs include:

  • The Goddard Institute for Space Studies models
  • The open-source finite volumes fluid dynamics (OFF) code
  • The Nucleus for European Modelling of the Ocean (NEMO) project

Fortran is also popular among various climate modeling programs as mathematical formulae can be readily converted into code. Further, its performance is quick, and most of the climate modeling community is familiar with the language.

See More: What Is MATLAB (Matrix Laboratory)? Working, Functions, and Applications

How Does Fortran Work?

A modern Fortran program consists of multiple program units, including the primary program, auxiliary subprograms, and modules. Each program consists of a single primary program and possibly additional program elements.

Unlike other languages such as Basic, a Fortran program is not written in a ‘Fortran window’ of an integrated development environment (IDE). Instead, it is written and stored with a text editor (or a processor), and a Fortran compiler converts the program into an executable file. This is because Fortran is a compiler-based programming language.

To initiate the creation of a Fortran program, the user must launch an editor. It is best to employ a simple editor, such as Notepad, as word processors may add unnecessary formatting notes, which will cause Fortran to malfunction.

Then, the steps involved in Fortran working are:

How Fortran Works

How Fortran Works

1. Writing the program

To access the DOS editor, input ‘edit’ (and return) at a DOS prompt or launch Notepad under Windows. All Fortran programs commence with the keyword ‘program,’ have the keyword ’end program,’ and end with the word ’end.’

Each line must start with a tab or indent, except the third line, which must have the letter ’c’ in the first column. Then, enter the program shown below; it calculates the dimensions of the circle of length ‘s’ as per user specifications. The file that you store is referred to as the program’s source file.

program squarearea

real s, area

c    This program computes the area of a square.

print *, “What is the length of the square?”

read *, s

area = s*s

print *, “The area of the square is “, area

print *, “Bye!”

end

The first statement specifies the program’s name, while the second states that ‘s’ and ‘area’ are single-precision real quantities. The third statement commencing with ‘c’ in column one is a comment describing the program’s functionality. Such remarks are for the programmer’s advantage and are disregarded by Fortran.

The following line asks the user for the square’s extent, and the fifth statement acknowledges this input. The sixth statement calculates the area, while the seventh statement notifies the user of the area being calculated. The final two statements send farewell and terminate the program.

2. Saving the source file

A Fortran source file’s name must conclude with the .f extension for the compiler to be able to identify it. After entering the preceding code, store your work as area.f. When saving a file in Notepad, you must enclose the entire file name in quotation marks; otherwise, the extension.txt will be appended.

Under DOS, you can see the files within this directory by entering dir and pressing the Enter key; under Windows, you can double-click on ‘My Computer’ and navigate to the folder carrying the source program.

3. Compiling the program

After creating and saving a source file, the next step is to assemble it. Enter ‘g77 name.f’ within a Fortran window. Simply enter the title of the source file, area, in place of the name. If the source file exists in a different directory from the Fortran program, you must also include the file’s directory path. In the mathematical computer lab, enter g77 area.f to build the file from the preceding example.

Importantly, g77 is the most commonly used Fortran compiler in basic programming; based on the type of compiler you are using, the command can be slightly different.

If your program contains errors, which typically occur on the first collection attempt, you will receive Fortran error messages rather than a compiled file. Fortran will return a DOS prompt if your program contains no errors. This is a positive sign showing that Fortran has successfully generated a compiled file. The default filename for this freshly created file is a.exe.

Your assembled file is now executable, signifying that the program is now available to execute.

4. Running the program

To execute a file with the default extension a.exe, input ‘a’ and hit return. After running the program and observing its operation, you can return to the editor and make the necessary changes. It may be preferable to keep two windows — the Fortran window and the editing window — to ensure you can easily move between them with a mouse click. After making adjustments to the program, you need to save and reload it for the modifications to take effect.

Among the most frequent programming mistakes in Fortran is creating and running a program that never terminates. In such a circumstance, type ‘Control-C’ to halt the program’s execution.

See More: What Is JSON? Meaning, Types, Uses, and Examples

Key Fortran concepts

Now that we know how a Fortran program works, let’s look at the key terminology and commands related to its working.

  • Program: Every Fortran program must commence with a line containing the program’s name. For instance, it could be program primes or program quadratic.
  • Declarations: Following the program’s name are the declaration statements, which specify the variables’ types. For example, the declaration statement ‘real s, area’ states that r and area are true variables with single precision.
  • Variables: A variable name comprises characters selected from the alphabetic order A to Z and the numerals 0 to 9, with the first character being a letter. You cannot use your program’s title like a variable and can’t use terminology restricted for the Fortran programming language, including ‘program,’ ‘real,’ ‘end,’ etc.
  • The ‘implicit’ quantifier: The implicit quantifier preceding a type declaration allocates the specified type to all variables whose names begin with the specified letters. For instance, the ‘implicit integer (a-e)’ declaration makes variables commencing with a, b, c, d, or e integers. However, it is best to avoid the implicit quantifier, as programmers with restricted memories are likely to commit errors.
  • Assignment: The equals to sign ‘=’ allocates the numerical value of the integer or statement on the right to the variables on the left.
  • Comment: To signify a remark, enter a ‘c’ in column 1 and add the comment in sections 7 to 72. Alternatively, you can employ an exclamation mark ‘!’ to signify a comment; it may appear anywhere on the line (except columns 2 to 6). Everything following an exclamation mark on a line is considered comments and disregarded by Fortran.
  • End statement: The end statement signifies the conclusion of the primary Fortran program or a subprogram. Unlike other languages, such as Basic, it can’t be utilized amid a program.

See More: Java vs. JavaScript: 4 Key Comparisons

Pros and Cons of Fortran

In April 2021, the TIOBE Index, which assesses the prevalence of different programming languages, placed Fortran as the 20th most prevalent language worldwide. This is a remarkable feat, given that Fortran is over 60 years old! This is due to its following key advantages:

1. Improved performance

With the arrival of supercomputers, the computing community has placed more emphasis on performance. Historically, the evolution of Fortran has centered on optimization. To provide the compiler the best opportunity to optimize code aggressively, the programming language imposes several constraints on the programmer. This makes it extremely difficult to write slow code with Fortran. In other programming languages, including C, you can carry out actions that would result in slow code.

2. Greater suitability for scientific computing

Programming languages such as C and C++ are very useful for general purposes. Performing even the most fundamental operations of scientific computation, such as coping with multidimensional arrays and complex numbers, demands significant syntactic latency. On the contrary, Fortran has almost always provided organic support for arrays with multiple dimensions, number structures, and some specialized functions.

3. Excellent backward compatibility

The field of numerical computation is not as susceptible to obsolescence as web designing. In scientific computation, the longevity of code is a highly desired quality. Anyone who invests a lot of time in writing mathematical code is also keen to ensure it keeps working, practically unmodified, for decades to come. Due to its stringent backward compatibility policy, Fortran ensures the endurance of code over the long term.

However, despite these benefits, the language has a few drawbacks:

  • It has inadequate string management capabilities, which include ineffective concatenation functions.
  • The fact that subroutines pass arguments through reference instead of by value affects data protection.
  • In some instances, loop controls are slightly restricted, necessitating the continued use of the GOTO statement for controlling flow.
  • It continues to utilize insecure storage as well as sequence-linking capabilities.
  • Precision issues may arise when transferring Fortran code coming from one system to another, although this has improved from Fortran 90 onward.
  • In older Fortran programs, each line correlates to a unique punched card carrying 72 columns, suggesting that each line is limited to 72 characters.

See More: What Is JSON? Meaning, Types, Uses, and Examples

Takeaway

Fortran is a slightly archaic programming language that is still widely used today. It strives to keep up with contemporary programming languages by incorporating new backward-compatible features and is still actively developed. 

Even though contemporary programming languages are moving toward a more generalized approach, this competent domain-specific language continues to be a mainstay in several of the most significant sectors of computing. Even in the age of supercomputers, it is obvious that Fortran is here to stay.

Did this article help you understand Fortran in detail? Tell us on FacebookOpens a new window , TwitterOpens a new window , and LinkedInOpens a new window . We’d love to hear from you!

Image Source: Shutterstock

MORE ON PROGRAMMING 

Chiradeep BasuMallick
Chiradeep is a content marketing professional, a startup incubator, and a tech journalism specialist. He has over 11 years of experience in mainline advertising, marketing communications, corporate communications, and content marketing. He has worked with a number of global majors and Indian MNCs, and currently manages his content marketing startup based out of Kolkata, India. He writes extensively on areas such as IT, BFSI, healthcare, manufacturing, hospitality, and financial analysis & stock markets. He studied literature, has a degree in public relations and is an independent contributor for several leading publications.
Take me to Community
Do you still have questions? Head over to the Spiceworks Community to find answers.