I have some Fortran files I would like to use in Python files. I have used the command C:\Python27\python.exe setup.py build_ext --inplace --fcompiler=g95. My setup.py file contains the following code:
import sys, os
extra_link_args = []
extra_link_args = ['-framework', 'accelerate']
from numpy.distutils.core import setup, Extension
opt_flags = ['-g', '-fbounds-check', '-I/usr/include/']
files1 = ['particle_solvers/fbsl_sim_fmod.f90',
'particle_solvers/fbsl_parts_fmod.f90',
'particle_solvers/fbsl_poisson_fmod.f90',
'particle_solvers/fbsl_convol_fmod.f90',
'particle_solvers/fbsl_lbfr_parts_fmod.f90',
'particle_solvers/fbsl_ltp_parts_fmod.f90',
'particle_solvers/fbsl_pusher_fmod.f90',
]
ext1 = Extension(name='_fbsl_f90',
sources=files1,
extra_compile_args=opt_flags,
extra_link_args=extra_link_args)
setup(name="_fbsl_f90",
version='0.1',
description="Hidden",
author="Hidden",
author_email='Hidden',
url='',
ext_modules=[ext1])
But I have got the following errors :
g95.exe:f90: build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:211
&ef2pywrap, smooth_heaviside, r)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_smooth_heaviside' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:13
&nf2pywrap, t)
1
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:217
&nf2pywrap, f_exact_is_known, t)
2
Error: Differing types REAL(8) and LOGICAL(4) in formal arguments at (1) and (2)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:223
&inal_is_knownf2pywrap, f_exact_final_is_known)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_f_exact_final_is_known'
at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:228
&2pywrap, f_exact_initial, eta_0, eta_1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_f_exact_initial' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:235
&, t, eta_0, eta_1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_f_exact' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:243
&rap, f_exact_final, eta_0, eta_1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_f_exact_final' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:250
&_field_is_givenf2pywrap, velocity_field_is_given)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_velocity_field_is_given'
at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:255
&ine_u0, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_affine_u0' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:262
&ine_u1, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_affine_u1' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:269
&p, quadratic_u0, t, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_quadratic_u0' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:277
&p, quadratic_u1, t, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_quadratic_u1' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:285
&w_0f2pywrap, bwd_affine_flow_0, t, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_bwd_affine_flow_0' at (1
)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:293
&w_1f2pywrap, bwd_affine_flow_1, t, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_bwd_affine_flow_1' at (1
)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:301
&ic_flow_0f2pywrap, bwd_quadratic_flow_0, t, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_bwd_quadratic_flow_0' at
(1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:309
&ic_flow_1f2pywrap, bwd_quadratic_flow_1, t, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_bwd_quadratic_flow_1' at
(1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:317
&0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_bggk_a' at (1)
error: Command "C:\Users\QUENTIN\bin\g95.exe -fno-second-underscore -O -Ibuild\s
rc.win32-2.7 -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\in
clude -IC:\Python27\PC -c -c build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90 -o
build\temp.win32-2.7\Release\build\src.win32-2.7\_fbsl_f90-f2pywrappers2.o -fmod
=build\temp.win32-2.7\Release\ -Ibuild\temp.win32-2.7\Release\" failed with exit
status 1
I don't understand why I have those Extra formal argument errors. How can I fix them ? I am working on Windows 7 with Python 2.7 and g95 compiler.
EDIT : Okay, to simplify, here is a sample of my Fortran code :
module test_f90
implicit none
real *8 :: delta
contains
real*8 function test_f(r)
real*8, intent(in) :: r
test_f = 0.5*( 1 + erf(r/delta) )
end function
end module test_f90
When I use the command C:\Python27\python.exe setup.py build_ext --inplace --fcompiler=g95 with this setup.py file :
import sys
extra_link_args = []
from numpy.distutils.core import setup, Extension
opt_flags = ['-g', '-fbounds-check', '-I/usr/include/']
files1 = ['test_fmod.f90',
]
ext1 = Extension(name='_test_f90',
sources=files1,
extra_compile_args=opt_flags,
extra_link_args=extra_link_args)
setup(name="_test_f90",
version='0.1',
description="test module",
author="Hidden",
author_email='Hidden',
url='',
ext_modules=[ext1])
I have got this Fortran file generated by f2py :
! -*- f90 -*-
! This file is autogenerated with f2py (version:2)
! It contains Fortran 90 wrappers to fortran functions.
subroutine f2pywrap_test_f90_test_f (test_ff2pywrap, r)
use test_f90, only : test_f
real(kind=8) r
real(kind=8) test_ff2pywrap
test_ff2pywrap = test_f(r)
end subroutine f2pywrap_test_f90_test_f
subroutine f2pyinittest_f90(f2pysetupfunc)
use test_f90, only : delta
interface
subroutine f2pywrap_test_f90_test_f (test_ff2pywrap, test_f, r)
real(kind=8) test_f
real(kind=8) r
real(kind=8) test_ff2pywrap
end subroutine f2pywrap_test_f90_test_f
end interface
external f2pysetupfunc
call f2pysetupfunc(delta,f2pywrap_test_f90_test_f)
end subroutine f2pyinittest_f90
but I still have this error :
g95.exe:f90: build\src.win32-2.7\_test_f90-f2pywrappers2.f90
In file build\src.win32-2.7\_test_f90-f2pywrappers2.f90:15
subroutine f2pywrap_test_f90_test_f (test_ff2pywrap, test_f, r)
1
Error: Extra formal argument for 'f2pywrap_test_f90_test_f' at (1)
error: Command "C:\Users\QUENTIN\bin\g95.exe -fno-second-underscore -O -Ibuild\s
rc.win32-2.7 -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\in
clude -IC:\Python27\PC -c -c build\src.win32-2.7\_test_f90-f2pywrappers2.f90 -o
build\temp.win32-2.7\Release\build\src.win32-2.7\_test_f90-f2pywrappers2.o -fmod
=build\temp.win32-2.7\Release\ -Ibuild\temp.win32-2.7\Release\" failed with exit
status 1
Sorry, it appears the f2py wrapper support is broken, as it declares a function twice with conflicting signatures: first 2 then 3 formal arguments. It's not clear this version will work for you as desired, though you might find it useful to work through the examples of the first few f2py ToC entries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With