[Fortran] 纯文本查看 复制代码
program barnes
implicit none
external sub1,sub2
integer,parameter::xx=4,yy=4
real Fa(xx,yy),Fb(xx,yy),Fd(xx,yy),Fk(xx,yy),F0(xx,yy),F(xx,yy)
real G1,G2
integer c1,c2,i,j
write(*,*)'please write G1,c1'
read *,G1,c1
open(3,file='d:/barns/beijing.grd',form='binary')
read(3) ((Fk(i,j),j=1,yy),i=1,xx)
call sub1(Fk,c1)
call sub2(F0,G1,Fk,c1)
Fa=F
write(*,*)'please write G2,c2'
read*,G2,c2
call sub1(Fk,c2)
call sub2(F0,G1,Fk,c2)
Fb=F
do i=1,xx
do j=1,yy
Fd(i,j)=Fa(i,j)-Fb(i,j)
write(*,*)Fd
enddo
enddo
write(*,*)
OPEN(11,FILE='d:/barns/out2.grd',form='binary')
write(11) ((Fd(i,j),j=1,yy),i=1,yy)
close(11)
close(8)
end
subroutine sub1(Ff,c)!计算初始值
implicit none
integer i,j,m,n,c,xx,yy
real F0(xx,yy),Ff(xx,yy),F2,F3,F4,Wk,Rk
common xx,yy
do i=1,xx
do j=1,yy
do m=1,xx
do n=1,yy
Rk=sqrt((i-m)**2.0+(j-n)**2.0)
Wk=exp(-(Rk**2.0)/(4.0*c))!权重函数计算
F2=Wk*Ff(m,n) !分子计算
F3=F2+F3
F4=F4+Wk
enddo
enddo
F0(i,j)=F3/F4
enddo
enddo
endsubroutine
subroutine sub2(F0,G,Ff,c)!计算F值
implicit none
integer i,j,m,n,c,xx,yy
real F0(4,4),Ff(4,4),F(4,4),Fs(4,4),D,F2,F3,F4,Rk,Wk,G
common xx,yy
do i=1,xx
do j=1,yy
do m=1,xx
do n=1,yy
D=Ff(m,n)-F0(m,n)
Rk=sqrt((i-m)**2.0+(j-n)**2.0)
Wk=exp(-(Rk**2.0)/(4.0*c*G))!权重函数计算
F2=Wk*D !分子计算
F3=F2+F3
F4=F4+Wk
enddo
enddo
Fs(i,j)=F3/F4
F(i,j)=Fs(i,j)+F(i,j)
enddo
enddo
endsubroutine