This is the only compulsory program unit, every program must have one:
[ PROGRAM [main program name
] ]
...
declaration of local objects
![]()
...
executable stmts
![]()
...
[ CONTAINS
internal procedure definitions
]
END [ PROGRAM [
main program name
] ]
The PROGRAM statement and main program name
are optional,
however, it is good policy to always use them.
main program name
can be any valid
Fortran 90 name.
The main program contains declarations and executable statements and may also contain internal procedures. These internal procedures are separated from the surrounding program unit, the host (in this case the main program), by a CONTAINS statement. Internal procedures may only be called from within the surrounding program unit and automatically have access to all the host program unit's declarations but may also override them.
Figure 7: Schematic Diagram of a Main Program
Internal procedures may not contain further internal procedures, in other words the nesting level is a maximum of 1. The diagram shows two internal procedures, Sub1 and Funkyn however, there may be any number of internal procedures (subroutines or functions) which are wholly contained within the main program.
The main program may also contain calls to external procedures. The diagram represents two external procedures, ExtSub1 and ExtFunn, however, again there may be any number of external procedures (subroutines or functions). External procedures are totally outside of the main program.
The main program must contain an END statement as its last (non-blank) line. For neatness sake this should really be suffixed by PROGRAM (so it reads END PROGRAM) and should also have the name of the program attached too. Using as descriptive as possible END statements helps to reduce confusion.