%load_ext f2pymagic import numpy as np %%f2py -f SUBROUTINE FOO(A,B) REAL*8 A, B Cf2py intent(in) a Cf2py intent(inout) b PRINT*, " A=",A," B=",B PRINT*, "INCREMENT A AND B" A = A + 1D0 B = B + 1D0 PRINT*, "NEW A=",A," B=",B END print(foo.__doc__) a=np.array(2) # these are integer rank-0 arrays b=np.array(3) print(a,b) foo(a,b) print(a, b) %%f2py SUBROUTINE FIB(A,N) C C CALCULATE FIRST N FIBONACCI NUMBERS C INTEGER N REAL*8 A(N) Cf2py intent(in) n Cf2py intent(out) a Cf2py depend(n) a DO I=1,N IF (I.EQ.1) THEN A(I) = 0.0D0 ELSEIF (I.EQ.2) THEN A(I) = 1.0D0 ELSE A(I) = A(I-1) + A(I-2) ENDIF ENDDO END print(fib.__doc__) a = fib(10) print(a) %%f2py real function r(m,t) integer m real t r = 0.1 * t * (m ** 2 + 14 * m + 46) if (r .LT. 0) r =0.0 return end r(1, 10.0) %%f2py subroutine dbl(x) real, intent(inout) :: x x = 2.0e0 * x end subroutine myvar=np.array((10.0,)) dbl(myvar) print(myvar) %%f2py module laplace implicit none contains subroutine for_update1(u, dx2, dy2, nx, ny) real(8), intent(inout) :: u(nx,ny) real(8), intent(in) :: dx2, dy2 integer, intent(in) :: nx, ny integer :: i, j do j = 2, ny-1 do i = 2, nx-1 u(i, j) = ((u(i+1, j) + u(i-1, j)) * dy2 + & (u(i, j+1) + u(i, j-1)) * dx2) / (2*(dx2+dy2)) end do end do end subroutine subroutine for_update2(u, dx2, dy2, nx, ny) real(8), intent(inout) :: u(nx,ny) real(8), intent(in) :: dx2, dy2 integer, intent(in) :: nx, ny u(2:nx-1,2:ny-1) = ((u(3:,2:ny-1)+u(:ny-2,2:ny-1))*dy2 + & (u(2:nx-1,3:) + u(2:nx-1,:ny-2))*dx2) / (2*(dx2+dy2)) end subroutine end module laplace print(laplace.__doc__)