      SUBROUTINE QIZSET(NRM,RHOBT,QIZONE,QINF,QINFB,IDBG)
C 
C  SET HEAT FLOWS ASSOCIATED WITH INTERZONE FLOWS 
CMDK NWL
CMDK NZN
CMDK NZW
CMDK DUCTS2
CMDK ENCBLK
CMDK ENCBK1
CMDK FLWSIZ
CMDK INDIC1
CMDK QIZNB
CMDK TEMP1
      DATA IFIRST/1/
C  QINFB MAY GET RESET IN QIZLEAK BELOW!      
      QINFB=0.
C 
C  SOLVE FOR HEAT FLOWS ASSOCIATED WITH THE BELOW INTERZONE AIRFLOW 
C    NOTE: CFHIZ VALUES ARE READ AND SET IN DCTFLW
C 
C  NROOMS-    1       2       3       4       5 
C CFHIZ INDICE
C     1       0    W(1-2)   W(1-2)  W(1-2)  W(1-2)
C     2       X       X     W(1-3)  W(1-3)  W(1-3)
C     3       X       X       X     W(1-4)  W(1-4)
C     4       X       X       X       X     W(1-5)
C     5       X       X     W(2-3)  W(2-3)  W(2-3)
C     6       X       X       X     W(2-4)  W(2-4)
C     7       X       X       X       X     W(2-5)
C     8       X       X       X     W(3-4)  W(3-4)
C     9       X       X       X       X     W(3-5)
C    10       X       X       X       X     W(4-5)
C      HERE: 0 OR X MEANS NO INTERZONE FLOW 
C            W(1-2) MEANS AIR FLOW FROM ZONE 1-2, ETC 
C 
C  SOLUTION LOGIC EXECUTES THE ABOVE TABLE BY ROWS
C    NOTE:!!!!MORE LOGIC WILL BE REQUIRED FOR MORE ZONES THAN FIVE!!! 
C 
C   RESET ARRAYS ACCORDING TO THE ABOVE INDICE TABLE
      IF(ICFIZB.EQ.0)THEN 
         IF(NROOMS.EQ.3)THEN
             CFHIZ(5)=CFHIZ(3)
             ENDIF
         IF(NROOMS.EQ.4)THEN
             CFHIZ(9)=CFHIZ(5)
             CFHIZ(10)=CFHIZ(6) 
             CFHIZ(5)=CFHIZ(4)
             CFHIZ(6)=CFHIZ(9)
             CFHIZ(8)=CFHIZ(10) 
             ENDIF
          ENDIF 
      IF(ICFIZB.GT.0.AND.IFIRST.EQ.1)THEN 
C       ICFIZB AND CFHZBI VALUES ARE READ IN NAMELIST CONTROL IN STRRUN 
C       CHFZB1 AND 2 ARE FLOWS INTO THE ZONE WITH BLWR ON AND OFF 
C       CHFZB3 AND 4 ARE FLOWS OUT OF THE ZONE WITH BLWR ON AND OFF 
C  FOUR CFHZBI(1) VALUES CORRESPOND TO W(1-2) IN ABOVE CFHIZ TABLE
C  FOUR CFHZBI(2) VALUES CORRESPOND TO W(1-3) 
C  FOUR CFHZB1(3) VALUES CORRESPOND TO W(2-3) 
          IF(NROOMS.EQ.3)THEN 
C  SET CFHZBI VALUES IN ACCORD WITH ORDER IN CFHIZ ARRAY 
              CFHZB1(5)=CFHZB1(3) 
              CFHZB2(5)=CFHZB2(3) 
              CFHZB3(5)=CFHZB3(3) 
              CFHZB4(5)=CFHZB4(3) 
              ENDIF 
          IF(NROOMS.EQ.4)THEN 
              CFHZB1(9)=CFHZB1(5) 
              CFHZB1(10)=CFHZB1(6)
              CFHZB1(5)=CFHZB1(4) 
              CFHZB1(6)=CFHZB1(9) 
              CFHZB1(8)=CFHZB1(10)
