[MATRIX-SIG] Python/Fortran interface
Zane C. Motteler
motteler@laura.llnl.gov
Mon, 18 Aug 1997 07:39:59 -0700 (PDT)
Aaron et al,
On Fri, 15 Aug 1997, Aaron Watters wrote:
>Chastise me severely on evidence of stupidity!
>
>It seems to me that the first step is to know how
>to call Fortran from C: then the standard methods
>for wrapping C-functions and objects apply.
>(see the std refs or either English Python book.)
>
>As for mapping Fortran arrays (or other structures)
>into NumPy arrays, that might be trickier, and
>I'd love to look into it more (maybe in a few weeks).
>Who else knows more?
FORTRAN arrays are stored in column-major order whereas
(contiguous) NumPy arrays are stored in row-major order.
Thus to communicate a NumPy array to FORTRAN, make it
contiguous and take its transpose.
>Please let us know of success or problems.
>Brag with simple example code if you get lucky!
>A simple example of mapping a 2d fortran array
>of doubles into/out-of Numeric would be great.
>Is there such a beasty? Dr. Zane?
We have a Perl script (appropriately called Fcc)
which automates the process of calling C from FORTRAN
for many common platforms. It does so by creating
wrappers for the C functions, which convert the
FORTRAN arguments into what C expects. This is just
the reverse of what you asked for, but much of the code
could be used to go in the opposite direction. Certainly
the ideas we used are generally applicable. I can
make the script and its man page available on our
ftp site if people are interested.
Konrad mentions CFORTRAN. We used to use this;
basically it consists of a header file which creates
huge macros to do the job of argument conversion. We
found it to be very difficult to use, particularly
while debugging, because of the humongous multi-
line macros and the impenetrable code that they
generate.
Zane
-----------------------------------------------------------------------------
Zane C. Motteler, Ph. D. ___________ALSO:_________________
Computer Scientist | Professor Emeritus of Computer|
Lawrence Livermore National Laboratory | Science and Engineering |
P O Box 808, L-472 | California Polytechnic State |
Livermore, CA 94551-9900 | University, San Luis Obispo |
510/423-2143 ---------------------------------
FAX 510/423-9969
zcm@llnl.gov or motteler@laura.llnl.gov or zmottel@calpoly.edu
_______________
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________