next up previous contents
Next: Main Program Example Up: Program Units Previous: Procedure Classes

 

Main Program Syntax

This is the only compulsory program unit, every program must have one:

 
[ PROGRAM [  tex2html_wrap_inline21746  main program name  tex2html_wrap_inline21748  ] ]

...

tex2html_wrap_inline21746  declaration of local objects tex2html_wrap_inline21748

...

tex2html_wrap_inline21746  executable stmts tex2html_wrap_inline21748

...

[ CONTAINS

tex2html_wrap_inline21746  internal procedure definitions tex2html_wrap_inline21748 ]

END [ PROGRAM [ tex2html_wrap_inline21746  main program name tex2html_wrap_inline21748 ] ]

The PROGRAM statement and tex2html_wrap_inline21746  main program name tex2html_wrap_inline21748 are optional, however, it is good policy to always use them. tex2html_wrap_inline21746  main program name tex2html_wrap_inline21748 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.

  figure8971
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.




next up previous contents
Next: Main Program Example Up: Program Units Previous: Procedure Classes

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996
Not for commercial use.