Using Fortran code through f2py
Fortran (derived from Formula Translation) is a mature programming language mostly used for scientific computing. It was developed in the 1950s with newer versions emerging, such as Fortran 77, Fortran 90, Fortran 95, Fortran 2003, and Fortran 2008 (refer to http://en.wikipedia.org/wiki/Fortran). Each version added features and new programming paradigms. We will need a Fortran compiler for this example. The gfortran
compiler is a GNU Fortran compiler, and can be downloaded from http://gcc.gnu.org/wiki/GFortranBinaries.
The NumPy f2py
module serves as an interface between Fortran and Python. If a Fortran compiler is present, we can create a shared library from Fortran code using this module. We will write a Fortran subroutine that is intended to sum the rain amount values as given in the previous examples. Define the subroutine and store it in a Python string. After that, we can call the f2py.compile()
function to produce a shared library from the Fortran...