An extension for IPython that help to use Fortran in your interactive session.
Compile and import symbols from a cell with Fortran code, 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.
Martín Gaitán <firstname.lastname@example.org>
see this notebook
You can install or upgrade via pip
pip install -U fortran-magic
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: %load_ext fortranmagic In: %%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 the subroutine f1 is already available in your python session as a function:
In: f1(1.0, 2.1415) Out: 9.26574066397734e-05
See the documentation for further details.
0.7.1 / 2022-04-12
Synchronize version number in fortranmagic.py & setup.py (TBD, TBD, https://github.com/Serge3leo)
Patch fortran source in compiled object. (029d890, 2020-08-01, https://github.com/mgaitan)
Fix deprecation warning (3667bc1, 2017-08-18, https://github.com/guihigashi) [IPython.utils.path removed from IPython 8.x]
Simplify f2py execution. (d8a058f, 2016-06-04, https://github.com/QuLogic) Don’t change directories, and don’t mangle sys.argv. The former can be specified directly in the Popen constructor, and the latter is cruft from when the f2py module was imported directly.
0.7 / 2016-03-13
Fix cross compatibility with older NumPy and Python 3. (15ab10c)
Thanks to Elliott Sales de Andrade for this contribution
0.6 / 2015-12-02
Decode text before printing
Call f2py module instead of binary (numpy >=1.10 is mandatory)
Check if f2py command failed
Thanks to Juan Luis Cano Rodríguez for this contribution
0.5 / 2015-01-21
Call f2py via subprocess. It fixes problems finding fortran compilers under Windows. (Thanks to David Powell )
0.4.3 / 2013-12-09
Fix two python3.2+ incompatibilities (Thanks Ramon Crehuet for the report)
0.4.2 / 2013-10-08
Implement the --extra option (Thanks to Denis Vasilyev for the help)
Include %%fortran’s args in the hashing, so the same cell are recompiled with the same code but different arguments
0.3 / 2013-10-03
Added %fortran_config to set and persist default arguments for %%fortran
0.2.1 / 2013-09-24
Packaged and registered in pypi
Starting a version’s changelog
0.2 / 2013-09-19
Fortran highlighting in a %%fortran cell
Works (or it should) in any platform (linux/windows/osx) and with py3 (thanks to Bradley Froehle)
Many f2py’s arguments exposed as magic arguments
0.1 / 2013-09-08
First public release
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for fortran_magic-0.7.1-py3-none-any.whl