sharing variables in fortran
Douglas du Boulay
ddb at crystal.uwa.edu.au
Wed Apr 28 21:57:23 EDT 1999
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
More information about the Python-list
mailing list