FORTRAN

Load a 64-bit FORTRAN library in 64-bit Python (view the FORTRAN source code). To load the 32-bit library in 32-bit Python use '/fortran_lib32'.

>>> from msl.loadlib import LoadLibrary
>>> from msl.examples.loadlib import EXAMPLES_DIR
>>> fortran = LoadLibrary(EXAMPLES_DIR + '/fortran_lib64')

Call the factorial function. With a FORTRAN library you must pass values by reference using ctypes, and, since the returned value is not of type ctypes.c_int we must configure ctypes for a value of type ctypes.c_double to be returned

>>> from ctypes import byref, c_int, c_double
>>> fortran.lib.factorial.restype = c_double
>>> fortran.lib.factorial(byref(c_int(37)))
1.3763753091226343e+43