In [1]:
%load_ext fortranmagic



In [6]:
%%fortran
    subroutine f1(n)
    INTEGER j
    INTEGER, DIMENSION(4,4) ::array
            array = reshape((/ 9,9,6,-1,9,30,5,22,6,5,10,0,-1,22,0,36 /), shape(array))
    DO 20 j = 1, n
        print *, 'NEW J'
        print *, array(1:, j)
        print *, array(j+1:,j) 
20 Continue
    END

end


	Building module "_fortran_magic_ad7f7624d535ee52eb60f74a4504fe5a"...
		Constructing wrapper function "f1"...
		  f1(n)
	Wrote C/API module "_fortran_magic_ad7f7624d535ee52eb60f74a4504fe5a" to file "/var/folders/zz/zyxvpxvq6csfxvn_n00008yc00027l/T/tmpm9Oc0Z/src.macosx-10.5-x86_64-2.7/_fortran_magic_ad7f7624d535ee52eb60f74a4504fe5amodule.c"

In [7]:
f1(4)

In [51]:
%%file test.py
import testf
testf.f1(2)


Overwriting test.py

In [52]:
!python test.py


Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import testf
ImportError: No module named testf

In [12]:
%%fortran
subroutine f1(x, y, z)
    real, intent(in) :: x,y
    real, intent(out) :: z

    z = sin(x+y)

end subroutine f1


	Building module "_fortran_magic_4d8bc857b5604a359550a6a7ae3b2578"...
		Constructing wrapper function "f1"...
		  z = f1(x,y)
	Wrote C/API module "_fortran_magic_4d8bc857b5604a359550a6a7ae3b2578" to file "/var/folders/zz/zyxvpxvq6csfxvn_n00008yc00027l/T/tmp16Inxr/src.macosx-10.5-x86_64-2.7/_fortran_magic_4d8bc857b5604a359550a6a7ae3b2578module.c"

In [7]:
import numpy as np
x = np.array([1,2,3,4])
y = np.arange(4)

In [9]:
x * y


Out[9]:
array([ 0,  2,  6, 12])

In [10]:
x.dot(y)


Out[10]:
20

In [ ]: