Я уже некоторое время использую Fortran 90 и недавно решил обернуть некоторые модули с помощью f2py для упрощения создания прототипов с использованием Python в качестве внешнего интерфейса.
Однако я столкнулся с ошибкой при попытке скомпилировать подпрограмму, которой передана внешняя функция (из Python). Вот код, который повторяет ошибку:
! file: callback.f90
subroutine callback(f,x,y)
implicit none
! - args -
! in
external :: f
real(kind=kind(0.0d0)), intent(in) :: x
! out
real(kind=kind(0.0d0)), intent(inout) :: y
y = f(x)
end subroutine
Теперь, если я использую f2py для генерации файла подписи (.pyf), вот что я получу:
! -*- f90 -*-
! Note: the context of this file is case sensitive.
python module callback__user__routines
interface callback_user_interface
function f(x) result (y) ! in :callback:callback.f90
intent(inout) f
real(kind=kind(0.0d0)) intent(in) :: x
real(kind=kind(0.0d0)) intent(inout) :: y
end function f
end interface callback_user_interface
end python module callback__user__routines
python module callback ! in
interface ! in :callback
subroutine callback(f,x,y) ! in :callback:callback.f90
use callback__user__routines
external f
real(kind=kind(0.0d0)) intent(in) :: x
real(kind=kind(0.0d0)) intent(inout) :: y
end subroutine callback
end interface
end python module callback
! This file was auto-generated with f2py (version:2).
! See http://cens.ioc.ee/projects/f2py2e/
Что не правильно, поэтому я изменяю это следующим образом:
! -*- f90 -*-
! Note: the context of this file is case sensitive.
python module __user__routines
interface
function f(x) result (y)
real(kind=kind(0.0d0)) intent(in) :: x
real(kind=kind(0.0d0)) :: y
end function f
end interface
end python module __user__routines
python module callback ! in
interface ! in :callback
subroutine callback(f,x,y)
use __user__routines
external f
real(kind=kind(0.0d0)) intent(in) :: x
real(kind=kind(0.0d0)) intent(inout) :: y
end subroutine callback
end interface
end python module callback
! This file was auto-generated with f2py (version:2).
! See http://cens.ioc.ee/projects/f2py2e/
Тем не менее оба выдают ошибку, сообщающую, что я не определил f:
callback.f90:1:21:
subroutine callback(f,x,y)
1
Error: Symbol ‘f’ at (1) has no IMPLICIT type
callback.f90:10:6:
y = f(x)
1
Error: Can't convert UNKNOWN to REAL(8) at (1)
callback.f90:1:21:
subroutine callback(f,x,y)
1
Error: Symbol ‘f’ at (1) has no IMPLICIT type
callback.f90:10:6:
y = f(x)
1
Error: Can't convert UNKNOWN to REAL(8) at (1)
Я провел как можно больше исследований по правильному редактированию файла подписи .pyf вручную, но безрезультатно в этом случае. Кто-нибудь сталкивался с подобной ошибкой при попытке использовать f2py с внешними функциями?