# [MATRIX-SIG] Matrix to Fortran

**Janko Hauser
**
jhauser@ifm.uni-kiel.de

*Mon, 9 Feb 1998 13:08:50 +0100 (CET)*

At the weekend I have tried to interface NumPy with some Fortran
routines. I use for this the Cfortran package to prototype the
interface between C and Fortran, in the hope that this will be
portable. I have success with a routine wich accepts 1D arrays.
The interface looks like this (I use the LLNL defines for ease):
PROTOCCALLSFSUB11(RGRD1, rgrd1, INT, FLOATV, FLOATV, INT, FLOATV,
FLOATV, INT, INT, FLOATV, INT, INT)
#define RGRID1(nx,x,p,mx,xx,q,intpol,lw,w,lwmin,ier) \
CCALLSFSUB11(RGRD1, rgrd1, INT, FLOATV, FLOATV, INT, FLOATV, \
FLOATV, INT, INT, FLOATV, INT, INT, nx,x,p,mx,xx,q,intpol,lw,w, \
lwmin,ier)
Py_Try(PyArg_ParseTuple(args, "iOOiOOiiOii", &nx, &ox, &op,
&mx, &oxx, &oq, &intpol, &lw, &ow, &lwmin, &ier));
GET_ARR(ax, ox, PyArray_FLOAT, 1);
.
.
.
x = (float *) A_DATA (ax);
.
.
.
RGRID1(nx,x,p,mx,xx,q,intpol,lw,w,lwmin,ier);
This is ok, but if I want to interface the 2D version of regrid I
can't pass the 2D fields correctly. I pass
GET_ARR(ax, ox, PyArray_FLOAT, 2);
.
.
.
x = (float *) A_DATA (ax);
.
.
.
But in the Fortran routine I can't access the field. I have looked
into the result of f2c, where also a simple pointer is passed, and
every index calculated from the two indices.
Then, is this the right way? I hope that this will be portable. Is
there another way? This are only four subroutines, so I haven't looked
into SWIG yet, but I think I should.
__Janko
_______________
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________