next up previous contents
Next: Subroutine Example Up: Program Units Previous: Procedures

 

Subroutine Syntax

Syntax of a (non-recursive) subroutine declaration:

 
SUBROUTINE  tex2html_wrap_inline21746  procname  tex2html_wrap_inline21748 [ ( tex2html_wrap_inline21746  dummy args  tex2html_wrap_inline21748 ) ]

tex2html_wrap_inline21746  declaration of dummy args 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 [ SUBROUTINE [ tex2html_wrap_inline21746  procname tex2html_wrap_inline21748 ] ]

SUBROUTINE s may contain internal procedures but only if they themselves are not already internal.

  figure9160
Figure 8: Schematic Diagram of a Subroutine

The structure is similar to that of the main PROGRAM unit except a SUBROUTINE can be parameterised (with arguments) and the type and kind of these must be specified in the declarations section. A SUBROUTINE may include calls to other program units either internal, external or visible by USE association (defined in a module and USE d in the procedure. As with the main PROGRAM, the SUBROUTINE must terminate with an END statement and it is jolly good show to append SUBROUTINE and the name of the routine to this line as well.

In order to promote optimisation a recursive procedure must be specified as such -- it must have the RECURSIVE keyword at the beginning of the subroutine declaration (see Section gif).




next up previous contents
Next: Subroutine Example Up: Program Units Previous: Procedures

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