Reputation: 51
I have CERN program which calculates the gamma function of complex argument, but I can't run the program because of lack of Fortran knowledge.
I have the following program:
PROGRAM Console1
IMPLICIT REAL *8 (A-H,O-Z)
COMPLEX *16 gama,z,w
z=cmplx(0,0.707106781186548d0)
gama=cgamma(0,z,w)
END
SUBROUTINE cgamma(mo, z, w)
INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(14, 60)
INTEGER, INTENT(IN) :: mo
COMPLEX (dp), INTENT(IN) :: z
COMPLEX (dp), INTENT(OUT) :: w
... the subroutine code here
END SUBROUTINE cgamma
and then error appears
error #6553: A function reference is invoking a subroutine subprogram. [CGAMMA]
Upvotes: 2
Views: 808
Reputation: 32366
Look at the error message:
A function reference is invoking a subroutine subprogram.
SUBROUTINE cgamma(mo, z, w)
END SUBROUTINE
defines cgamma
as a (in this case external) subroutine.
In the program
gama=cgamma(0,z,w)
references cgamma
as a function (returning a result to be assigned to gama
). This is the incompatibility to which the error message refers.
To resolve this you need to reference the subroutine with a call
statement, or change cgamma
to be a function, returning an appropriate result.
Given the design of the procedure (three arguments) I'd expect the function is intended.
Upvotes: 2
Reputation: 995
technically it is not a program.
I will repost part of the document in your link below, notice the SUBROUTINE cgamma
and END SUBROUTINE cgamma
as the very first and very last lines. Technically this file is not a fortran program, it is only a subroutine which is part of a larger program.
SUBROUTINE cgamma(mo, z, w)
IMPLICIT NONE
! variables and code not worth posting to illustrate what is happening
60 w = CMPLX(w1, w2, KIND=dp)
RETURN
70 w = (0.0_dp, 0.0_dp)
RETURN
CONTAINS
FUNCTION rexp(x) RESULT(fn_val)
! extra code here, do not need to post it
fn_val = -1.0_dp
RETURN
END FUNCTION rexp
END SUBROUTINE cgamma
In fortran the first and last lines of the file would be PROGRAM whatever
and END
.
so you will either need to get the full program and use that which calls this cgamma subroutine, or write your own fortran PROGRAM
which then calls this cgamma
subroutine.
Upvotes: 2