[Matrix-SIG] Re: regarding f2py

Pearu Peterson pearu@ioc.ee
Wed, 26 Jan 2000 13:04:54 +0200 (EET)

On Tue, 25 Jan 2000, Thilo Ernst wrote:

> Dear Pearu,
> in search for useful tools for my new project, which involves integrating
> scientific-computing (largely Fortran)
> codes via Python, I saw your f2py announcement & web page.  I find f2py v=
> interesting, I only have one
> problem. As you are using Python and NumPy, you are certainly aware of Pa=
> Dubois=B4 PyFort tool which seems
> to be quite related to your work.  OTOH, there seem to be important
> differences: E.g. I didn=B4t notice support for
> Fortran->Python callbacks when scanning the PyFort docs (superficially as=
> yet, I have to admit).
> This makes it difficult for me as a prospective "customer" of these two t=
> to decide which to use.
> I think it would be very helpful if you as the author, and obviously a "d=
> expert" could put some words
> of comparison on the f2py web page.=20

I think, Paul Dubois and me started to develop such a tool approximately
at the same time (summer 1999) but independently and having different
goals in mind.

My goal was to have tool that would scan large number of
fortran codes (in Netlib libraries such as
blas,lapack,minpack,odepack,etc) and produce raw wrappings of the Fortran
77 codes so that they could be called from Python in a similar way as you
would call them from C or Fortran.=20
Since many of these routines take `external' arguments, the
call-back mechanism was needed in the very early stage of the
development. Thanks to Travis Oliphant who implement the first call-back
mechanism for f2py.=20

During the development f2py has undergone three iterations, each has
be rewritten from scratch. By now it has reached to a quite stable stage.
Though, f2py has currently one shortcoming: using multi-dimensional arrays
is not very user-friendly --- the user must be aware of differences that
are how the multidimensional arrays are stored in Python/C (raw major
order) and in Fortran (column major order).
I think, Paul has found a more user-friendlier solution to this problem.
In fact, the next goal for f2py is to find a better solution to the
problem. That is to eliminate the differences between Python and Fortran
multi-D arrays in the wrapper level so that the user need not to know
about C/Fortran differences.

I hope that Paul is willing to give a nice comment on his tool. From the
documentation of Pyfort I find that his main goal is to wrap Fortran 95
codes to Python, in future.

> One more question: how did you construct the Fortran parser?

Well, I took XL Fortran 5.1 Language Reference Guide and by
following it carefully, implemented the fortran code "cracker" (see
crackfortran.py). The Python Regular Expression module re turned out to be =
most useful for parsing fortran code lines. Note also that I was able to
produce such a parser partly because the syntax of Fortran 77/90/95=20
language is relatively simple (compared to C, for instance) and because
Python is such a nice language (that you all know anyway ;-)