24小时热门版块排行榜    

Znn3bq.jpeg
查看: 589  |  回复: 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 Peterchao 2026-05-18 8/400 2026-05-24 11:58 by 晓晓爱翠翠
[基金申请] 西安交大新媒学院副院长用撤稿论文结题 +3 bjvtcliu 2026-05-24 5/250 2026-05-24 10:16 by kudofaye
[教师之家] 论文撤稿了 +3 bjvtcliu 2026-05-24 5/250 2026-05-24 10:06 by Equinoxhua
[教师之家] 某211大学教师把个人教师官方主页改成:我跑了我跑了我跑了!官宣跑路! +4 zju2000 2026-05-21 5/250 2026-05-24 09:35 by songwz
[考博] 26/27申博自荐 10+4 ZXW0202 2026-05-22 9/450 2026-05-24 08:47 by bjvtcliu
[硕博家园] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +3 hvkbtfonbv 2026-05-23 3/150 2026-05-24 08:01 by 9ps9vgkqva
[硕博家园] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +3 pmo95bazuy 2026-05-23 7/350 2026-05-24 06:35 by fpo5ljpv91
[基金申请] 揭秘青基评审内幕:几个A才能顺利中标 +3 国自然国社科中 2026-05-23 4/200 2026-05-23 15:37 by 2000zf36392
[基金申请] 青B发送上会通知了吗 +5 chemBioBro 2026-05-22 7/350 2026-05-23 12:35 by zhuifengzhy
[考博] 博士申请 +3 焦晓明 2026-05-21 3/150 2026-05-23 11:26 by mlc840311
[论文投稿] 投稿求助,期刊 +4 希冀,有书读 2026-05-20 8/400 2026-05-22 10:16 by 希冀,有书读
[文学芳草园] 献血感触 +7 呀呀好傻 2026-05-19 13/650 2026-05-21 20:15 by 呀呀好傻
[基金申请] 面上本子正文33页,违规吗?会被低分嘛? +14 1234567wang 2026-05-17 16/800 2026-05-21 17:58 by 脆脆的饼干
[基金申请] 国自然评分 +4 无名者登山 2026-05-20 5/250 2026-05-21 16:35 by swuq
[基金申请] 国自然上会要求 +7 无名者登山 2026-05-18 11/550 2026-05-21 15:50 by draco1987
[基金申请] 提交了我也来说说感想 +9 fummck 2026-05-20 10/500 2026-05-21 14:17 by draco1987
[基金申请] 评审有感 +15 popular289 2026-05-18 26/1300 2026-05-21 10:35 by 西葫芦炒鸡蛋
[考博] 如果工作了想读博,可以边工作边读全日制嘛? 30+3 铁达火车 2026-05-18 5/250 2026-05-20 09:33 by tfang
[考博] 博士申请 +5 星…… 2026-05-18 6/300 2026-05-18 23:49 by 糊糊涂涂好
[硕博家园] 我在等一个没有答案的答案 +3 Love_MH 2026-05-17 3/150 2026-05-18 02:22 by 竹林孤影
信息提示
请填处理意见