Re: [f2py] problems with parameters and common blocks
Pearu Peterson <[email protected]> Mon, 15 Aug 2011 09:50:53 +0300
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <[email protected]> |
Hi,
On 08/15/2011 09:30 AM, teichmann.clemens wrote:
> Hello,
>
> I'm developing a python interface for an xml data set and an old fortran
> program (xml -> python -> fortran). Because the main computation
> subroutine needs many variables, the values are written to variables in
> common-blocks. In this common blocks are also arrays that have the size
> of previously given parameters. These parameters are just maximum values
> (e.g. a maximum amount of sth to compute). So an arrays is initiated
> with the size 20 even though there were just the first four entries set.
> In the subroutine, e.g. for-loops just iterate over those four entries
> using a previously given counter. My problem is that f2py just know the
> max value (which makes sense) and so if i handover a python list with
> just those four values, there is an system error:
> SystemError: error return without exception set
> 0-th dimension must be fixed to 22 but got 4
>
> Is there any possibilty to either change the parameters before the modul
> is implemented or change the size of the arrays? I thought of using
> dummy entries for the python lists, but this isn't my desired solution.
If the size of the array is always fixed to 4 for the user then you
could wrap your fortran programs in three steps:
1) Generate signature file:
f2py foo.f -h foo.pyf
2) Edit foo.pyf by replacing 22 with 4 in all relevant places (the
dimension specifications of the common block array)
3) Build extension module using the signature file as input:
f2py -c foo.pyf foo.f
HTH,
Pearu