24小时热门版块排行榜    

查看: 700  |  回复: 2

astringent

铜虫 (著名写手)


[交流] 【求助】为什么两种写法得到的值不一样?

为什么把if语句放到不同的位置,结果就不一样了呢?请大家帮忙分析一下,多谢。
写法一(判断语句为h0(t)/=0):
t0=0
             do ntel=1, npoints
         
               neworig = .false.
               if (t0.eq.0) then
                   neworig = .true.
               elseif (ntel-time0(t0).eq.it0)then
                   neworig = .true.
               endif

               if (neworig) then
                  t0 = t0 + 1         ! update number of t=0
                  time0(t0) = ntel    ! store the time of t=0
                  h0(t0) = h(ntel)
                endif
         
                do t=1, t0             ! update tcf for t=0
                   delt=ntel-time0(t)+1 ! actual time minus t=0
                   if(h0(t)/=0.and.(delt.lt.npoints)) then
                      ntime(delt) = ntime(delt)+1d0
                      tcf(delt)=tcf(delt)+h(ntel)*h0(t)
                      tcf0(delt)=tcf0(delt)+h0(t)*h0(t)
                    endif
                 enddo               
              enddo
写法二(判断语句为if (h(ntel)/=0) then)
t0=0
             do ntel=1, npoints
         
               neworig = .false.
               if (h(ntel)/=0) then
               if (t0.eq.0) then
                   neworig = .true.
               elseif (ntel-time0(t0).eq.it0)then
                   neworig = .true.
               endif
              endif

               if (neworig) then
                  t0 = t0 + 1         ! update number of t=0
                  time0(t0) = ntel    ! store the time of t=0
                  h0(t0) = h(ntel)
                endif
         
                do t=1, t0             ! update tcf for t=0
                   delt=ntel-time0(t)+1 ! actual time minus t=0
                   if(delt.lt.npoints) then
                      ntime(delt) = ntime(delt)+1d0
                      tcf(delt)=tcf(delt)+h(ntel)*h0(t)
                      tcf0(delt)=tcf0(delt)+h0(t)*h0(t)
                    endif
                 enddo               
              enddo
回复此楼

» 猜你喜欢

» 抢金币啦!回帖就可以得到:

查看全部散金贴

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zhuwei04

木虫 (正式写手)


astringent(金币+10): 2011-02-13 20:36:36
h(1) 能保证/=0吗?
如果和h(1)=0,写法一比较好吧,至少能保证do t=1, t0 这句不出错
2楼2011-02-13 10:18:59
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
★ ★ ★
astringent(金币+10): 2011-02-13 20:36:39
余泽成(金币+3): 谢谢参与应助! 2011-02-20 18:22:58
你这个程序片断有太多的东西没有交待,所以不能从程序片断上来解读

在下面的这段代码中,你加了一个判断才能进行 neworig 的赋值,但在方法一中,没有这样的判断,因此,可能会导致 neworig 的值在两个程序中不一样,那么可能会直接影响最后的结果……
CODE:
             if (h(ntel)/=0) then
               if (t0.eq.0) then
                   neworig = .true.
               elseif (ntel-time0(t0).eq.it0)then
                   neworig = .true.
               endif
              endif

3楼2011-02-13 10:24:20
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 astringent 的主题更新
普通表情 龙 兔 虎 猫 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 售SCI文章,我:8O.5.5.1O.54,科目全,可十急 +6 5sJFDKp2kwuI 2026-11-06 14/700 2026-11-09 11:52 by GwrQVVR6Oenx
[硕博家园] 售SCI一区T0P文章,我:8O.55.1.O.54,科目全,可伽急 +5 5sJFDKp2kwuI 2026-11-06 16/800 2026-11-09 11:47 by GwrQVVR6Oenx
[考研] 售SCI一区T0P文章,我:8O.55.1.O.5.4,科目齐全,可+急 +8 ncTVBM6AOJHF 2026-11-04 15/750 2026-11-09 10:23 by Equinoxhua
[考研] 售SCI一区T0P文章,我:8O.55.1.O.54,科目全,可伽急 +3 5sJFDKp2kwuI 2026-11-06 12/600 2026-11-09 06:32 by l48hFd8Nwae2
[硕博家园] 售SCI一区T0P文章,我:8.O55.1.O.54,科目全,可十急 +5 2rKfVQg2jQww 2026-11-06 11/550 2026-11-09 00:26 by l48hFd8Nwae2
[公派出国] 售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急 +4 5sJFDKp2kwuI 2026-11-06 8/400 2026-11-09 00:14 by l48hFd8Nwae2
[教师之家] 售SCI一区T0P文章,我:8.O.55.1.O.5.4,科目全,可+急 +5 5sJFDKp2kwuI 2026-11-06 9/450 2026-11-08 22:46 by l48hFd8Nwae2
[考博] 售SCI一区文章,我:8O5.5.1.O5.4,科目全,可伽急 +6 ELBZ6WwEaRj6 2026-11-05 8/400 2026-11-06 16:34 by 5sJFDKp2kwuI
[考博] 售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急 +6 ELBZ6WwEaRj6 2026-11-04 14/700 2026-11-06 16:32 by 5sJFDKp2kwuI
[公派出国] 售SCI一区文章,我:8.O.551.O.5.4,科目全,可伽急 +6 ttH3f1oA6ace 2026-11-04 12/600 2026-11-06 16:10 by 5sJFDKp2kwuI
[硕博家园] 售SCI一区文章,我:8O5.5.1.O5.4,科目全,可伽急 +4 ttH3f1oA6ace 2026-11-04 11/550 2026-11-06 16:10 by 5sJFDKp2kwuI
[公派出国] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +8 ncTVBM6AOJHF 2026-11-04 12/600 2026-11-06 13:47 by BkA9Bi5cMhkD
[硕博家园] 售一区SCI文章T0P,我:8O.551.O54,科目全,可十急 +3 ELBZ6WwEaRj6 2026-11-05 5/250 2026-11-06 09:01 by 2lRNluKrJpwL
[硕博家园] 售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急 +3 ELBZ6WwEaRj6 2026-11-04 12/600 2026-11-06 05:32 by qL1cU46YIdK0
[考研] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +4 ttH3f1oA6ace 2026-11-04 14/700 2026-11-06 05:11 by qL1cU46YIdK0
[硕博家园] 售SCI一区文章,我:8O5.5.1.O5.4,科目全,可伽急 +4 ncTVBM6AOJHF 2026-11-04 12/600 2026-11-06 04:47 by qL1cU46YIdK0
[公派出国] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +3 ELBZ6WwEaRj6 2026-11-04 9/450 2026-11-06 02:15 by qL1cU46YIdK0
[考博] 售一区SCI文章T0P,我:8O.551.O54,科目全,可十急 +4 ttH3f1oA6ace 2026-11-04 7/350 2026-11-06 02:13 by qL1cU46YIdK0
[硕博家园] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +3 ttH3f1oA6ace 2026-11-04 9/450 2026-11-06 02:02 by qL1cU46YIdK0
[教师之家] 售SCI一区T0P文章,我:8O.55.1.O.54,科目全,可伽急 +4 ncTVBM6AOJHF 2026-11-04 12/600 2026-11-05 11:10 by PYZmcHr5kSaq
信息提示
请填处理意见