Coder Social home page Coder Social logo

mgaitan / fortran_magic Goto Github PK

View Code? Open in Web Editor NEW
116.0 12.0 33.0 79 KB

An extension for IPython/Jupyter that helps to use Fortran in your interactive session.

License: BSD 3-Clause "New" or "Revised" License

Python 55.65% Jupyter Notebook 41.76% Fortran 1.40% Shell 1.20%

fortran_magic's Introduction

Fortran magic

PyPI PyPI - Downloads

Compile and import symbols from a cell with Fortran code, using 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

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.