FORTRAN Reference Manual
Program Units
FORTRAN Reference Manual—528615-001
4-6
Assigning a Value to the Function Name
Assigning a Value to the Function Name
The symbolic function name serves as the main entry point to the function subprogram.
The function subprogram must contain a statement that stores a value in the function
name. If more than one statement stores a value in the name of the function, the last
value stored is the value returned to the calling program.
You can define the function name in any one of the following ways:
•
By using an assignment statement
•
By using an input statement
•
By using the function name as an actual argument in a statement calling another
function or subroutine subprogram
In the following example, the function TINTEREST uses an assignment statement to
define the value of the function:
FUNCTION tinterest (principal, payment, rate, months)
REAL interest
tinterest = 0
balance = principal
DO 10 j = 1,months
interest = balance * (rate/12)
amount = payment - interest
balance = balance - amount
tinterest = tinterest + interest
10 CONTINUE
RETURN
END
In the following example, the value returned by the function is the value read by a
READ statement:
FUNCTION sum(a,b)
READ (5,*) sum
.
RETURN
END










