I have a legacy code in Fortran for creation of FDq-matrices
. The code consists of a subroutine, which I would like to be able to call in Python. This subroutine itself uses Fortran modules.
Subroutine which I need to call from Python:
- finiteDifferences.f90
Modules used within subroutine:
- Lagrange_Interpolation_Method.f
- Linear_Algebra_Lapack.f
- Nonlinear_Algebra.f
- Piecewise_Polynomial_Interpolation.f
- Optimum_Grid_Methods.f
Ideally, I would like to end up with an fdq.so
file which I could import into my python code.
I am perfectly capable of using F2PY
to create .so
file from a single subroutine, even including Lapack. But I don't know how to work with subroutines which call for modules.
For simple compilation I add a program main.f90
which calls the subroutine and I use following command:
gfortran -O3 -o fdq -fcheck=all -ffree-form -fdefault-double-8 -fdefault-real-8 -framework Accelerate -Wall Lagrange_Interpolation_Method.f90 Nonlinear_Algebra.f90 Linear_Algebra_Lapack.f90 Piecewise_Polynomial_Interpolation.f90 Optimum_Grid_Methods.f90 finiteDifferences.f90 main.f90
Then when calling for F2PY with following command:
f2py3 -c --verbose --opt='-O3 -fcheck=all -ffree-form -fdefault-double-8 -fdefault-real-8 -framework Accelerate' Lagrange_Interpolation_Method.f90 Nonlinear_Algebra.f90 Linear_Algebra_Lapack.f90 Piecewise_Polynomial_Interpolation.f90 Optimum_Grid_Methods.f90 finiteDifferences.f90 -m fdq
The first error produced by the above command:
/var/folders/bj/4qqzkp4560d75dw4wr7tpmr00000gn/T/tmp39eelon3/src.macosx-13-arm64-3.11/fdqmodule.c:578:23: error: expected expression nodes_Dims[0]=1 + ; ^