I’m using ctypes (Pthyon3.2) to call F90 routines from a shared library on a 64-bit Debian Linux machine. If the F90 routine takes and argument of type,
! We're in fortran (F90)
subroutine MyFunc(FooF90)
real(8),intent(in) :: FooF90
! do some stuff...
return
what should I pass from Python? My guess is,
# We're in Python3.2
F90func(ctypes.byref(ctypes.c_double(FooPy)))
Is this correct? I couldn’t easily find a reference for passing fortran arguments of type real(n) from Python.
Thanks in advance.
real(8)is not defined by the standard, so anything can happen (you should get the kind number byselected_real_kindoriso_c_bindingoriso_fortran_env). In practice it will be equivalent toc_doublefor most compilers. You are probably using gfortran for which this holds by default.There might be a problem, if the Python interpreter expects by
valueargument passing by default. Search forbyref()function in ctypes.