C 
              CFHZB2(9)=CFHZB2(5) 
              CFHZB2(10)=CFHZB2(6)
              CFHZB2(5)=CFHZB2(4) 
              CFHZB2(6)=CFHZB2(9) 
              CFHZB2(8)=CFHZB2(10)
C 
              CFHZB3(9)=CFHZB3(5) 
              CFHZB3(10)=CFHZB3(6)
              CFHZB3(5)=CFHZB3(4) 
              CFHZB3(6)=CFHZB3(9) 
              CFHZB3(8)=CFHZB3(10)
C 
              CFHZB4(9)=CFHZB4(5) 
              CFHZB4(10)=CFHZB4(6)
              CFHZB4(5)=CFHZB4(4) 
              CFHZB4(6)=CFHZB4(9) 
              CFHZB4(8)=CFHZB4(10)
              ENDIF 
          IFIRST=0
          ENDIF 
      QIZONE=0. 
      IF(NROOMS.EQ.1)GO TO 100
C  HEAT FLOWS ASSOCIATED WITH INTERZONE FLOWS CAUSED BY BLWR OPERATION
      IF(ICFIZB.EQ.0)CALL QZST(NRM,NROOMS,1,CFHIZ,RHOBT,QIZONE, 
     +                         QIZONS,IDBG) 
      IF(ICFIZB.GT.0)THEN 
C  HEAT FLOWS ASSOCIATED WITH INTERZONE FLOWS INPUT IN NAMELIST 
C   CONTROL  IN STRRUN
C     INTERZONE HEAT FLOWS IN FORWARD DIR,I.E. (1-2),(1-3),(2-3)
          IF(IEFAN.NE.0)THEN
C                                -- BLOWER ON --
              CALL QZST(NRM,NROOMS,1,CFHZB1,RHOBT,QIZONE,QIZONS,IDBG) 
          ELSE
C                                -- BLOWER OFF -- 
              CALL QZST(NRM,NROOMS,1,CFHZB2,RHOBT,QIZONE,QIZONS,IDBG) 
              ENDIF 
C  INTERZONE HEAT FLOWS IN BACKWARD DIRECTION (2-1),(3-1),(3-2),
          IF(IEFAN.NE.0)THEN
C                                -- BLOWER ON --
              CALL QZST(NRM,NROOMS,2,CFHZB3,RHOBT,QIZONE,QIZONS,IDBG) 
          ELSE
C                                -- BLOWER OFF -- 
              CALL QZST(NRM,NROOMS,2,CFHZB4,RHOBT,QIZONE,QIZONS,IDBG) 
              ENDIF 
          ENDIF 
  100 CONTINUE
      IF(NLEAKS.GT.0)CALL QZLEAK(NRM,RHOBT,QIZONE,QIZONS,QINF,
     +                           QINFB,IDBG)      
      RETURN
      END 
      SUBROUTINE QZST(NRM,NROOMS,IC,CFHIZ,RHOBT,QIZONE,QIZONS,IDBG) 
C 
C   SET HEAT FLOWS ASSOCIATED WITH INTERZONE FLOWS
C   IC    =1, FORWARD FLOWS (1-2),(1-3),(2-3) FOR EXAMPLE 
C         =2, BACKFLOWS CAUSED BY THERMAL GRADIENTS IN OPENINGS SUCH
C             AS A DOOR (2-1),(3-1),(3-2) FOR EXAMPLE 
      PARAMETER (NZN=5)
      DIMENSION CFHIZ(10),IZ(10,2,2),QIZONS(NZN)
C  IZ VALUES ARE ZONE NUMBER OF OPERATING ZONES 
      DATA (((IZ(I,J,K),I=1,10),J=1,2),K=1,2)/
     +        1,1,1,1,2,2,2,3,3,4,
     +        2,3,4,5,3,4,5,4,5,5,
     +        2,3,4,5,3,4,5,4,5,5,
     +        1,1,1,1,2,2,2,3,3,4/
      IF(IDBG.NE.0)WRITE(60,501)NRM,IC,(CFHIZ(I),I=1,3)
