24小时热门版块排行榜    

查看: 645  |  回复: 5

astringent

铜虫 (著名写手)


[交流] 【求助】子程序传值出错

我在主程序中调用了一个子程序test,然后再子程序中又调用了一个子程序test1.在子程序中的write语句都能得到ihbnum=1,可是主程序write语句的ihbnum去等于0,请大家帮忙看看,先谢了
program main
--
call test(a1,a2,----ihbnum1)
write (*,*) ihbnum1
enddo
子程序为:
subroutine test &
          (io,ih,ia,xxx,yyy,zzz,nattot,cell,atomname,resname,ihbnum)

      implicit none
      include 'constants.h'

      integer io,ih,ia,nattot,ihbnum
      double precision xxx(nattot),yyy(nattot),zzz(nattot)
      double precision cell(*)
      character*4 atomname(nattot)
      character*3 resname(nattot)

      integer iat

      ia = 0

      do iat=1, nattot
             if((resname(iat).eq.'DC5'.or.resname(iat).eq.'DC ').and.&
               (atomname(iat).eq.' N1 '.or.atomname(iat).eq.' N4 '.or.&
               atomname(iat).eq.' N3 '.or.atomname(iat).eq.' O2 ')then
               call test1 &
                   (io,ih,iat,xxx,yyy,zzz,nattot,cell,ihbnum)
               if(ihbnum.eq.1)  then
               ia=iat
               write(21,*) 'test',ihbnum,ia
             endif
      enddo
      
      return
      end

subroutine test1 &
          (io,ih,iat,xxx,yyy,zzz,nattot,cell,ihbnum)
-------
            ihbnum=0

      call bondcalculation(io,ih,xxx,yyy,zzz,nattot,cell,dx0,dy0,dz0,r0)
      call bondcalculation(io,iat,xxx,yyy,zzz,nattot,cell,dx1,dy1,dz1,r1)
           if (r1.lt.roamax) then
              theta = dacos(dx0*dx1+dy0*dy1+dz0*dz1)
                  if(theta.lt.thetamax*pi/180.0) then
                      call bondcalculation &
                         (ih,iat,xxx,yyy,zzz,nattot,cell,dx2,dy2,dz2,r2)
                        if (r2.lt.rhamax) then
                              ihbnum = 1
                        write(21,*) 'find',ihbnum,iat
                        endif
                   endif
           endif
                 
      return
      end
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

ykwang

金虫 (正式写手)



astringent(金币+1):谢谢参与
astringent(金币+5): 2010-11-23 06:21:13
astringent(金币+5): 2010-11-29 15:55:59
主程序write语句的ihbnum等于0是因为子程序test在最后一步循环中调用test1时ihbnum的返回值为0。如果在子程序test中
   write(21,*) 'test',ihbnum,ia
加上下列条件返回语句
   IF(ihbnum.eq.1)THEN
        RETURN
    ENDIF
则主程序中write语句的ihbnum就会等于1。
2楼2010-11-23 06:06:52
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

astringent

铜虫 (著名写手)


再问一下,对于子程序,这两个write语句输出的ihbnum的值是不是write(20)ihbnum=1,而write(21)的ihbnum=0?
subroutine test1 &
          (io,ih,iat,xxx,yyy,zzz,nattot,cell,ihbnum)
-------
            ihbnum=0

      call bondcalculation(io,ih,xxx,yyy,zzz,nattot,cell,dx0,dy0,dz0,r0)
      call bondcalculation(io,iat,xxx,yyy,zzz,nattot,cell,dx1,dy1,dz1,r1)
           if (r1.lt.roamax) then
              theta = dacos(dx0*dx1+dy0*dy1+dz0*dz1)
                  if(theta.lt.thetamax*pi/180.0) then
                      call bondcalculation &
                         (ih,iat,xxx,yyy,zzz,nattot,cell,dx2,dy2,dz2,r2)
                        if (r2.lt.rhamax) then
                              ihbnum = 1
                        write(20,*) 'find',ihbnum
                        endif
                   endif
           endif
          write(21,*) 'find',ihbnum     
      return
      end
3楼2010-11-23 06:32:40
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

ykwang

金虫 (正式写手)


从这段程序看,write(20,###)中写入的一定是ihbnum=1,但write(21,###)中写入的ihbnum除了ihbnum=0外还有ihbnum=1。
4楼2010-11-23 06:42:52
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

astringent

铜虫 (著名写手)


引用回帖:
Originally posted by ykwang at 2010-11-23 06:06:52:
主程序write语句的ihbnum等于0是因为子程序test在最后一步循环中调用test1时ihbnum的返回值为0。如果在子程序test中
   write(21,*) 'test',ihbnum,ia
...

i have tried use the return, but it does not work, how can i solve this?
6楼2010-11-23 19:20:11
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
简单回复
2010-11-23 08:02   回复  
astringent(金币+1):谢谢参与
nono2009:专业区请勿灌水。谢谢! 2010-11-25 07:35:16
astringent(金币+3): 2010-11-29 15:56:24
祝福祝福
相关版块跳转 我要订阅楼主 astringent 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[文学芳草园] 梦想 +5 myrtle 2026-08-26 8/400 2026-09-02 02:42 by Leogzhya
[基金申请] 面上合作单位盖章 +6 ssyjh 2026-08-27 9/450 2026-09-01 20:01 by huagongfeihu
[基金申请] 学科评审组评审是指会评吗? +4 瞬息宇宙 2026-08-31 4/200 2026-09-01 14:58 by jiaoxg
[论文投稿] 小白求助 投论文要求的highlights应该如何写 5+3 l1963982152 2026-08-29 4/200 2026-09-01 09:04 by 北京莱茵编辑
[基金申请] 麻烦专家们看看评委们的意见(F口面上) +7 gdd2018 2026-08-28 12/600 2026-09-01 08:32 by 尼古拉斯小虫
[基金申请] 国社科又开始会评了,不知道这次命运如何 +7 雨打竹帘 2026-08-30 11/550 2026-08-31 23:16 by hittle2008
[基金申请] 能否申诉? +7 echo8914667 2026-08-30 8/400 2026-08-31 17:00 by yihongxu
[基金申请] 中青基了要发朋友圈吗? +7 349506619 2026-08-28 7/350 2026-08-31 13:39 by 冼亮淀粉酶
[基金申请] 为什么到现在没收到通知? +5 tannykie 2026-08-29 5/250 2026-08-30 21:05 by purplejack
[考博] 找导师 +6 yuanjiabao 2026-08-29 7/350 2026-08-30 14:40 by 生科新手
[基金申请] 我就是申请一个面上项目而已,这评审意见是按照杰青的条件评的吧? +6 gouxfjh 2026-08-28 11/550 2026-08-30 07:57 by gouxfjh
[基金申请] 国自然面上复盘~欢迎讨论 (金币+15) +15 晴天加油 2026-08-26 16/800 2026-08-29 18:28 by symmetry
[基金申请] 怎么查啊 +6 huang1991js 2026-08-26 6/300 2026-08-28 08:42 by winsaint
[基金申请] 看板上这么多中的,有点像50人群里49个人都是骗子的那种感觉…… +5 a089 2026-08-26 6/300 2026-08-27 14:05 by jonewore
[基金申请] 为什么 国际(地区)合作与交流项目 没有放榜? 10+3 majunge000 2026-08-26 11/550 2026-08-27 08:42 by 北京莱茵编辑
[基金申请] 我不理解! +15 Edward_pc 2026-08-26 23/1150 2026-08-26 20:34 by zzuzxg
[基金申请] 国际合作可查了,中了面上 (EPI+1)(金币+50) +18 Ldrop2023 2026-08-26 18/900 2026-08-26 11:15 by cmrandy
[基金申请] 系统进不去 +4 yanglien 2026-08-26 5/250 2026-08-26 11:10 by wenfengw83
[基金申请] 国合可查了 +3 paperzjh 2026-08-26 3/150 2026-08-26 10:41 by LemmonTr
[基金申请] 牛来!米来!面来! +8 beefly 2026-08-26 8/400 2026-08-26 08:37 by xuzhipiao
信息提示
请填处理意见