24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 816  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 280求调剂 +8 咕噜晓晓 2026-04-02 9/450 2026-04-02 16:52 by 1939136013狗壮
[考研] 0703化学 +4 goldtt 2026-04-02 6/300 2026-04-02 16:05 by goldtt
[考研] 材料调剂 +6 一样YWY 2026-04-02 6/300 2026-04-02 15:23 by BruceLiu320
[考研] 材料求调剂 一志愿哈工大总分298分,前三科223分 +12 dongfang59 2026-03-27 12/600 2026-04-02 12:26 by ms629
[考研] 一志愿北交大材料工程总分358 +3 cs0106 2026-04-02 5/250 2026-04-02 11:37 by olim
[考研] 324分 085600材料与化工 +20 呆鹅oor 2026-03-27 20/1000 2026-04-02 10:13 by oooqiao
[考研] 322求调剂 +5 熹僖XX 2026-03-31 6/300 2026-04-02 10:08 by 求调剂zz
[考研] 一志愿厦门大学化学工程(专硕)-数二英二406分-求调剂 +5 厦大化工 2026-04-01 5/250 2026-04-02 10:03 by jp9609
[考研] 材料调剂 +12 一样YWY 2026-04-01 12/600 2026-04-02 00:21 by 百秒光年
[考研] 材料与化工(0856)304求B区调剂 +8 邱gl 2026-03-30 16/800 2026-04-01 17:58 by 邱gl
[考研] 285求调剂 +7 AZMK 2026-03-30 13/650 2026-04-01 17:00 by 七度不信任
[考研] 英一数二生物信息学287分,本科生物科学,求调剂 +3 碧水xyz 2026-03-29 4/200 2026-04-01 15:35 by plum
[考研] 086000生物与医药298调剂求助 +4 元元青青 2026-03-31 6/300 2026-04-01 11:13 by syh9288
[考研] 一志愿华南师范361分,化学求调剂 +4 Nicole88888 2026-04-01 4/200 2026-04-01 10:08 by 唐沐儿
[考研] 0855机械初试280求调剂 +3 kazenotori 2026-03-31 3/150 2026-04-01 10:08 by JourneyLucky
[考研] 083000学硕274求调剂 +12 Li李鱼 2026-03-26 12/600 2026-03-31 10:01 by cal0306
[考研] 293分求调剂,外语为俄语 +5 加一一九 2026-03-31 5/250 2026-03-31 09:39 by zhshch
[考研] 370求调剂 +3 080700调剂 2026-03-30 3/150 2026-03-31 01:09 by A_Zhe
[考研] 福建理工大学材料学院先进合金团队招收考研调剂学生 +3 大华金商都 2026-03-30 4/200 2026-03-31 01:04 by 方英俊602
[考研] 327求调剂 +5 小卡不卡. 2026-03-29 5/250 2026-03-30 19:30 by Wang200018
信息提示
请填处理意见