CoCalc Public Filesfortranmagic.ipynbOpen with one click!
Author: Harald Schilly
Views : 222
Compute Environment: Ubuntu 18.04 (Deprecated)

fortranmagic in python 3 on cocalc

In [1]:
import fortranmagic fortranmagic
<module 'fortranmagic' from '/usr/local/lib/python3.6/dist-packages/fortranmagic.py'>
In [2]:
fortranmagic.__version__
'0.6.1'
In [3]:
%load_ext fortranmagic
(not running untrusted Javascript)
In [4]:
%%fortran -v subroutine f1(x, y, z) real, intent(in) :: x,y real, intent(out) :: z z = sin(x / 3 * y / 3) + cos(x * y) end subroutine f1
Ok. The following fortran objects are ready to use: f1
In [5]:
import matplotlib.pyplot as plt import numpy as np
In [15]:
%timeit zz = f1(3, 4)
252 ns ± 18.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
In [16]:
# Some example data x_min, x_max, y_min, y_max = -2 * np.pi, 2 * np.pi, -2 * np.pi, 2 * np.pi f = [[f1(x, y) for x in np.linspace(x_min, x_max, num=500)] for y in np.linspace(y_min, y_max, num=500)] # Make the plot plt.figure(figsize=(10, 7)) plt.imshow(f, interpolation="bicubic", origin="lower", extent=[x_min, x_max, y_min, y_max]) plt.colorbar() plt.title(r"Title here (remove for papers)") plt.xlabel(r"Description of $x$ coordinate (units)") plt.ylabel(r"Description of $y$ coordinate (units)") plt.tight_layout() plt.show()
In [ ]:
In [ ]: