24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 481  |  回复: 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的回帖
★ ★ ★
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的回帖
查看全部 3 个回答

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的回帖
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 求调剂 +6 akdhjs 2026-03-31 7/350 2026-03-31 14:39 by yaochuang
[考研] 286求调剂 +6 Faune 2026-03-30 6/300 2026-03-31 14:37 by jp9609
[考研] 0710生物学求调剂! +4 叙述文 2026-03-31 4/200 2026-03-31 14:32 by 记事本2026
[考研] 一志愿085600中科院宁波所276分求调剂 +12 材料学257求调剂 2026-03-28 13/650 2026-03-31 14:30 by 六翼TMR
[考研] 调剂申请 +6 张张张张zy 2026-03-31 6/300 2026-03-31 14:20 by 记事本2026
[考研] 317求调剂 +11 蛋黄咸肉粽 2026-03-26 12/600 2026-03-31 13:30 by 记事本2026
[考研] 调剂求院校招收 +7 鹤鲸鸽 2026-03-28 7/350 2026-03-31 11:21 by oooqiao
[考研] 一志愿北京化工大学材料与化工(085600)296求调剂 +25 稻妻小编 2026-03-26 25/1250 2026-03-30 20:11 by 滴滴上岸呀
[考研] 375求调剂 +6 雨夏整夜 2026-03-29 6/300 2026-03-30 10:21 by herarysara
[考研] 材料与化工304求B区调剂 +4 邱gl 2026-03-26 7/350 2026-03-30 08:39 by 探123
[考研] 一志愿北京工业大学,324分求调剂 +6 零八# 2026-03-28 6/300 2026-03-29 21:20 by nanaliuyun
[考研] 311求调剂 +6 冬十三 2026-03-24 6/300 2026-03-29 20:45 by 无际的草原
[考研] 298求调剂 +3 种圣赐 2026-03-29 3/150 2026-03-29 12:06 by longlotian
[考研] 352分-085602-一志愿985 +5 海纳百川Ly 2026-03-29 5/250 2026-03-29 09:57 by Sjndkwm
[硕博家园] 招收生物学/细胞生物学调剂 +4 IceGuo 2026-03-26 5/250 2026-03-29 01:25 by griffith2014
[考研] 一志愿华理,数一英一285求A区调剂 +8 AZMK 2026-03-25 12/600 2026-03-28 18:15 by AZMK
[考研] 295求调剂 +5 1428151015 2026-03-27 6/300 2026-03-28 04:04 by fmesaito
[考研] 324求调剂 +5 hanamiko 2026-03-26 5/250 2026-03-27 10:33 by wangjy2002
[考研] 081200-11408-276学硕求调剂 +4 崔wj 2026-03-26 4/200 2026-03-27 08:04 by chemisry
[考研] 环境专硕324分求调剂推荐 +5 轩小宁—— 2026-03-26 5/250 2026-03-26 12:05 by i_cooler
信息提示
请填处理意见