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