Skip to content

IPython notebook cell magic to compile and import Fortran code automatically using f2py

License

Notifications You must be signed in to change notification settings

ChaoYue/fortran_magic

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fortran magic

Compile and import everything from a Fortran code cell, using f2py.

The contents of the cell are written to a .f90 file in the directory IPYTHONDIR/fortran using a filename with the hash of the code. This file is then compiled. The resulting module is imported and all of its symbols are injected into the user's namespace.

author:Martín Gaitán <gaitan@gmail.com>
homepage:https://github.com/mgaitan/fortran_magic
example:see this notebook

Install

Install the extension with %install_ext

In[1]: %install_ext https://raw.github.com/mgaitan/fortran_magic/master/fortranmagic.py

Usage

Once it's installed, you can load it with %load_ext fortranmagic. Then put your Fortran code in a cell started with the cell magic %%fortran`. For example:

In[2]: %load_ext fortranmagic


In[3]: %%fortran

       subroutine f1(x, y, z)
            real, intent(in) :: x,y
            real, intent(out) :: z

            z = sin(x+y)

       end subroutine f1

Every symbol is automatically imported. So f1 is already available:

In[4]:  f1(1.0, 2.1415)
Out[4]: 9.26574066397734e-05

About

IPython notebook cell magic to compile and import Fortran code automatically using f2py

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published