CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Avatar for Testing 18.04.

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

| Download
Project: Testing 18.04
Views: 709
Kernel: Python 3 (system-wide)

fortranmagic in python 3 on cocalc

import fortranmagic fortranmagic
<module 'fortranmagic' from '/usr/local/lib/python3.6/dist-packages/fortranmagic.py'>
fortranmagic.__version__
'0.6.1'
%load_ext fortranmagic
MIME type unknown not supported
%%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
%timeit zz = f1(3, 4)
252 ns ± 18.3 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.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()
Image in a Jupyter notebook