Fortran - DrXyzzy/cocalc GitHub Wiki

CoCalc supports various ways to run fortran code. They're provided by GNU gfortran (also f95) in the terminal.

A more convenient way to explore Fortran is to mix it with Python by using the f2py wrapper.

In a Jupyter Notebook running Python 3, there is also the fortranmagic extension available.

  1. %load_ext fortranmagic
  2. Write a function in a cell like that:
%%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
  1. Use that new function f1 in Python, e.g. f1(2.2, -1) gives -0.8305184841156006.

Ref: example worksheet