Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

fortran compile ERROR !

SOLVED
Go to Solution
Highlighted
Occasional Advisor

fortran compile ERROR !

First of all, I am almost unfamiliar with fortran language as well as compiler.

The version of Fortran compiler is B.11.11.71 (F90 v2.7.1), on HP D380 Server with HP-UX 11i OS.

The source code is as follows:
=============================================
RECURSIVE FUNCTION FACTORIAL( X )

real :: x, GAMMA

if ( X .gt. 12.0 ) then
FACTORIAL = GAMMA( X+1 )
else
if ( X .le. 1.0 ) then
FACTORIAL = 1.0
else
FACTORIAL = X * FACTORIAL( X-1 )
end if
end if

RETURN
END
=============================================

But when compiling, it shows that:
=============================================
# f90 -c factorial.f90
factorial.f90
external function FACTORIAL
FACTORIAL = X * FACTORIAL( X-1 )
^
Error 282 at (11:factorial.f90) : This is not the name of a function but of a function result

1 Error
f90: Errors detected.
=============================================

I really don't know what's wrong. Help me please !
1 REPLY
Advisor

Re: fortran compile ERROR !

Hello:

I'm kind of rusty at Fortran, but I'd say all you need to do is something similar to this example from the HP docs:

RECURSIVE FUNCTION factorial (n) RESULT(r)
INTEGER :: n, r
IF (n.ne.0) THEN
r = n*factorial(n-1)
ELSE
r = 1
ENDIF
END FUNCTION factorial

Regards,
Dave