Closed
Description
Hi, while testing f2py for some simple examples i stumbled upon an error, which i think i have understood the cause, but i didn't go through the f2py implementation to propose a solution.
I believe the fortran file is not parsed correctly when generating the signature file if functions and subroutines are closed with endfunction
or endsubroutine
, without space, which is allowed in the gfortran and compiles correctly.
the code test.f90 builds correctly with either end subroutine
or endsubroutine
but in the latter case, the python module loads the first subroutine (subb
) but not the second (subc
)
Reproducing code example:
test.f90
:
module test
implicit none
contains
subroutine subb(k)
real(8), intent(inout) :: k(:)
k=k+1
endsubroutine
subroutine subc(w,k)
real(8), intent(in) :: w(:)
real(8), intent(out) :: k(size(w))
k=w+1
endsubroutine
end module
build.py
:
src = open('test.f90','r').read()
from numpy import f2py
f2py.compile(source=src,source_fn='test1854.tmp.f90',extension='.f90',extra_args="--opt='-ffree-line-length-none'",modulename='test1854')
import test1854
print( test1854.test.subb.__doc__ )
import numpy as np
x=np.array([1,2,3],dtype=np.float)
print( test1854.test.subb(x))
print(x)
print( test1854.test.subc.__doc__ )
print( test1854.test.subc(x))
print(x)
Error message:
python build.py
:
Traceback (most recent call last):
File "build.py", line 10, in <module>
print( test1854.test.subc.__doc__ )
AttributeError: 'fortran' object has no attribute 'subc'
Numpy/Python version information:
1.16.4 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 19:07:31)
[GCC 7.3.0]