Skip to content

f2py: external functions declared in single line don't work #17859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
krystophny opened this issue Nov 27, 2020 · 0 comments · Fixed by #18181
Closed

f2py: external functions declared in single line don't work #17859

krystophny opened this issue Nov 27, 2020 · 0 comments · Fixed by #18181

Comments

@krystophny
Copy link

External functions (e.g. #14919 or https://stackoverflow.com/questions/44073679/errors-when-using-a-fortran-call-back-function-in-f2py) do not generate correct headers in f2py if declared in F90 style.

Reproducing code example:

Version A: two lines for external

subroutine a(fcn)
    implicit none
    external fcn
    real(8) :: fcn
    real(8) :: x, y
    x = 0d0
    y = fcn(x)
end

Version B: one line for external

subroutine a(fcn)
    implicit none
    real(8), external :: fcn
    real(8) :: x, y
    x = 0d0
    y = fcn(x)
end

Output:

Running f2py source.f90 -h header.pyf produces the following results.

Version a correctly outputs a pyf header

!    -*- f90 -*-
! Note: the context of this file is case sensitive.

python module a__user__routines
    interface a_user_interface
        function fcn(x) result (y) ! in external1.f90:a:unknown_interface
            real(kind=8) :: x
            real(kind=8) :: y
        end function fcn
    end interface a_user_interface
end python module a__user__routines
subroutine a(fcn) ! in external1.f90
    use a__user__routines
    external fcn
end subroutine a

! This file was auto-generated with f2py (version:2).
! See http://cens.ioc.ee/projects/f2py2e/

Version B incorrectly produces a header without external function

!    -*- f90 -*-
! Note: the context of this file is case sensitive.

subroutine b(fcn) ! in external2.f90
    real(kind=8) :: fcn
end subroutine b

! This file was auto-generated with f2py (version:2).
! See http://cens.ioc.ee/projects/f2py2e/

NumPy/Python version information:

1.19.4 3.9.0 (default, Oct 27 2020, 14:15:17)
[Clang 12.0.0 (clang-1200.0.32.21)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants