C and Python interoperability

A Fortran program rarely stands alone. iso_c_binding gives the kinds, the types and the BIND(C) attribute that make a call across the boundary legal, in both directions: C from Fortran and Fortran from C. The last lessons leave the C boundary for the Python one, where a shared library built with -shared -fPIC is called through ctypes, and where f2py would do the same work if it were installed.

104 iso_c_binding: kinds and types c_int, c_double, c_char, c_ptr, c_null_ptr and the bind(c) attribute Open 105 Calling C from Fortran an INTERFACE BIND(C), a C function called from Fortran, and the two files built together Open 106 Being called from C BIND(C) on a Fortran subroutine, a C main that calls it, and the array that crosses the boundary Open 107 Calling Fortran from Python with ctypes a shared library built with -shared -fPIC, ctypes.CDLL, argtypes and a real call Open 108 Interoperable derived types BIND(C) on a derived type, c_ptr and c_f_pointer, and a struct shared with C Open 109 f2py and the tools not in this image what f2py does, why it is not run here, the install route in words, and the ctypes route that was run Open

Lessons