[Fortran] 纯文本查看 复制代码
program test
implicit none
integer,parameter::nCol = 36
integer i, j
character(80) str(nCol)
character(32),parameter:: strHead(1)=['Province']
!strHead(23)=['Province','City','Stationname','Longitude','Latitude','Publishtime', 'AQI','SO2','NO2','CO','O3','PM10', &
!'PM2_5','SO2_24H_AVG','NO2_24H_AVG','CO_24H_AVG','O3_24H_AVG','PM10_24H_AVG','PM2_5_24H_AVG','O3_8H','O3_8H_24H','PrimaryPollutant','Quality']
logical L(nCol)
open(11,file='F:\GraduateStudent\Data-Data\sichuanpollution.csv')
open(10,file='F:\GraduateStudent\Data-Data\sichuanpollution1.csv')
!读取表头
read(10,*) str
!判断需要读取的列
L = .false.
do i = 1, nCol
str(i) = adjustl( str(i) )
if( any(trim(str(i))==strHead) ) then
L(i) = .true.
write(11,"(a,',')",advance='no') trim( str(i) ) !输出新表头
end if
end do
write(11,*)
do
read(10,*,iostat=j) str
if(j/=0) exit
do i =1, nCol
if(.NOT.L(i)) cycle
write(11,'(a,",")',advance='no') trim( str(i) )
end do
write(11,*)
end do
end program test