returning values from FORTRAN with f2py
pearu at cens.ioc.ee
Mon Sep 9 04:52:38 EDT 2002
On 7 Sep 2002, Chris Fonnesbeck wrote:
> I am wondering how to persuade some fortran code that I have compiled
> with f2py to return its calculated values to me in python. I have
> some code that does gaussian elimination (mostly from Numerical
> Reciopes), and is supposed to return an inverted matrix so that I can
> solve a system of linear equations. However, when run in python, the
> function runs without error but returns no values:
> >>> a = [[2,1,3],[1,-1,1],[3,6,-1]]
> >>> b = [7,2,10]
> >>> import gauss
> >>> gauss.gauss(a,3,b,1)
> Is there something that I have to change in my fortran code to make
> this work?
You can add the following comment lines to your Fortran code:
cf2py intent(in,copy,out) a
cf2py intent(in,copy,out) b
(provided that you want the arguments a and b returned to Python).
If you cannot modify Fortran codes then you should create a .pyf file and
insert the above lines there (without cf2py prefix, of course).
More information about the Python-list