- 积分
- 428
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-10-28
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
求助各位大侠啊啊!!!
最近写一个程序,想让它输出像150.0,150.1,150.2。。。。这样的数据,就进行了一个循环累加。
但是结果出来是150.0000,150.1000,150.2000,150.2001。。。类似这样的结果,而且越往后加,误差越大,而且有的时候还会有158.9999这样的结果。我改成双精度的实数也没有用,
真是不知道怎么解决了,请教各位有没有碰到过类似的情况?紧急啊
谢谢各位了
源代码如下,加红色的部分就是累加出错的地方:
program read_f
implicit none
integer::i,j,k,t,h,c
real :: x0,y0
real::lat,lon,e
real*8,det
integer,parameter::n=1423033
integer,parameter::ix=1001,jx=601
real :: alat(n),alon(n),emission_d(n)
real :: x(n),y(n),emis(n) !select the domain
det = 0.100000d0
i=1
k=1
x0=0.0
y0=60.0
open(10,file='edgar_HTAP_BC_emi_AIR_2008.txt')
do t=1,n
read(10,*)alat(t),alon(t),emission_d(t)
if(alat(t).ge.0.0.and.alat(t).le.60.0.and.alon(t).ge.60.0.and.& !select
alon(t).le.160.0) then
x(i)=alat(t)
y(i)=alon(t)
emis(i)=emission_d(t)
i=i+1
end if
end do
print*,'x(i-1)=',x(i-1),'y(i-1)=',y(i-1)
print*,'x(i)=',x(i),'y(i)=',y(i)
h=i-1 !h=hangshu
print*,'h=',h
close(10)
open(12,file='test.txt')
do i=1,h
write(12,*)x(i),y(i),emis(i)
end do
print*,'raw files are written!'
open(11,file='2008_air_bc.txt')
close(12)
e=0.0
write(11,*)x0,y0,e
do i=1,h
if(abs(x(i)-x0)<=1.0e-6) then
print*,'x(i)=',x(i),'y(i)=',y(i)
if(abs(y(i)-y0-0.1)>1.0e-6)then!
do j=0,(y(i)-y0)/det-2
lat=x0
lon=y0+det
e=0.0
x0=lat
y0=lon
print*,'lat=',lat,'lon=',lon ,'det=',det,'y0=',y0
write(11,*)lat,lon,e
end do
end if
lat=x(i)
lon=y(i)
e=emis(i)
write(11,*)lat,lon,e
else if(abs(x(i)-x0-det)<1.0e-6)then
print*,'x(i)=',x(i)
if(abs(y(i)-60.0)<1.0e-6.and.abs(y0-160.0)<1.0e-6)then
lat=x(i)
lon=y(i)
e=emis(i)
x0=lat
y0=lon
write(11,*)lat,lon,e
else if((.not.(abs(y(i)-60.0)<1.0e-6)).and.abs(y0-160.0)<1.0e-6)then
x0=x(i)
y0=60.0
e=0.0
write(11,*)x0,y0,e
do j=0,(y(i)-y0)/0.1-1
lat=x0
lon=y0+det
e=0.0
x0=lat
y0=lon
write(11,*)lat,lon,e
end do
lat=x(i)
lon=y(i)
e=emis(i)
write(11,*)lat,lon,e
else if(abs(y(i)-60.0)<1.0e-6.and.(.not.abs(y0-160.0)<1.0e-6))then
do j=0,(160.0-y0)/0.1-1
lat =x0
lon =y0+det
e=0.0
x0=lat
y0=lon
write(11,*)lat,lon,e
end do
lat=x(i)
lon=y(i)
e=emis(i)
write(11,*)lat,lon,e
else if((.not.abs(y(i)-60.0)<1.0e-6).and.(.not.abs(y0-160.0)<1.0e-6))then
do j=0,(160.0-y0)/0.1-1
lat =x0
lon =y0+det
e=0.0
x0=lat
y0=lon
write(11,*)lat,lon,e
end do
x0=x(i)
y0=60.0
e=0.0
write(11,*)x0,y0,e
do j=0,(y(i)-y0)/0.1-1
lat=x0
lon=y0+det
e=0.0
x0=lat
y0=lon
write(11,*)lat,lon,e
end do
lat=x(i)
lon=y(i)
e=emis(i)
write(11,*)lat,lon,e
end if
end if
if(abs(i-h)<1.0e-6.and.abs(y(i)-160.0)>1.0e-6) then
do j=0,(160.0-y(i))/0.1-1
lat=x0
lon=y0+det
e=0.0
x0=lat
y0=lon
write(11,*)lat,lon,e
end do
end if
end do
close(11)
end
|
|