我现在正在为某个迭代运行一个程序。时间步长为0.01。我想在达到特定时间时写入一些信息。例如:增加双精度值
program abc
implicit none
double precision :: time,step,target
integer :: x
time = 0.d0
step = 0.01
target = 5.d0
do x = 1,6000
time = time + step
"some equations here to calculate the model parameters"
if(time.eq.target)then
write(*,*) "model parameters"
endif
enddo
然而,“时间”永不等于1.0或2.0或等它显示了如“0.999999866”而不是“1.0”和“1.99999845”,而不是“2.0”。
尽管我可以使用整数“x”来定义何时写信息,但我更喜欢使用时间步长。此外,我可能想要更改时间步长(0.01/0.02/0.05/etc)或目标(5.0/6.0/8.0/etc)。
有谁知道如何解决这个问题?谢谢你。
'如果(x.eq.nint(目标/步骤))' – agentp