-
Book Overview & Buying
-
Table Of Contents
Learning SciPy for Numerical and Scientific Computing Second Edition - Second Edition
SciPy provides a simple way of including Fortran code—f2py. This is a utility shipped with the NumPy libraries, which is operative when distutils from SciPy are available. This is always the case when we install SciPy.
The f2py utility is supposed to run outside Python, and it is used to create from any Fortran file a Python module that can be easily called in our sessions. Under any *nix system, we call it from the terminal. Under Windows, we recommend you run it in the native terminal, or even better, through a cygwin session.
Before being compiled with f2py, any Fortran code needs to undergo three basic changes, which are as follows:
Removal of all allocations
Transformation of the whole program into a subroutine
If anything special needs to be passed to f2py, we must add it with the comment string "!f2py" or "cf2py"
Let's illustrate the process with a simple example. The following naive subroutine, which we store in the primefactors.f90 file, performs a factorization...
Change the font size
Change margin width
Change background colour