Metadata-Version: 2.4
Name: fortran-magic
Version: 1.0
Summary: An IPython extension for compiling and using Fortran code interactively.
Project-URL: Homepage, https://github.com/mgaitan/fortran_magic
Project-URL: Documentation, https://nbviewer.org/github/mgaitan/fortran_magic/blob/master/documentation.ipynb
Project-URL: Changelog, https://github.com/mgaitan/fortran_magic/blob/master/CHANGES.md
Project-URL: Repository, https://github.com/mgaitan/fortran_magic
Project-URL: Issues, https://github.com/mgaitan/fortran_magic/issues
Author-email: Martin Gaitan <gaitan@gmail.com>
License: Copyright (c) 2013, Martín Gaitán
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without modification,
        are permitted provided that the following conditions are met:
        
          Redistributions of source code must retain the above copyright notice, this
          list of conditions and the following disclaimer.
        
          Redistributions in binary form must reproduce the above copyright notice, this
          list of conditions and the following disclaimer in the documentation and/or
          other materials provided with the distribution.
        
          Neither the name of the {organization} nor the names of its
          contributors may be used to endorse or promote products derived from
          this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
        ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
        WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
        ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
        (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
        LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
        ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
        SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License-File: LICENSE
Keywords: f2py,fortran,ipython,notebook,science
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Framework :: IPython
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Fortran
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: <3.16,>=3.10
Requires-Dist: ipython
Requires-Dist: meson
Requires-Dist: ninja
Requires-Dist: numpy
Description-Content-Type: text/markdown

# Fortran magic

[![PyPI](https://img.shields.io/pypi/v/fortran-magic)](https://pypi.python.org/pypi/fortran-magic)
[![CI](https://github.com/mgaitan/fortran_magic/actions/workflows/micromamba.yml/badge.svg)](https://github.com/mgaitan/fortran_magic/actions/workflows/micromamba.yml)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/fortran-magic)](https://pypi.python.org/pypi/fortran-magic)

Compile and import symbols from a cell with Fortran code, using [f2py](https://numpy.org/doc/stable/f2py/).

> **Attention:** I am looking for collaborators to maintain this project. If you are interested,
> please open an issue (or PRs) with your proposals for improvements and volunteer to be a maintainer.

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: https://github.com/mgaitan/fortran_magic
- Documentation: see [this notebook](https://nbviewer.org/github/mgaitan/fortran_magic/blob/master/documentation.ipynb)

## Install

You can install or upgrade via [uv](https://docs.astral.sh/uv/):

```bash
uv add fortran-magic
```

Or via pip:

```bash
pip install -U fortran-magic
```

Or run directly

```bash
uv run --with=fortran-magic ipython
```

## 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:

```text
In[1]: %load_ext fortranmagic

In[2]: %%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:

```text
In[3]:  f1(1.0, 2.1415)
Out[3]: 9.26574066397734e-05
```

## Tests

Run tests with:

```text
uv run --group dev pytest
```

See the documentation for further details.
