知識社群Login
fortran 產生文字檔的 範例
by 高顯忠, 2010-12-08 14:16, Views(2902)
!dec$if(.false.)

檔案的內容是

y= sin(), x= 0 to 3.1415926 step dx

dx= 16等分

準備教

   0.000000  0.000000
   0.196350  0.195090
   0.392699  0.382683
   0.589049  0.555570
   0.785398  0.707107
   0.981748  0.831470
   1.178097  0.923880
   1.374447  0.980785
   1.570796  1.000000
   1.767146  0.980785
   1.963495  0.923880
   2.159845  0.831470
   2.356194  0.707107
   2.552544  0.555570
   2.748894  0.382683
   2.945243  0.195090
   3.141593  0.000000


!dec$endif
! ---------------------------------------------------------

program VF0904
implicit none
integer no
real x, y, x1, x2, dx

! plot y= sin(x), x= 0 to pi step dx
no= 16
x1= 0.0
x2= 4.0*atan(1.0)

dx= (x2 - x1)/no
x2= x2 + 0.1*dx

! for x= x1 to x2 step dx do ...
x= x1
open(unit= 1, file= 'plot-sin.txt', status= 'UNKNOWN');

do while (x .LE. x2)
  y= sin(x)
  write(unit= 1, fmt= '(1x, 2F10.6)')x, y

  x= x + dx
end do

close(1);
print *, 'Done!'
pause
end program VF0904