Re: [f2py] problems with parameters and common blocks

Ben Forbes <[email protected]> Mon, 15 Aug 2011 17:55:33 +1000
Newsgroups gmane.comp.python.f2py.user
Message-ID <CACc3ktRBK8dXDjzF=Hn6i4Pi+69qN8Wbpojp1=SgYPbm2brmxg@mail.gmail.com>
Hi Clemens,

I'm guessing it's not possible to have the module limit itself to
using only 'someCount' entries? In that case it does indeed seem a
difficult problem.

Ben

On Mon, Aug 15, 2011 at 5:38 PM, teichmann.clemens
<teichmann.clemens-gM/[email protected]> wrote:
> Hi Pearu,
>
> thanks for that advice, but the actual size of the array is dynamic between
> two or more runs. In my example it has the size four, but it could also be
> smaller/bigger up to max value. At the moment I'm trying to append dummy
> values to the arrays and check the internal computation. If this doesn't
> work, i need to change the size of the arrays in the modul (after it was
> wrapped) or dynamic wrap the fortran program, which could be really hard.
>
> Hi Ben,
>
> A little example to demonstrate my problem.
> this is my common.f
>       integer someCount
>       integer maxg
>       parameter (maxg = 22)
>       real*8 c(maxg)
>       common /asd/
>      *            c,
>      *            someCount
>
> and the subroutine
>       subroutine foo()
>       include 'common.f'
>       integer sum
>       sum = 0
>
>       do 111 i = 1,someCount
>       sum = sum + c(i)
>   111 continue
>
>       return
>       end
>
> the variable "someCount" and the array "c" is set in the python program.
> someCount can now have e.g. the value four, because there are just four
> elements to compute. Because of the parameter maxg, the modul wants a list
> with exact 22 entries to set the array "c"
>
> greetings,
> Clemens
>
> 2011/8/15 Pearu Peterson <[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
>>
>> _______________________________________________
>> f2py-users mailing list
>> f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
>> http://cens.ioc.ee/mailman/listinfo/f2py-users
>
>
> _______________________________________________
> f2py-users mailing list
> f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
> http://cens.ioc.ee/mailman/listinfo/f2py-users
>
>



-- 
Benjamin D. Forbes
School of Physics
The University of Melbourne
Parkville, VIC 3010, Australia