问题描述
使用 F2Py
来编译 Fortran
例程适合在 Python中使用
F2Py
时成功编译配置gfortran作为编译器,但是在调用时, Python $ <$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $'函数select(x)result(y)
implicit none
整数,意图(in):: x(:)
整数:: i,j,temp(size(x))
integer,allocatable :: y(:)
j = 0
do i = 1,size(x)
if(x(i)/ = 0)then
j = j + 1
temp(j)= x(i)
endif
enddo
allocate(y(j))
y = temp(:j)
end function select
可以找到类似的StackOverflow文章。
> http://www.shocksolution.com/2009/09/f2py-binding-fortran-python/ ,特别是在示例中,以及
<$的含义p $ p> !f2py depends(len_a)a,bar
然而,作者没有触及生成不同大小数组的问题。
Using F2Py
to compile Fortran
routines being suitable to be used within Python
, the following piece of code is successfully compiled configured gfortran as the compiler while using F2Py
, however, at the time of invoking in Python
it raises a runtime error!
Any comments and solutions?
function select(x) result(y)
implicit none
integer,intent(in):: x(:)
integer:: i,j,temp(size(x))
integer,allocatable:: y(:)
j = 0
do i=1,size(x)
if (x(i)/=0) then
j = j+1
temp(j) = x(i)
endif
enddo
allocate(y(j))
y = temp(:j)
end function select
A similar StackOverflow post can be found here.
Take a look at this article http://www.shocksolution.com/2009/09/f2py-binding-fortran-python/ , especially at the example and the meaning of
!f2py depend(len_a) a, bar
However, the author does not touch of the problem of generating a an array of different size.
这篇关于F2Py:使用Python调用Fortran中的可分配数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!