24小时热门版块排行榜    

查看: 790  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
信息提示
请填处理意见