implicit real*8(a-h,o-z) real*8 x, y, y2 integer i c do i = 0 , 500 x = i / 100.0d0 y = f1s(x) y2 = y**2 write(6,'(3e20.10)') x , y, y2 end do end c================================================================== real*8 function f1s(r) c c 1s function for hydrogen atom c implicit real*8(a-h,o-z) parameter(r0 = 0.529d0) c f1s = ( 1/r0 )**(1.5d0) * exp(-r/r0) c return end
さて、上のプログラムを"Intro"を使ってコンパイル、実行してみましょう。
ただし計算の出力結果は100行にもわたるので、出力ファイルを指定して
おきましょう。Introの設定を変更していなければ出力ファイル名を指定
できないのですが、これをできるようにする方法を
山本君に教えてもらいました。もちろん私が口頭で以前説明したshellから
利用する方法でもよいのですが、こちらの方がわかりやすいと思います。ここでは
その出力ファイル名をprog7-1.outと
しておきます。
次にグラフを作成するソフトを起動します。現在みなさんが使っている
NextStepの中にグラフ作成ツールはいくつかありますが、ここでは"GNUPLOT"を
使用します。
"GNUPLOT"はファイルビューアを使って起動します。場所は
implicit real*8(a-h,o-z) real*8 pi, x0, dm, s, x, y, a, rr, xx, yy integer i c pi = atan(1.0d0)*4.0d0 x0 = 2.0d1 dm = 0.1d0 s = 100.0d0 / x0 c do i = 1 , 50000 x = x0 * irnd() * 1.0d-8 y = dm * irnd() * 1.0d-8 if( f1s(x) .gt. y ) then rr = s * x a = 2.0d0 * pi * irnd() * 1.0d-8 xx = rr*cos(a) yy = rr*sin(a) write(6,'(2e20.10)') xx , yy end if end do end c================================================================== real*8 function f1s(r) c c 1s function for hydrogen atom c implicit real*8(a-h,o-z) parameter(r0 = 0.529d0) c f1s = ( 1/r0 )**3 * r*r * exp(-2.0d0*r/r0) c return end c================================================================== integer function irnd() integer m1, m2, m3, i save m1, m2, m3 c data m1, m2, m3/92658393, 76438567, 65428733/ 1 continue i = m1 + m2 + m3 if( m2 .lt. 50000000) i = i + 1357 if( i .ge. 100000000) i = i - 100000000 if( i .ge. 100000000) i = i - 100000000 m1 = m2 m2 = m3 m3 = i irnd = i c return end
またコンパイル回数、実行回数の報告は特にしなくて結構です。むしろ試行錯誤を いろいろやらないとうまくいかないものもあると思います。