
D. Haugli Aer E 160 Aerospace Engineering
2/2/2005 Main Programs, Page 1 Iowa State University
Main Programs
The essential structure of a FORTRAN program with no explicit subroutines or functions is:
PROGRAM <insert name of program>
<Insert IMPLICIT NONE statement and declarations>
<Insert executable statements followed by STOP>
END PROGRAM <insert name of program>
Every program must begin with the PROGRAM line, and end with END PROGRAM. Program names
must begin with a letter, and may contain any combination of letters, numbers and underscore
characters after the first letter. No other characters are allowed.
(Programs are saved in text files. The text files must be named with the extension .f90, such as
main.f90. The name of the text file can be different from the name on the PROGRAM line.)
Variables are declared immediately after the PROGRAM line (including the line IMPLICIT NONE,
which must listed before data type declarations such as REAL, CHARACTER or INTEGER).
Executable statements follow the declarations, and end with the line STOP. (STOP tells the
program to stop running.)
Case (e.g., small or capital letters) does not matter in writing a FORTRAN program. Each
programmer develops their own style, and many use case to clarify their codes. For example,
this instructor uses capital letters for FORTRAN commands and lower case letters for program
and variable names.
Good programmers add comments to their codes that explain what the code is doing. Words and
sentences that follow an exclamation point are comments. The compiler ignores them.
Several examples of main programs follow.
Example 1. The Hello World program below is a traditional introduction to the form of a
main program.
PROGRAM hello
WRITE (*,*) "Hello World!"
STOP
END PROGRAM hello
This program has no declarations. The statement,
WRITE (*,*) "Hello World!"
is an executable statement and causes the words "Hello World!" to appear on the screen
when the program runs.