I have a python main program that calls a subroutine from a fortran program, the subroutine works well when i write without the 'module, implicit none' sentence but doesnt work with it
heres a reproducible exaple of the code that works:
#data.csv is where i read the data from
a,b,c
1,5,0.3
2,8,0.6
3,9,0.7
4,16,0.2
5,23,0.4
#from python
import pandas as pd
import pymod
from numpy import *
data = pd.read_csv('data.csv')
column = data.columns
x_data = data[column[0]].values
y_data = data[column[1]].values
data_len = len(data)
a, b, sa, sb, r_squared, sigma = pymod.simple_lin_fit(x_data, y_data, data_len)
print(a, b, sa ,sb, r_squared)
#pymod.f90
subroutine simple_lin_fit(x_data, y_data, N, a, b, sa, sb, r_squared, sigma)
implicit none
real(kind = 8), dimension(N) , intent(in) :: x_data, y_data
real(kind = 8), intent(out) :: a, b, sa, sb, r_squared, sigma
real(kind = 8) :: sum_x, sum_xx, sum_xy, sum_y, sum_yy, SSE, SXX, SXY, SYY
integer, intent(in) :: N
sum_x = sum(x_data)
sum_y = sum(y_data)
sum_xx = sum(x_data**2)
sum_yy = sum(y_data**2)
sum_xy = sum(x_data*y_data)
SXY = sum_xy - sum_x*sum_y/N
SXX = sum_xx - sum_x**2/N
SYY = sum_yy - sum_y**2/N
a = SXY/SXX
b = (sum_y - a*sum_x)/N
SSE = sum((y_data-a*x_data-b)**2)
sigma = sqrt(SSE/(N-2))
r_squared = 1 - SSE/SYY
sa = sigma/sqrt(SXX)
sb = sa*sqrt(sum_xx/N)
end subroutine simple_lin_fit
it works very well, when i compile it, but it doesnt work when i put the scentences
module pymod
implicit none
contains
<subroutine>
end module
in it,and i need to write it as a fortran module because I need to add some other modules to the fortran module
the error i've got is this
Traceback (most recent call last):
File "lin_fit.py", line 27, in <module>
a, b, sa, sb, r_squared, sigma = pymod.simple_lin_fit(x_data, y_data, N)
AttributeError: module 'pymod' has no attribute 'simple_lin_fit'
im compiling it with
f2py3 -m pymod -c pymod.f90 mv .so pymod.so
python3 pythonprogram.py