C 
C  HEAT FLOWS SET IN ACCORD WITH ORDER OF CFHIZ ARRAY(SEE TABLE IN
C  COMMENTS OF QIZSET SUBPROGRAM
      DO 30 I=1,10
      IF(NROOMS.EQ.3)THEN 
         IF(I.EQ.3.OR.I.EQ.4)GO TO 30 
         IF(I.EQ.6)GO TO 40 
         ENDIF
      IF(NROOMS.EQ.4)THEN 
         IF(I.EQ.4.OR.I.EQ.7)GO TO 30 
         IF(I.EQ.9)GO TO 40 
         ENDIF
      CALL QZSET(NRM,IZ(I,1,IC),IZ(I,2,IC),CFHIZ(I),RHOBT,QIZONE, 
     +           QIZONS,IDBG) 
      IF(NROOMS.EQ.2)GO TO 40 
   30 CONTINUE
   40 CONTINUE
      RETURN
  501 FORMAT(1X,'NRM,IC,CFHIZ= ',2I4,3G13.5)
      END 
      SUBROUTINE QZSET(NRM,NRM1,NRM2,CFHIZ,RHOBT,QIZONE,QIZONS,IDBG)
C 
C  AUXILLIARY SUBPROGRAM TO QIZSET USED TO SET INTERZONE
C  HEAT FLOWS DUE TO AIR MOVEMENT BETWEEN ZONES 
CMDK CPAIR
CMDK FTR
CMDK NZN
CMDK FLWSIZ
CMDK INDIC1
CMDK TEMP1
CMDK TIMEB
      REAL QIZONS(NZN)
C      
C  QIZONE IS HEAT EXCHANGE IN ZONE NRM FROM INTERZONE FLOW
C    NOTE: QIZONE BECOMES QIZN(NRM) IN TAZONE AND TBZONE.      
C  QIZONS IS HEAT LOST FROM THE ZONE THAT INTR ZONE FLOW COMES FROM.
C  RHOBT IS SET IN TAZONE.
      DQZONE=0. 
C         IF FURNACE BLOWER IS OFF, DONT PERMIT INTERZONE FLOWS 
C         IF INTERZONE FLOWS WERE NOT READ IN NAMELIST CONTROL IN STRRUN
      IF(IEFAN.EQ.0.AND.ICFIZB.EQ.0)GO TO 100 
      IF(NRM.EQ.NRM1.AND.CFHIZ.LT.0.)THEN 
C      
C           AIR FLOW FROM ZONE NRM2 TO ZONE NRM1
          DQZONE=RHOBT/(TI(NRM2)+FTR)*ABS(CFHIZ)*CPAIR* 
     +                   (TI(NRM2)-TI(NRM1))
C NOTE: IF TEMP IN ZONE NRM2 IS LOWER THAN IN NRM1, IT ISNT LOSING
C       HEAT =DQZONE.  COOL AIR IS SIMPLY FLOWING OUT OF ZONE NRM2!     
          IF(DQZONE.GT.0.)QIZONS(NRM2)=QIZONS(NRM2)+DQZONE
            
          IF(IDBG.GT.0)WRITE(60,500)NRM2,NRM1
          ENDIF 
      IF(NRM.EQ.NRM2.AND.CFHIZ.GT.0.)THEN 
C      
C            AIR FLOW FROM ZONE NRM1 TO ZONE NRM2 
          DQZONE=RHOBT/(TI(NRM1)+FTR)*CFHIZ*CPAIR*
     +                  (TI(NRM1)-TI(NRM2)) 
C NOTE: IF TEMP IN ZONE NRM1 IS LOWER THAN IN NRM2, IT ISNT LOSING 
C       HEAT = DQZONE.  COOL AIR IS SIMPLY FLOWING OUT OF ZONE NRM!     
          IF(DQZONE.GT.0.)THEN
            QIZONS(NRM1)=QIZONS(NRM1)+DQZONE
C              MUST NEGATE DQZONE FOR PROPER SIGN WITH QIZONE            
            DQZONE=(-1.)*DQZONE
          ELSE
            DQZONE=0.
          ENDIF
          IF(IDBG.GT.0)WRITE(60,500)NRM1,NRM2
          ENDIF 
  100 QIZONE=QIZONE+DQZONE
      IF(IDBG.GT.0.AND.DQZONE.NE.0.)WRITE(60,501)NRM,CFHIZ,DQZONE,QIZONE 
      RETURN
  500 FORMAT(1H0,'AIR FLOW FROM ZONE',I4,' TO ZONE',I4) 
  501 FORMAT(1X,'ZONE NO.= ',I4/1X,'ZONE AIR FLOW= ',G13.5,'CFH'/ 
     +1X,'HEAT FLOW BY INTERZONE FLOW= ',G13.5,' BTU/HR'/ 
     +1X,'TOTAL HEAT FLOW TO THIS ZONE BY INTERZONE FLOW= ',G13.5,
     +' BTU/HR')
      END 
      SUBROUTINE QZLEAK(NRM,RHOBT,QIZONE,QIZONS,QINF,QINFB,IDBG)      
C         HEAT FLOWS ASSOCIATED WITH LEAKS IN VERTICAL ENCLOSURE
C         ELEMENTS WITH TEMPERATURE DIFFERENCE ON EITHER SIDE 
C         
CMDK CPAIR
CMDK FTR
CMDK NZN
CMDK NZW
CMDK NWL
CMDK ENCBLK
CMDK ENCBK1
CMDK ENCBK2
CMDK LPSTRB
CMDK OWETHR
CMDK TEMP1
CMDK TIMEB
C SEE QZSET FOR DEFINITION OF QIZONE AND QIZONS
      DIMENSION QIZONS(NZN)
      DO 100 J=1,NLEAKS
      IZW=IZWLEAK(J)
C  CHECK TO SEE IF THE ENCLOSURE IZW WITH THIS LEAK IS IN ZONE NRM:      
      N2=NWALLA(NRM)
      DO 2 K2=1,N2
    2 IF(IZW.EQ.NENC(NRM,K2))GO TO 3
      GO TO 100
    3 CONTINUE
      DQZONE=0.
      H=HGTLEAK(IZW)
      W=WDLEAK(IZW)
      NZONC=NZNC(IZW)
      IF(NZONC.GT.8)THEN
        NZN8=NZONC-8
        T2=TI(NZN8)
      ELSE IF(NZONC.EQ.1)THEN
        T2=TODDB
      ELSE IF(NZONC.EQ.2.OR.NZONC.EQ.7)THEN
        T2=TI(NZNBAS)
      ELSE IF(NZONC.EQ.3.OR.NZONC.EQ.8)THEN
        T2=TCRW
      ELSE IF(NZONC.EQ.6)THEN
        T2=TGARAG
      ELSE
        GO TO 100
      ENDIF
      RHO1=RHOBT/(TI(NRM)+FTR)
      RHO2=RHOBT/(T2+FTR)
C      IF(NTIM.LT.100)WRITE(60,*)' TI,TODDB,RHO1,RHO2= ',TI,TODDB,
C     +               RHO1,RHO2
C  USE FLOW THROUGH A CRACK IF WIDTH OR HEIGHT OF LEAKAGE OPENING
C  IS LESS THAN 0.25 INCHES  (AN ARBITRARY DECISION!)
      IF(H.LT.0.25.OR.W.LT.0.25)THEN
        IOUT=1
        IF(NZONC.EQ.1.AND.WSPED.GT.0.)THEN
C           CONNECTING ZONE IS OUTDOORS (I.E. THIS IS AN OUTSIDE WALL)          
C           USE WIND VELOCITY PRESSURE FOR DRIVING PRESSURE DIFF.
C              UNITS:  WSPED - MILES/HR; RHO2 - LBM/FT3
C                      DPW - LBF/FT2
C                      RHO2 - LBM/FT3; WLEAK - LBM/HR
C              .03343 IS (5280/3600)^2/(2*32.174)
C              120.3 IS .6*3600*SQRT(2*32.174)/144.
           DPW=.03343*RHO2*WSPED*WSPED
C        ELSE
C              USE STACK EFFECT DUE TO TEMP DIFF ACROSS ENCLOSURE ELE
C              REF. 1989 ASHRAE HANDBOOK OF FUNDAMENTALS, P.23.4
C              NOTE: HNPL IS HEIGHT FROM CENTER OF OPENING TO NEUTRAL
C                    PRESSURE LEVEL IN BUILDING, INCHES
          DPW=(RHO2-RHO1)*HNPL(IZW)/12.
          IF(DPW.LT.0.)THEN
            DPW=(-1.)*DPW
            IOUT= -1
          ENDIF
        ENDIF
        RHOAV=.5*(RHO1+RHO2)
        IF(IOUT.EQ.1)THEN
          WLEAK=120.3*W*H*RHO2*(DPW/RHOAV)**.65
        ELSE
          WLEAK=120.3*IOUT*W*H*RHO1*(DPW/RHOAV)**.65
        ENDIF
      ELSE
C              USE BROWN-SOLVASON MODEL FOR LARGE OPENINGS.
C              REF: INT.J.HEAT MASS TRANSFER,VOL 5,P.859-868(1962) 
C              COEF OF .26 IF FROM WEBER AND KEARNEY AS PER WALTON
C              REF: WALTON,G.N.,ASHRAE TRANS(1984),VOL 90,PT 1D
C 10.5828 IS .26(.0147).72*SQRT(32.174)/(.24*12.32E-06*12^2.5)
C  WHERE .0147 IS THERM COND OF AIR,BTU/HR-FT-F
C        .72 IS PRANDTL NO. OF AIR
C        12.32E-06 IS VISCOSITY OF AIR,LBM/FT-SEC
C        .24 IS SPEC HEAT OF AIR, BTU/LBM-F
        DRHO=RHO2-RHO1
        RHOAV=.5*(RHO2+RHO1)
        IOUT=1
        RHO=RHO2
        IF(DRHO.LT.0.)THEN
          DRHO=DRHO* (-1.)
          IOUT = -1
          RHO=RHO1
        ENDIF
        WLEAK=10.5828*IOUT*RHO*W*H**1.5*SQRT(DRHO/RHOAV)
      ENDIF
      IF(WLEAK.GT.0.)THEN
C              AIR FLOWS INTO ZONE NRM!
        DQZONE=WLEAK*CPAIR*(T2 - TI(NRM))
        IF(NZONC.EQ.1)THEN
          IF(NRM.NE.NZNBAS)THEN
            QINF=QINF+DQZONE
C              QINF IS USED IN TAZONE TO TRAP INFILTRATION VALUES,
C              BUT IS NOT USED IN CALC OF ZONE AIR TEMP.  THEREFORE
C              DONT SET DQZONE= 0., BECAUSE IT IS NEEDED IN CALC OF
C              ZONE AIR TEMP.        
          ELSE
            QINFB=QINFB+DQZONE
C              HERE QINFB IS USED IN TBZONE TO CALC ZONE AIR TEMP, SO 
C              SET DQZONE=0.
            DQZONE=0.
          ENDIF
        ENDIF
        
        IF(DQZONE.GT.0.)THEN
          IF(NZONC.GT.8)THEN
            QIZONS(NZN8)=QIZONS(NZN8)+DQZONE
          ELSE IF(NZONC.EQ.2.OR.NZONC.EQ.7)THEN
            QIZONS(NZNBAS)=QIZONS(NZNBAS)+DQZONE
          ENDIF
        ENDIF
      ELSE
C              AIR FLOWS OUT OF ZONE NRM
C    DQZONE IS NOT A HEAT LOAD OR LOSS IN ZONE NRM IF TI(NRM)<T2
C    WHEN AIR FLOWS OUT OF ZONE NRM.
        IF(TI(NRM).GT.T2)DQZONE=WLEAK*CPAIR*(TI(NRM)-T2)        
      ENDIF
      QIZONE=QIZONE+DQZONE
      IF(IDBG.GT.0)WRITE(60,*)' QZLEAK: NRM,WLEAK,DQZONE,QIZONE= ',
     +             NRM,WLEAK,DQZONE,QIZONE
  100 CONTINUE      
      RETURN
      END
