[Fortran] 纯文本查看 复制代码
program flash_density_test
implicit none
!声明变量
character(len=512)::cRead,dRead
character(len=10)::datee
character(len=15)::time
real::lat,lon
character(len=4)::timingerror
integer::station
integer::status1=0,status2=0
integer::i,j
integer,parameter::nx=150,ny=140
real,dimension(nx,ny)::md
character(len=10)::year,month,day,hour,minn,sec,ti,station1,ex1,ex2,ex3
real::lat1,lon1
do i=1,nx
do j=1,ny
md(i,j)=0.0
end do
end do
!读取文件
open(11,file='2006.txt',status='old')
OPEN(12,file='output1.txt',status='replace')
OPEN(13,file='xinan.grd',form='unformatted',status='replace')
OPEN(14,file='20170210_27.txt',status='old')
do while(.true.)
read(11,"(A512)",iostat=status1)cRead
if(status1/=0) exit
CALL parserRead(cRead)
!write(*,*)lat,lon
lon=lon-97
lat=lat-21
READ(14,"(A512)",iostat=status2)dRead
if(status2/=0) exit
CALL parserRead1(dRead)
!write(*,*)lat1,lon1
lon1=lon1-97
lat1=lat1-21
do i=1,nx
do j=1,ny
if(lon>=(i-1)*0.1.and.lon<i*0.1.AND.lat>=(j-1)*0.1.AND.lat<j*0.1) then
md(i,j)=md(i,j)+1.0
end if
if(lon1>=(i-1)*0.1.and.lon1<i*0.1.AND.lat1>=(j-1)*0.1.AND.lat1<j*0.1) then
md(i,j)=md(i,j)+1.0
end if
end do
end do
end do
close(11)
write(12,'(1x,150f7.1)')((md(i,j),i=1,nx),j=1,ny)
CLOSE(12)
write(13)((md(i,j),i=1,nx),j=1,ny)
CLOSE(13)
CLOSE(14)
contains
!调用子程序1
subroutine parserRead(c)
character(len=*)::c
integer::k
do k=1,LEN_TRIM(c)
if (c(k:k)=="/") c(k:k)="|"
end do
READ(c,*)datee,time,lat,lon,timingerror,station
do k=1,LEN_TRIM(datee)
if (datee(k:k)=="|") datee(k:k)="/"
end do
end subroutine parserRead
!调用子程序2
subroutine parserRead1(d)
character(len=*)::d
integer::h
do h=1,LEN_TRIM(d)
if(d(h:h)=="/") d(h:h)="|"
end do
READ(d,*)year,month,day,hour,minn,sec,lat1,lon1,ti,station1,ex1,ex2,ex3
do h=1,LEN_TRIM(year)
if(year(h:h)=="|") year(h:h)="/"
end do
end subroutine parserRead1
end program