Fortran-compiled DLLs in Python

Thomas Heller theller at python.net
Thu May 27 10:03:05 EDT 2004


"byte biscuit" <stephen.mcphail at casaccia.enea.it> writes:

> Hi there everybody!
> The problem is the following:
> we have a DLL (H2O.dll) - compiled in Visual Fortran - depending in turn on
> another DLL.
> H2O.dll contains only one (1) function, with a known name (WATER).
> The WATER function is called with the following parameters:
> - TT (datatype: double precision)                                    [input]
> - PP (datatype: double precision)                                    [input]
> - State (datatype: integer)
> [input]
> - DiERR (datatype: integer)
> [output]
> - SIG (datatype: double precision)
> [output]
> - Prop (datatype: double precision array[16 elements])   [output]
>
> Obviously, we would like to make use of Python to handle the function and
> pick out the results...
> We thought of using the **ctypes** module to tackle the problem, but we have
> stranded just about at the first attempt:
>
>>>> from ctypes import *
>>>> h2o = windll.H2O
>>>>
> h2o.WATER(c_long(40.0),c_long(1.0),c_int(2),c_int(dierr),c_int(Sig),c_long*1
> 6(prop))
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> TypeError: int expected instead of float instance
>
> Who can show us the Right way, riding the Python? THANKS!
>
> stephen
>
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list

"Luca Simonetti" <simonettil at tiscali.it> writes:

> Hi Thomas!
> an answer from the true creator of the ctypes module - nice!
> anyway, we tried implementing your solution and got the following
> Traceback Error:
>
>>>>h2o.WATER(c_double(40.0), c_double(1.0), c_int(2),byref(dierr), byref(sig), prop)
>
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> WindowsError: exception: access violation
>
> which would seem to be the classical exception raised through a failed
> function call...?
>

This is the classical GP fault, which would normally crash a program.
ctypes catches it, but doesn't give more information (in current CVS, it
would have informed you about which memory location could not be written
or read, but that would probably not help you very much).

> - Prop (datatype: double precision array[16 elements])   [output]

I do not know how fortran passes this parameter, in the example code I
posted I assumed that the caller allocates an array, passes a pointer to
it to fortran, and the fortran code fills in the elements.

Do you have C sample code that works?

Thomas





More information about the Python-list mailing list