Re: fortran compile ERROR ! (62 Views)
Reply
Occasional Advisor
Kinmax_1
Posts: 9
Registered: ‎04-29-2003
Message 1 of 2 (62 Views)
Accepted Solution

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 !
Please use plain text.
Advisor
David Johns
Posts: 33
Registered: ‎04-10-2001
Message 2 of 2 (62 Views)

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
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation