The simplest Fortran program

The simplest Fortran program is what might be called a "do-nothing" program. It contains all of the required parts of a Fortran program. The program is as follows:

      PROGRAM MAIN
      STOP
      END

The program simply starts and stops. It has a beginning (the PROGRAM instruction), and then tells the system to halt execution (STOP). Notice that there is both STOP and END. The distinction is that STOP tells the system to halt the execution of the program, while END identifies the end of your instructions - that is, END will always appear as the last line of a program. Complex programs may have more than one STOP instruction; for example, execution may be halted if an error occurs. A single instruction in Fortran is usually called a statement.

Although seemingly trivial, writing and executing this program illustrates some of the basic rules of writing Fortran programs:

  • Only one instruction (or statement) may appear on a line.
  • The statement is limited to the first 72 characters of each line. Some Fortran compilers will accept longer lines. However, this is not standard and therefore use of longer statements is strongly discouraged.
  • The program is written in all uppercase letters. Although almost all Fortran compilers will accept lowercase letters, the standard calls for uppercase.
  • Notice that all of the lines in the example above begin with 6 blank spaces. This is because the Fortran standard requires that the first 6 characters of a line be reserved for statement numbers and continuation characters. We will learn about statement numbers and continuations later.

Assignment: Type the "do-nothing" program. It is important that it be hand-typed: do not use cut-and-paste. Save it as a file, compile it and run it. Here are some typical ways of compiling and running programs.

 

Next: The Hello World program.

Back to main page for programming tutorial