From: ddb at crystal.uwa.edu.au (Douglas du Boulay)
Date: Thu, 29 Apr 1999 09:57:23 +0800
Subject: sharing variables in fortran
References: <3725643A.734B9F06@crystal.uwa.edu.au> <Pine.LNX.4.04.9904270241500.31241-100000@us2.mayo.edu>
Message-ID: <3727BC83.831910A@crystal.uwa.edu.au>
Content-Length: 1364
X-UID: 173                                                  

Travis Oliphant wrote:

> > I am wondering if it is possible to coerce python to use
> > memory  addresses corresponding to a fortran common block (by way of a c
> > extension)
> > for storage of certain variables.

> There is an exported function you can call from C called
> PyArray_FromDimsAndData that creates a NumPy array from some dimension
> information and a pointer to already allocated memory.  There is some
> improving documentation on the C-API to Numeric in the documentation
> recently released for NumPy.  See the scientific computing topic section
> of www.python.org
>
> I'm not sure how to access a Fortran common block from C at the moment.
>

Thanks Travis, that at least gets me started

If I can borrow from  Greg Landrums reply:

if  testblock is my fortran common block,
the equivalent in C is

typedef struct {
  float var1;
  int var2;
} common1;
common1 testblock;        /* a global  block that exists for the entire
period of module use */

so if  I   have  a testmodule.c  file with:

typedef struct {
        PyObject_HEAD
                                    /*  something is missing here */
} TestObject;

What do I have to put in the TestObject struct  to be able to read and write
the  var1 and var2  variables
directly in  a python script  with something along the lines of
self.testblock.var1=2.0    ?

Thanks again.
Doug





