Fortran magic
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.
- homepage:
- documentation:
see this notebook
Install
You can install or upgrade via pip
pip install -U fortran-magic
Basic 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[1]: %load_ext fortranmagic
In[2]: import sys
if sys.platform.startswith("win"):
# Depends of system, python builds, and compilers compatibility.
# See `documentation.ipnb`.
%fortran_config --fcompiler=gnu95 --compiler=mingw32
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 the subroutine f1 is already available in your python session as a function:
In[4]: f1(1.0, 2.1415) Out[4]: 9.26574066397734e-05
See the documentation for further details.
Changelog
0.8 / 2023-06-08
Fix use deprecating imp module (removed from Python 3.12b2)
Fix exponential duplication any not boolean flags of %%fortran_config
Include stored %%fortran_config’s args in hashing
Don’t rebuild cell if the module already loaded and hash not changed (Unix don’t reload already loaded shared library with same name. Windows can’t rewrite already loaded DLL)
Repair fortran highlighting in a %%fortran cell for nbclassic (Fortran highlighting for JupyterLab - unimplemented, for IPython 3.x - removed)
Printing compilers diagnostics for build errors by %%fortran without -vvv flag
0.7.1 / 2023-04-12
Synchronize version number in fortranmagic.py & setup.py (2023-04-10, 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
Improve documentation
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
Verbosity handling
Improved documentation
0.1 / 2013-09-08
First public release
Metadata
Release files for fortran-magic 0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| fortran-magic-0.8.tar.gz | 15.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fortran_magic-0.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.3 kB
Release files / fortran-magic-0.8.tar.gz
| Download URL | fortran-magic-0.8.tar.gz |
|---|---|
| Size | 15.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d5dcdbbc930cd47c3fadaf34775d25934014c7adfd86392a2dfccfec663b8ac5
|
|
BLAKE2b-256 checksum How to use checksums |
a330a2f06c456501bf4a5f142e6fc635a87fcf21b0480653f87184b73f11da42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Release files / fortran_magic-0.8-py3-none-any.whl
| Download URL | fortran_magic-0.8-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af08fe345d9a0d6eb1128abb346003b0be51da43a4ba7adf97186d4cb91e5c79
|
|
BLAKE2b-256 checksum How to use checksums |
29b45558fc0b4f7e403a4f5f43ebc88999e3b2b91e4858eb075a3cf9ad802aad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Security for fortran-magic 0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.