The RESULT variable is used to return the value of a function.
Syntax
[func-type] [type-spec] FUNCTION func-name ([dummy-args]) [RESULT(result-name)]Where:func-type is PURE, ELEMENTAL or RECURSIVEtype-spec is
INTEGER [kind-selector] or REAL [kind-selector] or DOUBLE PRECISION or COMPLEX [kind-selector] or CHARACTER [char-selector] or LOGICAL [kind-selector] or TYPE (type-name)kind-selector is ([KIND=] kind)
char-selector is ( [LEN=] length [, ) KIND=kind])
or (KIND=kind [, LEN=length]) or * char-length [,]kind is a scalar INTEGER expression that can be evaluated at compile time
length is a scalar INTEGER expression or *
char-length is a scalar INTEGER literal constant or (*)
func-name is the name of the function
dummy-args is a comma-separated list of dummy argument names
result-name is the name of the result variable
When the RESULT variable is present in a function declaration, its type and kind specifications define the type and kind specifications of the function.
Example
! function declaration with result variable function func2(a,b) result(res) real :: res ! result type defined here real,intent(in) :: a, b res=a-b ! function is assigned a result end function