2

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]

3
  • What do you have? A .exe, or .so or what?
    – Holmz
    Commented Dec 21, 2016 at 16:35
  • It's a .f90 I added the program.
    – tsogam
    Commented Dec 21, 2016 at 17:15
  • Don't use IMPLICIT other the IMPLICIT NONE. Look at the subroutine code how variables should be defined. You are asking for A LOT of trouble by using IMPLICIT REAL. Commented Dec 21, 2016 at 20:08

2 Answers 2

2

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.

1
  • Thanks, I just needed to write: call cgamma instead of gama=cgamma. Thanks for help
    – tsogam
    Commented Dec 21, 2016 at 17:59
2

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.

1
  • Thanks for advice, I did it
    – tsogam
    Commented Dec 21, 2016 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.