[f2py] (no subject)

LOPEZ GARCIA DE LOMANA, ADRIAN alopez at imim.es
Mon Jan 23 13:14:27 EET 2006


Hi people, 

I am a Python user. While writting a program, I need to call a Fortran routine for doing some optimizations. I found f2py and started using it. But there is something I'm stuck with and if someone have any idea will be vey helpful.

>From the Fortran code I need to calculate a value which is given by a Python function. The problem is that the Fortran routine that calls the Python function is not directly called from the Python program. I'm trying to do something like this (I hope to be able to explain myself):

Python:

import fortran_program

def fun(x):

    x = x*2

    return x

fortran_program.principal()


Fortran:

      subroutine principal   

      integer a

      a = 1

      write(*, *) a

      call foo

      return
      
      end

      subroutine foo

cf2py intent(callback) fun

      external fun

      real y

      y = 3.
      
      y = fun(y)

      write(*, *) y

      return
      
      end

This is not working. If I call the Python function fun from the subroutine principal, it works, but I guess fun is not properly defined at foo.

If someone could give me some suggestions, it would be great, 

Thanks for your time, 

Adrián.



More information about the f2py-users mailing list