我正在运行一个Fortran代码,该代码应该在左列中写为1到2000000,在右列中写为1-0.001,范围如下:
program signal
implicit none
integer dt_start, dtq, dtb, dtt, mdotb, i, mdot, t_start, n, dt, t
real*8 mdotq, mdott, nmdott
mdotb = 1 !burst phase
mdotq = 0.001 !quiescent phase
dtb = 100 !time for burst phase
dtq = 1080 !time for quiescent phase
dtt = 200 !transition time
t = 0 !initial time
dt = 10 !time step
n = 2000000 !interval
t_start = 0 !start of the range
open(unit=1, file='accretion.txt', status='unknown')
do i = 1, n
t = t + dt
dt_start = t-t_start
mdott = ((0.999/200)*t) + 0.505
nmdott = ((-0.999/200)*t) + 0.505
if (dt_start .le. dtb) then
if (dt_start .eq. dtb) then
t_start = i*dtb
endif
write(1,*) t, mdotb
else if (dt_start .le. dtt) then
if (dt_start .eq. dtt) then
t_start = i*dtt
endif
write(1,*) t, nmdott
else if (dt_start .le. dtq) then
if (dt_start .eq. dtq) then
t_start = i*dtq
endif
write(1,*) t, mdotq
else if (dt_start .le. dtt) then
if (dt_start .eq. dtt) then
t_start = i*dtt
endif
write(1,*) t, mdott
endif
enddo
close(1)
end
这将输出以下结果:
10 1
20 1
30 1
40 1
50 1
60 1
70 1
80 1
90 1
100 1
110 1
120 1
130 1
140 1
150 1
160 1
170 1
180 1
190 1
200 1
210 1
220 1
230 1
240 1
250 1
260 1
270 1
280 1
290 1
300 1
并一直持续到2000000。我不明白我对代码的错误处理,我认为我可能需要在某些时候重新启动?
答案 0 :(得分:0)
从这个角度看待您:
integer t = 0
integer t_start = 0
integer dt = 10
integer dtb = 100
integer n = 2000000
integer mdotb = 1
! (...)
do i = 1, n
t = t + dt
dt_start = t-t_start ! <- (*)
! (...)
if (dt_start .le. dtb) then ! <- condition (A)
if (dt_start .eq. dtb) then ! <- condition (A.1)
t_start = I*dtb. ! <- (**)
endif
write(1,*) t, mdotb ! <- output for branch (A)
else if ! <- other conditions
! (...)
end if
end do
对于第一个迭代i = 1, 9
,您的条件(A)
为true并且(A.1)
为false,然后执行分支(A)
的输出,并且代码显示{{1 }}在第一列中,t = 10, 90
在第二列中。
对于迭代mdotb = 1
,您最终有了i = 10
,因此条件dt_start == dtb
为true,而(A)
也为true。从分支(A.1)
内部,在标记为(A.1)
的行中获得分配t_start = 1000
。然后,再次执行分支(**)
的输出,代码在第一列中打印(A)
,在第二列中打印t = 100
。
对于以下迭代mdotb = 1
,请记住i = 11, 109
,因此在标记为t_start == 1000
的行中,您将有(*)
,dt_start = -890
...直到dt_start = -880
为止,其中所有时间条件dt_start = 90
都为true,(A)
则为false,并且您一直一直打印(A.1)
和t
。
通过到达迭代mdotb
,最后再次达到i = 110
,然后条件dt_start = 100
和(A)
都成立,然后再次执行行(A.1)
,然后(**)
,然后再次执行分支t_start = 11000
的输出,再次打印(A)
和t
。
对于随后的迭代mdotb
,请重复以下循环,其中i = 111, 1109
的值为负/低,仍然使条件dt_start
始终为真,并始终输出相同的输出。
然后(A)
再次制作i = 1110
,然后现在dt_start = 100
,输出相同...
此模式一次又一次重复,而分支t_start = 111000
的输出始终执行,并且永远不会达到其余条件。
显然,程序的逻辑存在缺陷(嗯,从技术上讲,它的范围是0.001〜1,因为它始终是1 ...但是您似乎并不喜欢它)。但是我不知道您要设法在输出的第二列上进行打印。我可以确定的是,如果希望第一列中的数字是1到2000000,则应该打印(A)
而不是I
。
答案 1 :(得分:0)
或者操作者想要...
“ write(,)t,mdott”
或
“ Write(,)t,mdotb!但是首先设置mdotb使其不为1”
或
“ Write(,)I,t!?