[問題] 請問要怎麼寫才對...

作者: qrew24   2014-03-19 18:49:23
我的程式碼如下:
open(1,file='10-0123-20L.S200510')
open(2,file='list')
do while (.true.)
read(1,'(1x,i4,1x,i2,i2,1x,i2,i2,1x,i2.2,f2.1,4x,f6.3,1x,f7.3,
& i3.3,f2.1,t80,a1)',end=99)
& year,mon,day,hour,min,se1,se2,lat,lon,d1,d2,typ
end do
do while (.true.)
read(1,'(1x,a4,4x,a2,7x,i2.2,i2.2,1x,i2.2,f3.2)',end=999)
& sta,phas,hh,mm,s1,s2
if((typ=='1').and.(phas=='IP'))then
parr=((hour*60+min)*60+(se1+se2))-((hh*60+mm)*60+(s1+s2))
write(2,'(f6.3,1x,f7.3,1x,i3.3,f2.1,1x,i4,1x,i2.2,1x,i2.2,1x
& ,i2.2,1x,i2.2,1x,i2.2,f2.1)')
& lat,lon,d1,d2,year,mon,day,hour,min,se1,se2,sta,phsa,parr
end if
end do
99 continue
999 continue
close(1)
close(2)
END
這是想要用來讀一個檔案裡面的資訊,再做輸出.
但是只有第一段do while讀得出來,為什麼第二段do while讀不出來?
檔案內容大致如下:
2005 1010 0123 20.1fL 21.310 120.068 7.0 TW6 3 0.0 1
GAP=154 0.32 1.0 0.9 2.0 -0.2403E+00 0.4331E+00 0.2387E+00E
2005-10-10-0123-16.obs01_001 6
ACTION:UP 14-02-11 14:29 OP:debb STATUS: ID:20051010012320 L I
OBS6 SZ IP 123 25.94 44 -0.0610 19.0 87
照這檔案來看,我只想要第一列和第四列.
先謝謝大家了!
作者: Cypresslin (啊哈哈~~)   2014-03-19 21:23:00
因為你的第一個do while就把檔案整個讀完了然後你要作的應該是把兩個迴圈合成一個,因為以第一個迴圈來說,他會用你的那個日期格式來讀檔案中的每一行

Links booklink

Contact Us: admin [ a t ] ucptt.com