Re: [f2py] mixed f77/f90 code

Pearu Peterson <[email protected]> Wed, 24 Nov 2010 10:27:18 +0200
Newsgroups gmane.comp.python.f2py.user
Message-ID <[email protected]>
Hi jaspeR,

The fcn issue that you saw is strictly speaking expected. When 
generating wrappers to lmdif.f f2py needs to know the signature of
external fcn but it is neither provided nor available (not called within 
the subroutine). Hence the failure. If you would provide the
signature then f2py would probably build the extension module successfully.

However, it seems that you don't need to wrap all these fortran 
subroutines to python. Assuming that only fit_gm is needed to be called 
from python, I suggest the following workflow:

1) create pyf file containing signatures of only those functions that 
will be used within python:

   f2py  -m foo -h foo.pyf fit_gM.f90

1.2) optionally check foo.pyf to see if signatures needs adjustments 
(specify input and output parameters using intent(in) or intent(out), 
etc). See f2py users guide or f2py paper for more information.

2) build the extension module:
f2py -c foo.pyf *.f fit_gM.f90 Morse_mod.f90

3) check what was built:
 >>> import foo
 >>> print foo.__doc__
This module 'foo' is auto-generated with f2py (version:2_6882).
Functions:
   x,chisqr,exit_status = fit_gm(file_name,data_length,alpha,gamma1)
.

HTH,
Pearu

On 11/24/2010 08:59 AM, jaspeR wrote:
> Pearu Peterson<pearu.peterson@...>  writes:
>
>>
>> Hi,
>>
>> Could you send a more complete example demonstrating the problem?
>> The failure may not be related to f77 and f90 cooperation...
>>
>> Pearu
>
> Hi Pearu!
>
> thanks for replying so fast once more... can i mail it to you? i will include a
> makefile. the code dependencies are structured in the following way:
>
> Morse_mod.f90 contains the function subroutine required for the fit, as well as
> all the functions necessary (that is, the function, and its partial derivatives
> after the constants i am optimizing). The main program for the standalone
> fortran compilation is called fit_scalable_pot.f90, for the wrapping in f2py i
> reduced that to fit_gM.f90, excluding the terminal-output-based command
> interface. the main program (fit_scalable_pot.f90) and the reduced subroutine
> for f2py wrapping (fit_gM.f90) call the linpack subroutines. the dependency
> tree is:
>
> lmder1.f
>    ◊--lmder.f
>        ◊--dpmpar.f,enorm.f,lmpar.f,qrfac.f
>                            ◊--dpmpar.f,enorm.f,qrsolv.f
>
> line 175ff. lists the dependencies of lmder.f in detail, same goes for line
> 95ff. of lmpar.f. there might be some more cross-dependencies, they can be
> found quickly with grep dpmpar *.f, for example. they are too interwoven to
> give the whole dependency tree.
>
> thanks a lot, again. not only is f2py a great software, the support in this
> mailing list is also superior! all the best,
>
> jaspeR
>
>
> ps: the original f90 main program fit_scalable_pot.f90 also allows for fit to
> some other potentials. their module files (*_mod.f90) are included for
> completeness to allow test compiling of the main program via the makefile. for
> testing purposes, an example file 'li' is included.
>
>
>
>
> _______________________________________________
> f2py-users mailing list
> [email protected]
> http://cens.ioc.ee/mailman/listinfo/f2py-users

_______________________________________________
f2py-users mailing list
[email protected]
http://cens.ioc.ee/mailman/listinfo/f2py-users