Mixed Fortran & Python

Utility

The scripts on this page require the utility module tompy.py

* * *

f2py

f2py is a Fortran to Python interface generator.

* * *

Sample Project

The following project was performed on Ubuntu.

Here is a project that solves the generalized eigenvalue problem.

The mass & stiffness matrices are read in by a Python script.

The Python script then passes the arrays to a Fortran program for the number-crunching.

The Fortran program then returns the eigenvalues & vectors to the Python script.

The project includes an option for the standard eigenvalue problem.

Note that this project requires Lapack.

Also the python-dev header & static library must be installed.

* * *

Source Code

Here are the two Fortran scripts and their compilation commands:  eigen_general.f

f2py -c -m eigen_general eigen_general.f –fcompiler=gnu95 -llapack
eigen_standard.f

f2py -c -m eigen_general eigen_general.f –fcompiler=gnu95 -llapack
Here is the Python script:

eigenvalues.py

python eigenvalues.py -i

Note that the Python script imports the Fortran subrountines via:

import eigen_standard import eigen_general
Related Posts

Generalized Eigenvalue Problem

Vibrationdata Blog Entry – Instructions for the generalized eigenvalue problem including Lapack installation.

* * *

– Tom Irvine

One thought on “Mixed Fortran & Python

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s