max533 发表于 2015-2-9 21:30:04

關於循序讀檔的問題

如題:在第2個迴圈內,我因為同一個檔案想一次讀2行再讓他返回前一行,並進行計算,檔案還沒讀完但卻在讀完2行之後就直接跳出,我該怎麼辦呢?!
stat2和stat3都在讀完一次之後就不再是0,是我哪裡有設計錯誤嗎?!

感謝各位高手幫忙解答!!!
以下為程序代碼:
program radiosonde_PWV_B
implicit none

integer :: stat,stat2,stat3,height_m1,height_m2,yr1,doy1,hr1,yr2,doy2,hr2
character :: filename*13,filename_new*13
real*8 :: timeall1,part_vapor_weight1,timeall2,part_vapor_weight2,pwv

open (11,file='list.txt')
close (11,status='delete')
call system ('dir /b *.radio2 > list.txt')
open (11,file='list.txt')

stat=0
do while (stat==0)
read (11,*,iostat=stat) filename
if (stat/=0) exit
open (22,file=filename)
filename_new=filename(1:6)//'.radio3'
open (33,file=filename_new)

stat2=0
stat3=0
do while (stat2==0 .and. stat3==0)
    read (22,*,iostat=stat2) timeall1,height_m1,part_vapor_weight1,yr1,doy1,hr1
    read (22,*,iostat=stat3) timeall2,height_m2,part_vapor_weight2,yr2,doy2,hr2
    if (stat2/=0 .or. stat3/=0) exit
    backspace (22)
    if ( hr1==hr2 ) then
      pwv=(part_vapor_weight1+part_vapor_weight2)*(height_m2-height_m1)*1D3/2
      write (33,50) timeall1,height_m1,height_m2,pwv,yr1,doy1,hr1
50    format (f12.7,1x,i5.5,1x,i5.5,1x,f12.7,1x,i4,1x,i3.3,1x,i2.2)
    else if ( hr1/=hr2 ) then
      cycle
    end if      
end do
end do
end program



以下為測試數據:




fcode 发表于 2015-2-10 10:35:06

yr1,doy1,hr1,yr2,doy2,hr2 这些变量应为 real 类型

max533 发表于 2015-2-10 10:48:33

fcode 发表于 2015-2-10 10:35
yr1,doy1,hr1,yr2,doy2,hr2 这些变量应为 real 类型

為什麼呢?!這些變數都在原始資料中都是整數耶!!!

fcode 发表于 2015-2-10 13:15:56

1994.0009406    00011             1022.1 14.0    76   0.0000104187 1994 001 08
timeall1    height_m1,part_vapor_weight1, yr1, doy1,         hr1

1994.0009406 timeall1
00011         height_m1
1022.1      part_vapor_weight1
14.0         yr1   这是real
76         doy1
0.0000104187 hr1这也是

max533 发表于 2015-2-10 22:11:00

fcode 发表于 2015-2-10 13:15
1994.0009406    00011             1022.1 14.0    76   0.0000104187 1994 001 08
timeall1    height_m1 ...

感謝大大提醒,的確因為沒有讀好檔案,造成檔案判斷讓iostat回傳的值不等於0。
页: [1]
查看完整版本: 關於循序讀檔的問題