Ask
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News Sign UpSign In
Project: Testing 18.04
Views: 654
Embed | Download | Raw |
Kernel: Python 3 (system-wide)

fortranmagic in python 3 on cocalc

import fortranmagic fortranmagic
fortranmagic.__version__
%load_ext fortranmagic
%%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
import matplotlib.pyplot as plt import numpy as np
%timeit zz = f1(3, 4)
# 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()