代码如下:
program wwlln_shiyan
implicit none
!声明变量
character(len=512)::cRead
character(len=20)::filename,DYfilename
character(len=20)::wwlln_date,wwlln_time
real::lat,lon
real::timingerror
integer::station
integer::status1=0
integer,parameter::fileid1=12,fileid2=13
integer::i
logical alive
!循环读取文件
OPEN(14,file="filename.txt",status="old")
OPEN(15,file="DYfilename.txt",status="old")
do i=20040810,20151130,1
READ(14,*)filename
READ(15,*)DYfilename
inquire(file=filename,exist=alive)
if (alive) then
!读取数据
OPEN(11,file=filename,status='old',form='formatted')
OPEN(13,file=DYfilename,status='replace')
do while(.true.)
READ(11,"(A512)",iostat=status1)cRead
if (status1/=0) exit
CALL parserRead(cRead)
if((lat>21).AND.(lat<34).AND.(lon>97).AND.(lon<111)) then
write(*,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
write(13,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
end if
end do
CLOSE(11)
CLOSE(13)
else
CYCLE
end if
end do
CLOSE(11)
CLOSE(13)
STOP
contains
!调用子程序
subroutine parserRead(c)
character(len=*)::c
integer::j
do j=1,LEN_TRIM(c)
if (c(j:j)=="/") c(j:j)="|"
end do
READ(c,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
do j=1,LEN_TRIM(wwlln_date)
if (wwlln_date(j:j)=="|") wwlln_date(j:j)="/"
end do
end subroutine parserRead
end program wwlln_shiyan
!生成filename.txt
program wwlln_filename
implicit none
!声明变量
integer::i
OPEN(11,file='filename.txt',status='replace')
do i=20040810,20151130,1
write(11,"(1x,A1,I8,A4)")"A",i,".txt"
end do
end program wwlln_filename
!生成DYfilename.txt(即经过经纬度拆选后的数据存放txt)
program wwlln_DYfilename
implicit none
!声明变量
integer::i
OPEN(11,file='DYfilename.txt',status='replace')
do i=20040810,20151130,1
write(11,"(1x,I8,A4)")i,".txt"
end do
end program wwlln_DYfilename
最后:计算机配置不够,在运行过大的数据会出现end of file 的报错。