HP Fortran Programmer's Reference (September 2007)

Program units and procedures
Statement functions
Chapter 7170
! Note that the dummy arguments must be scalar, so in order
! to find the average of the elements of the array, we must
! pass each element as a separate argument
get_avg(x1, x2, x3) = (x1 + x2 + x3) / 3
! reference the statement function get_avg
PRINT *, get_avg(x(1), x(2), x(3))
END SUBROUTINE print_avg
Here are the command lines to compile and execute the program, along with the output from
a sample run:
$ f90 stmt_func.f90
$ a.out
4.66667