Sharedfortranmagic.ipynbOpen in CoCalc

fortranmagic in python 3 on cocalc

import fortranmagic
<module 'fortranmagic' from '/usr/local/lib/python3.6/dist-packages/'>
%load_ext fortranmagic
(not running untrusted Javascript)
%%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
import matplotlib.pyplot as plt
import numpy as np
xx, yy = np.meshgrid(np.linspace(-10, 10, 100), np.linspace(-10, 10, 100))
%timeit zz = f1(xx, yy)
812 ns ± 33.6 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
# 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.title(r"Title here (remove for papers)")
plt.xlabel(r"Description of $x$ coordinate (units)")
plt.ylabel(r"Description of $y$ coordinate (units)")