[SciPy-user] f2py complex number problem

Ryan Krauss ryanlists at gmail.com
Fri Dec 9 14:08:47 CST 2005


Thanks Robert.  That will work.  But what am I doing wrong:

      subroutine test(s,out)
      double complex s, out
      external zsinh, zcosh
Cf2py intent(in) s
Cf2py intent(out) out
      out=zcos(s)-zcosh(s)+zsin(s)-zsinh(s)
!      out=zcos(s)+zsin(s)
      END

      double complex function zcosh(z)
      double complex z
      zcosh = 0.5*(exp(z)+exp(-z))
      END

      double complex function zsinh(z)
      double complex z
      zsinh = 0.5*(exp(z)-exp(-z))
      END

I can access zsinh and zcosh from python and they are correct, but
calling the main funtion returns NaN.  If I switch the comment so that
out=zsin(s)=zcos(s), everything works fine, so my zsinh and zcosh seem
to be screwing this up.

Two other rusty fortran questions.  Can I put zsinh and zcosh in a
library somewhere and import them either complied or just import the
definitions?  Is it possible to overwrite the interinsic cos, sin,
cosh, and sinh with my own comlex definitions?

I have a few fortran books I have checked out of the library and I
have tried googling, but I am not getting anywhere.

Thanks,

Ryan


On 12/9/05, Robert Kern <robert.kern at gmail.com> wrote:
> Ryan Krauss wrote:
> > I am trying to learn f2py and am running into a problem.  I need to
> > take the sin, cos, sinh, and cosh of complex numbers.  My FORTRAN is
> > quite rusty but this isn't working:
> >
> >       subroutine test(s,out)
> >       double complex s, out
> > Cf2py intent(in) s
> > Cf2py intent(out) out
> >       out=cos(s)-cosh(s)+sin(s)-sinh(s)
> >       END
> >
> >
> > f2py output ends with:
> > test.f: In subroutine `test':
> > test.f:5:
> >          out=cos(s)-cosh(s)+sin(s)-sinh(s)
> >                     ^
> > Reference to intrinsic `COSH' at (^) invalid -- one or more arguments
> > have incorrect type
>
> http://gcc.gnu.org/onlinedocs/gcc-3.4.1/g77/CosH-Intrinsic.html#CosH%20Intrinsic
>
> The COSH intrinsic only takes REAL agruments, at least in g77. EXP,
> however, works with COMPLEX arguments, so I suggest defining a ZCOSH
> function from the definition of cosh(z) = 0.5*(exp(z)+exp(-z))
>
> --
> Robert Kern
> robert.kern at gmail.com
>
> "In the fields of hell where the grass grows high
>  Are the graves of dreams allowed to die."
>   -- Richard Harter
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user
>



More information about the SciPy-user mailing list