本帖最后由 max533 于 2014-12-7 21:48 编辑
小弟百思不得其解。
為什麼在讀取完第一個檔案後,跑到第39行時,j會等於0呢???
然後因為這個算式不成立整個程序無法運行下去Q~Q
他出現的錯誤訊息是floating point divide by zero
floating point co-processor fault at adress 004015c8 in file pwv_mon_avg.f95 at line39
想請問各位高手有沒有遇過下面這種狀況,該如何改寫呢?!
程序如下:
[Fortran] 纯文本查看 复制代码 program pwv_mon_avg
implicit none
integer :: stat,i,j,stat2,year,mon,mon_def(12)
character :: filename*12,filename_new*16
real*8 :: pwv_mm,sum,pwv_mon_mean
open (11,file='list.txt')
close (11,status='delete')
call system ('for %f in (*_mon.pwv) do echo %f >> list.txt')
open (11,file='list.txt')
mon_def=(/ 01,02,03,04,05,06,07,08,09,10,11,12 /)
stat=0
do while (stat==0)
read (11,*,iostat=stat) filename
if (stat/=0) exit
open (22,file=filename)
filename_new=filename(1:4)//'_mon_avg.pwv'
open (33,file=filename_new)
do i=1,12,1
j=0
stat2=0
do while (stat2==0)
read (22,*,iostat=stat2) year,mon,pwv_mm
if (stat2/=0) exit
if (mon==mon_def(i))then
j=j+1
if (j==1) then
sum=pwv_mm
else if (j>1) then
sum=sum+pwv_mm
end if
else
cycle
end if
end do
pwv_mon_mean= sum / (j*1D0)
write (33,'(i2.2,3x,f12.7)') mon,pwv_mon_mean
end do
end do
end program 以下為測試用檔案: |