主题:求助:怎么用Fortran将开头相同的多行数据只输出为一行
一个如下形式的数据文件:
66666 0 49 1 0 0
1949011606 4 131 1351 996 35
1949011612 4 132 1353 996 35
1949011618 4 132 1356 996 35
66666 0 37 27 0 0
66666 0 39 28 0 0
66666 0 42 29 0 0
66666 0 38 30 0 0
1953010100 6 134 1384 955 60
1953010106 6 140 1374 955 60
如您所见,以66666开头的有多行,我只需要输出一行,我自己编的程序虽然能实现只有一行66666,但却删除了非66666的第一行数据,我的程序如下:
integer intensity,lat,lon,pres,wnd,line
character yi*11,top*6
open(1,file='f:\data\typhoon\janold.txt')
open(2,file='f:\data\typhoon\JAN.txt')
read(1,10)yi,intensity,lat,lon,pres,wnd
write(2,*)yi,intensity,lat,lon,pres,wnd
do while(.not.eof(1))
read(1,10,end=100)yi,intensity,lat,lon,pres,wnd
10 format(a12,i12,i12,i12,i12,i12)
top=yi(7:11)
if(top.eq.'66666')then
read(1,*)
else
read(1,10)yi,intensity,lat,lon,pres,wnd
write(2,*)yi,intensity,lat,lon,pres,wnd
endif
100 continue
backspace(1)
enddo
close(1)
close(2)
end
我的输出结果如下:
66666 0 49 1 0 0
1949011612 4 132 1353 996 35
1949011618 4 132 1356 996 35
66666 0 50 2 0 0
1953010106 6 140 1374 955 60
要怎么做才能既删除多余的66666行有不会把需要的数据删掉呢?还请各位大侠不吝赐教!
66666 0 49 1 0 0
1949011606 4 131 1351 996 35
1949011612 4 132 1353 996 35
1949011618 4 132 1356 996 35
66666 0 37 27 0 0
66666 0 39 28 0 0
66666 0 42 29 0 0
66666 0 38 30 0 0
1953010100 6 134 1384 955 60
1953010106 6 140 1374 955 60
如您所见,以66666开头的有多行,我只需要输出一行,我自己编的程序虽然能实现只有一行66666,但却删除了非66666的第一行数据,我的程序如下:
integer intensity,lat,lon,pres,wnd,line
character yi*11,top*6
open(1,file='f:\data\typhoon\janold.txt')
open(2,file='f:\data\typhoon\JAN.txt')
read(1,10)yi,intensity,lat,lon,pres,wnd
write(2,*)yi,intensity,lat,lon,pres,wnd
do while(.not.eof(1))
read(1,10,end=100)yi,intensity,lat,lon,pres,wnd
10 format(a12,i12,i12,i12,i12,i12)
top=yi(7:11)
if(top.eq.'66666')then
read(1,*)
else
read(1,10)yi,intensity,lat,lon,pres,wnd
write(2,*)yi,intensity,lat,lon,pres,wnd
endif
100 continue
backspace(1)
enddo
close(1)
close(2)
end
我的输出结果如下:
66666 0 49 1 0 0
1949011612 4 132 1353 996 35
1949011618 4 132 1356 996 35
66666 0 50 2 0 0
1953010106 6 140 1374 955 60
要怎么做才能既删除多余的66666行有不会把需要的数据删掉呢?还请各位大侠不吝赐教!