24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 817  |  回复: 1

astringent

铜虫 (著名写手)

[交流] 【求助】为什么子程序的值不能返回主程序??? 已有1人参与

刚学编程,遇到一问题,子程序中的ihb值不能返回到主程序中。当我把write语句写在子程序test1中时,能输出ihb=1,但是我把write语句写在call test1 后面,输出的ihb却为0,请大家帮忙看看为什么会这样?多谢了。
subroutine test &
          (io,ih,ia,xxx,yyy,zzz,nattot,cell,atomname,resname,ihb)

implicit none
      include 'constants.h'

      integer io,ih,ia,nattot,ihb
      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,ihb)
               write(21,*) 'test',ihb
               if(ihb.eq.1) ia=iat
             endif
      enddo
return
end

subroutine test1 &
          (io,ih,iat,xxx,yyy,zzz,nattot,cell,ihb)

      implicit none
      include 'constants.h'

      integer io,ih,iat,nattot
      integer,intent(inout) ::ihb

      double precision xxx(nattot),yyy(nattot),zzz(nattot)
      double precision cell(3)
      double precision theta,thetamax,roamax,rhamax
      double precision dx0,dy0,dz0,r0
      double precision dx1,dy1,dz1,r1
      double precision dx2,dy2,dz2,r2

      thetamax = 30.d0
      roamax = 3.5d0
      rhamax = 2.45d0
      ihb=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
                              ihb = 1
                         write(21,*) ihb
                        endif
                   endif
           endif
                 
      return
      end
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

wangxn06

金虫 (正式写手)


小木虫(金币+0.5):给个红包,谢谢回帖交流
主程序与子程序中的ihb是相同的,0应该是在子程序里赋的值吧
2楼2010-12-17 18:51:10
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 astringent 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 070305高分子化学与物理 304分求调剂 +16 c297914 2026-03-28 16/800 2026-04-02 20:50 by dongzh2009
[考研] 一志愿山东大学,085600,344 +6 魏子per 2026-04-02 7/350 2026-04-02 20:38 by dongzh2009
[考研] 求调剂 +7 Aniyaio 2026-04-02 7/350 2026-04-02 16:42 by zzsw+
[考研] 一志愿同济大学323分(080500)求调剂 +6 yikeniu 2026-04-01 6/300 2026-04-02 14:19 by smileboy2006
[考研] 266分,一志愿电气工程,本科材料,求材料专业调剂 +4 哇呼哼呼哼 2026-04-02 4/200 2026-04-02 13:10 by yulian1987
[考研] 找调剂 +6 楚乔乔 2026-04-01 6/300 2026-04-02 12:06 by xiaoranmu
[考研] 292分,材料与化工,申请调剂 +19 程晴之 2026-04-01 23/1150 2026-04-02 11:59 by 程晴之
[考研] 348环境工程调剂 +3 吴彦祖24k 2026-04-01 3/150 2026-04-02 09:14 by nanaliuyun
[考研] 296求调剂 +4 汪!?! 2026-03-31 7/350 2026-04-01 22:04 by 客尔美德
[考研] 339求调剂,想调回江苏 +7 烤麦芽 2026-03-27 10/500 2026-04-01 21:35 by 495374996
[考研] 0817化工学硕调剂 +11 努力上岸中! 2026-03-31 11/550 2026-04-01 20:30 by 赖春艳
[考研] 材料专硕306英一数二 +7 z1z2z3879 2026-03-31 7/350 2026-04-01 14:50 by ZXlzxl0425
[考研] 086000生物与医药 初试274求调剂 +5 小叮当来了 2026-03-30 6/300 2026-04-01 14:25 by mxj1203
[考研] 283求调剂 +9 A child 2026-03-28 9/450 2026-04-01 14:20 by Jaylen.
[考研] 335求调剂 +3 321* 2026-03-31 4/200 2026-04-01 00:00 by 321*
[考研] 一志愿a区211,085601-307分求调剂 +10 党嘉豪 2026-03-31 23/1150 2026-03-31 18:44 by JourneyLucky
[考研] 合肥区域性重点一本招收调剂 +4 6266jl 2026-03-30 8/400 2026-03-31 18:43 by 6266jl
[考研] 343求调剂 +8 爱羁绊 2026-03-28 8/400 2026-03-31 16:12 by 不吃魚的貓
[考研] 数一英一271专硕(085401)求调剂,可跨 +7 前行必有光 2026-03-28 8/400 2026-03-28 23:22 by 小木虫tim
[考研] 266求调剂 +11 阳阳哇塞 2026-03-27 12/600 2026-03-27 17:56 by yu221
信息提示
请填处理意见