next up previous contents
Next: Argument Association Up: Program Units Previous: Subroutines

 

Functions

Consider the following example,

      PROGRAM Thingy
       IMPLICIT NONE
       .....
        PRINT*, F(a,b)
       .....
      CONTAINS
       REAL FUNCTION F(x,y)
        REAL, INTENT(IN) :: x,y
         F = SQRT(x*x + y*y)
       END SUBROUTINE OutputFigures
      END PROGRAM Thingy

Functions also lie between CONTAINS and END PROGRAM statements. They have the following syntax:

 
 [< prefix >] FUNCTION < procname >( [< dummyargs >])

< declaration of dummy args >

< declaration of local objects >

...

< executable stmts, assignment of result >

END [ FUNCTION [ < procname > ] ]

It is also possible to declare the function type in the declarations area instead of in the header.

For more information, click here gif

Now try this question gif

Now try this question gif


next up previous contents
Next: Argument Association Up: Program Units Previous: Subroutines

©University of Liverpool, 1997
Wed May 28 23:37:18 BST 1997
Not for commercial use.