[Numpy-discussion] Do not understand what f2py is reporting

Samuel Dupree sdupree at speakeasy.net
Mon Nov 2 23:26:00 EST 2020


Andras,

Thank you for respond to my post. I sincerely appreciate it.

Following your advice, I replaced "integer * 4" with "integer" and I was 
able to generate the signature files for gravity_derivs.f. The problem 
now is generating the signature file for auto_deriv.f90.

I agree that f2py has a problem with

In: :auto_deriv:auto_deriv.f90:ad_auxiliary
get_parameters: got "invalid syntax (<string>, line 1)" on 
'(/((i,i=j,n), j=1,n)/)'

I'm not sure I understand why f2py has a problem with this syntax. Is 
there documentation that talks to what Fortran77, Fortran 90/95 syntax 
f2py will and will not accept?

Sam Dupree.



On November/02/2020 07:22:06, Andras Deak wrote:
> On Sun, Nov 1, 2020 at 2:33 AM Samuel Dupree <sdupree at speakeasy.net> wrote:
>> I'm attempting to build wrappers around two Fortran routines. One is a
>> Fortran 77 subroutine (see file gravity_derivs.f) that calls a Fortran
>> 90 package that performs automatic differentiation (see file
>> auto_deriv.f90).
>>
>> I'm running he Anaconda distribution for Python 3.7.6 on a Mac Pro
>> (2019) under Mac OS X Catalina (ver. 10.15.6). The version of NumPy I'm
>> running is 1.18.3. The commands I used to attempt the build are
>> contained in the file auto_deriv_build. The messages output by f2py are
>> captured in the file auto_derivs_build_report.txt.
>>
>> I don't understand the cause behind the error messages I got, so any
>> advice would be welcomed.
>>
>> Sam Dupree.
> Hi Sam,
>
> I've got a partial solution.
> I haven't used f2py yet but at least the error from your first `f2py`
> call seems straightforward. Near the top:
>
>      Line #119 in gravity_derivs.f:"      integer * 4            degree"
>          updatevars: no name pattern found for entity='*4degree'. Skipping.
>
> This shows that the fortran code gets parsed as `(integer)
> (*4degree)`. That can't be right. There might be a way to tell f2py to
> do this right, but anyway I could make your code compile by replacing
> every such declaration with `integer * 4 :: degree` etc (i.e. adding
> double colons everywhere).
> Once that's fixed your first f2py call raises another error:
>
>      Fatal Error: Cannot open module file ‘deriv_class.mod’ for reading
> at (1): No such file or directory
>
> I could generate these mod files by manually running `gfortran -c
> auto_deriv.f90`. After that the .mod files appear and your first
> `f2py` call will succed.
> You can now `import gravity_derivs`, but of course this will lead to
> an error because `auto_deriv` is not available in python.
> Unfortunately your _second_` f2py` call also dies on `auto_deriv.f90`,
> with such offending lines:
>
>      In: :auto_deriv:auto_deriv.f90:ad_auxiliary
>      get_parameters: got "invalid syntax (<string>, line 1)" on '(/((i,
> i=j,n), j=1,n)/)'
>
> I'm guessing that again f2py can't parse that syntax.
> My hunch is that if you can get f2py to work with `auto_deriv.f90` you
> should first run that. This should hopefully generate the .mod files
> after which the second call to `f2py` with `gravity_derivs.f` should
> work. If `f2py` doesn't generate the .mod files you could at worst run
> your fortran compiler yourself between the two calls to `f2py`.
> Cheers,
>
> András
>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at python.org
>> https://mail.python.org/mailman/listinfo/numpy-discussion
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list