読者です 読者をやめる 読者になる 読者になる

fortran66のブログ

fortran について書きます。

IPython + f2py ( Intel Visual Fortran ) Mandelbrot set

備忘メモ帳

よくわからんwww

f:id:fortran66:20140227042221p:plain

インテル(R) 64 Visual Studio 2010 モード コマンドプロンプトより (Canopy command prompt はなぜだか不可)

chcp 437
"C:\Program Files (x86)\Intel\Composer XE 2013 SP1\bin\ipsxe-comp-vars.bat" intel64 vs2010
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat"
set DISTUTILS_USE_SDK=1
"C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\SetEnv" /x64 /release
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe"

fortran

    subroutine cmandel(c, m)
        integer, parameter :: maxiter = 255
        integer, parameter :: kd = kind(1.0d0)
        complex(kd), intent(in ) :: c
        integer    , intent(out) :: m
        complex(kd) :: z
        z = c
        do m = maxiter, 1, -1
          if (abs(z) > 2.0_kd) exit
          z = z**2 + c
        end do 
        return
    end subroutine cmandel 

f2py

!f2py -c --fcompiler=intelvem -m mandel mandelf2py.f90

python

from PIL import Image
import mandel
x0 = -2.0
x1 =  2.0
y0 = -2.0
y1 =  2.0
nx = 512
ny = 512
img = Image.new("RGB", (nx, ny))

for iy in range(ny):
    y = iy * (y1 - y0) / (ny - 1)  + y0
    for ix in range(nx):
        x = ix * (x1 - x0) / (nx - 1)  + x0
        z = complex(x, y)
        m = mandel.cmandel(z)
        img.putpixel((ix, iy), ((5 * m) % 256, m, (10 * m) % 256))

imshow(img)
img.save("mandel.png", "PNG")

f:id:fortran66:20140227042435p:plain