I am new to Fortran and I am trying to run fortran inside python using f2py. I have had luck when the fortran function gave output as a single value. But when I modified the fortran function to give out an array, I am getting segmentation faults.
Could someone please help me out?
Here is the code:
Fortran function: in file called 'fortfunc.f95':
function fut(x,n)
implicit none
real, intent(in) :: x
integer, intent(in) :: n
real, dimension(2) :: fut
! My aim is to return an array fut which has 2 elements in it
fut(1)=x*n
fut(2)=x*n*100
end function fut
Then I use f2py to compile fortran function to be used in python:
f2py -c -m func fortfunc.f95
here func is name of module to be imported in python
Python code: (pretty straightforward)
import func # func is the name of module which contains function fut
x=20
n=20
res=func.fut(x,n)
print('answer is ',res)
I wish to get an array with 2 elements called 'res' but instead I get 'Segmentation fault: 11'
Can someone please point out my mistake?