      SUBROUTINE MRTSWF(QINT,QRAD,IDBG)
C
C  COMPUTE SELF-WEIGHTING FACTORS FOR MEAN RADIENT TEMP ANALYSIS
C  USED TO ACCOUNT FOR THE FACT THAT A SURFACE CANNOT SEE ITSELF
C  (CALL TO MRTSWF ONLY OCCURS ONCE (FROM STRRUN), BUT ENTRY MRTHRI
C   IS EXECUTED AT EVERY 2 MIN. TIMESTEP)
C
C - - -CONSTANTS
      PARAMETER (NSF=22)
CMDK NZN
CMDK NIWL
CMDK NKONST
CMDK NWN
CMDK NWL
CMDK NZW
CMDK BLKRAD
CMDK CNSTRK
CMDK ENCBK1
CMDK ENCBK2
CMDK ENCBLK
CMDK MRTBLK
CMDK MZON1
CMDK SOLARB
CMDK SURFAR
CMDK TEMPB
CMDK TIMEB
      REAL S(NSF), FSV(NSF), F(NSF), HRF(NZW), TRL(NZN), AFLTOT(NZN),
     +     AWLTOT(NZN)
C  NSF MUST BE LARGE ENOUGH TO INCL ALL ACTIVE ENCLOSURE
C      ELEMENTS FOR ONE ZONE (INCLUDING BACKSIDE OF SUBMERGED INTERIOR
C         PARTITION WALLS)
      DATA TOL/.0001/
      DATA SIGMA/.1714E-08/
      DATA IMESS/0/
C  NOTE: TREF, C1,AND C2 ARE INTERRELATED AS INDICATED BELOW
C        VALUES FOR TREF AND C2 ARE ARBITRARY
      DATA TREF/80.6/
      C2=1./360.
      C1=1.-C2*TREF
      C4=RADSOL*(1.-RADSFL)
      C5=RADSOL*RADSFL
      TREF3=(TREF+459.7)**3
      IF(IDBG.NE.0)WRITE(60,504)TREF,TREF3,RADSOL,RADSFL,C1,C2,C4
C
      DO 200 JT=1,NROOMS
      NRM=NRMA(JT)
      AFLTOT(NRM)=0.
      AWLTOT(NRM)=0.
      N2=NWALLA(NRM)
      IF(N2.GT.NSF)THEN
          WRITE(60,502)NSF
          STOP 'MRTSWF:MUST INCR NSF'
          ENDIF
C
C  FOR ZONE NRM, CALC ALL SELF-WEIGHTING FACTORS,FI, AND HRF VALUES
C
      N2A=N2
      DO 100 K2=1,N2
      IZW=NENC(NRM,K2)
      ID=IDEXP(IZW)
      NZON=NZNC(IZW)-8
      IF(ID.EQ.7.AND.NZNC(IZW).NE.6)THEN
        XR=1
C  FOR PARTITION WALLS SUBMERGED IN ZONE, XR=2.
        IF(ID.EQ.7.AND.NRM.EQ.NZON)THEN
          XR=2.
        ENDIF
        AWLTOT(NRM)=AWLTOT(NRM)+XR*AWALLA(IZW)
      ENDIF
      IF(ID.EQ.6.OR.ID.EQ.8)THEN
        AFLTOT(NRM)=AFLTOT(NRM)+AWALLA(IZW)
      ENDIF
      S(K2)=AWALLA(IZW)
      FSV(K2)=1.
      F(K2)=1.
C  CHECK FOR ANY SUBMERGED PARTITION WALLS.  ADD AN ENCLOSURE
C     SURFACE FOR EACH SUBMERGED WALL TO ACCOUNT FOR RADIATION
C     EXCHANGE WITH BACKSIDE OF SURFACE.  THIS ADDED SURFACE
C     IS ONLY USED TO GET CORRECT F(I)
      IF(ID.EQ.7.AND.NRM.EQ.NZON)THEN
          N2A=N2A+1
          IF(N2A.GT.NSF)THEN
              WRITE(60,502)NSF
              STOP 'MRTSWF:MUST INCR NSF'
              ENDIF
          S(N2A)=AWALLA(IZW)
          FSV(N2A)=1.
          F(N2A)=1.
          ENDIF
  100 CONTINUE
C
C  NOW CALC SELF WEIGHTING FACTORS(F(I)) AND HRF VALUES FOR THIS ZONE
      ITER=0
C
C  ITERATE TO GET F(I)'S BY DIRECT SUBSTITUTION
  130 IGO=0
      SUM=0
      DO 140 J=1,N2A
      SUM=SUM+S(J)*F(J)
  140 CONTINUE
      DO 150 I=1,N2A
      FSV(I)=1./(1.-S(I)*F(I)/SUM)
      DIF=ABS(FSV(I)-F(I))
      IF(DIF.GT.TOL*F(I))IGO=1
  150 CONTINUE
      ITER=ITER+1
      IF(IGO.EQ.1)THEN
        IF(IDBG.NE.0)WRITE(60,500)NRM,ITER,(FSV(K),F(K),K=1,N2)
        DO 160 I=1,N2A
  160   F(I)=FSV(I)
        IF(ITER.LT.100)GO TO 130
        STOP 'MRTSWF: F WONT CONVERGE'
      ENDIF
      DO 170 I=1,N2A
  170 F(I)=FSV(I)
      IF(IDBG.NE.0)WRITE(60,501)NRM,ITER,(F(K),K=1,N2A)
C
C  NOW CALC HRF VALUES (TARP MANUAL -MAR.1983,P.69,EQN H.2.3)
      DO 180 K2=1,N2
      IZW=NENC(NRM,K2)
      FI=F(K2)
      EPSLMI=WALLFI(IZW)
      HRF(IZW)=4.*SIGMA*TREF3/(1./FI+(1.-EPSLMI)/EPSLMI)
      HRI(IZW)=HRF(IZW)
      IF(IDBG.NE.0)WRITE(60,503)NRM,IZW,HRF(IZW),SIGMA,
     +             FI,EPSLMI
  180 CONTINUE
  200 CONTINUE
      QRAD=0.
      RETURN
C- - - - - - - ENTRY MRTHRI BELOW
      ENTRY MRTHRI(QINT,QRAD,IDBG)
      IF(IDBG.NE.0)WRITE(60,505)QINT,RADINT,RADSOL,RADSFL
C - - - - - -
      DO 220 JT=1,NROOMS
      NRM=NRMA(JT)
      CALL ZERV(2,SUMA,SUMB,0.,0.,0.,0.,0.,0.,0.,0.)
      N2=NWALLA(NRM)
C - - - - - -
      DO 210 K2=1,N2
      IZW=NENC(NRM,K2)
      NZON=NZNC(IZW)-8
      IF(NZNC(IZW).EQ.2.OR.NZNC(IZW).EQ.7)NZON=NZNBAS
      ID=IDEXP(IZW)
C - - -GET ZONE-SIDE SURFACE TEMP
      KON=KONSTA(IZW)
      NLM=NLMP(KON)
      IF(NLM.EQ.1)TISRF=TMPN(3,IZW)
      IF(NLM.EQ.3)TISRF=TMPN(4,IZW)
      HRI(IZW)=(C1+C2*TISRF)*HRF(IZW)
      XR=1.
C  DOUBLE RADIATION AREA TO ACCOUNT FOR BOTH SIDES OF SUBMERGED
C       INTERIOR WALLS
      IF(ID.EQ.7.AND.NZON.EQ.NRM)XR=2.
      SUMA=SUMA+XR*HRI(IZW)*AWALLA(IZW)*TISRF
      SUMB=SUMB+XR*HRI(IZW)*AWALLA(IZW)
      IF(IDBG.NE.0)WRITE(60,511)NRM,IZW,ID,HRI(IZW),TISRF,XR,SUMA,SUMB
     +,AWALLA(IZW)
  210 CONTINUE
      IF(SUMB.EQ.0.)WRITE(*,*)' MRTSWF: SUMB AT 210 = 0.,NRM= ',NRM
      TRL(NRM)=SUMA/SUMB
      IF(IDBG.NE.0)WRITE(60,512)TRL(NRM),SUMA,SUMB
  220 CONTINUE
      QRAD=0.
C
      DO 240 JT=1,NROOMS
      NRM=NRMA(JT)
      CALL ZERV(2,SUMA,SUMB,0.,0.,0.,0.,0.,0.,0.,0.)
      N2=NWALLA(NRM)
      C3=C1+C2*TRL(NRM)
      QRADC=QINT*RADINT*RQINT(NRM)
      QRAD=QRAD+QRADC
      SOLARW=SOLARL(2+NRM)
      IF(IMESS.LT.50)THEN      
        IF(NRM.EQ.NZNBAS.AND.SOLARW.GT.0.)THEN
          WRITE(60,*)' ****  OOOPS!  SHOULDNT HAVE SOLAR IN BASEMENT!'
          WRITE(60,*)'       SOLARW= ',SOLARW,' IN ZONE ',NRM
        ENDIF
        IMESS=IMESS+1
      ENDIF
      QSIF=C5*SOLARW/AFLTOT(NRM)
      QSIW=C4*SOLARW/AWLTOT(NRM)
      IF(IDBG.NE.0)WRITE(60,506)NRM,TRL(NRM),C3,RQINT(NRM),
     +                         QRADC,SOLARW
C
      DO 230 K2=1,N2
      IZW=NENC(NRM,K2)
      NZON=NZNC(IZW)-8
      IF(NZNC(IZW).EQ.2.OR.NZNC(IZW).EQ.7)NZON=NZNBAS
      HRI(IZW)=C3*HRI(IZW)
      IF(IDBG.NE.0)WRITE(60,507)IZW,HRI(IZW)
      ID=IDEXP(IZW)
      KON=KONSTA(IZW)
      NLM=NLMP(KON)
      IF(NLM.EQ.1)TISRF=TMPN(3,IZW)
      IF(NLM.EQ.3)TISRF=TMPN(4,IZW)
      SUMA=SUMA+XR*HRI(IZW)*AWALLA(IZW)*TISRF
      SUMB=SUMB+XR*HRI(IZW)*AWALLA(IZW)
C - -    QSI IS REFLECTED SOLAR ABSORBED BY INSIDE SURFACE OF PART WALLS
C        OR FLOOR IZW, BTU/HR-FT2 (*--*NOTE:PER SQ FT!!)
C        SOLARL IS SET IN STRLP1.
      QSI(IZW)=0.
      IF(ID.EQ.6.OR.ID.EQ.8)THEN
C              FLOOR INSIDE      
        QSI(IZW)=QSIF
      ELSE
        IF(ID.EQ.7.AND.NZNC(IZW).NE.6)THEN
          QSI(IZW)=QSIW
        ENDIF
      ENDIF
      IF(IDBG.NE.0)WRITE(60,508)QSI(IZW),SUMA,SUMB,TISRF,XR
  230 CONTINUE
C
C  TMR IS MEAN RADIENT TEMPERATURE
C    NOTE::WINDOW AREAS ARE NOT INCLUDED IN TMR CALCULATION AS YET.
C          LOSSES AT WINDOWS ARE ACCOUNTED FOR IN OVERALL U FROM
C          ZONE AIR TO OUTDOOR TEMP AT WINDOWS IN SUBPROGRAM LOOP
C          (SEE QWINST PARAMETER IN LOOP)
      IF(SUMB.EQ.0.)WRITE(*,*)' MRTSWF: SUMB AT 230 = 0.,NRM= ',NRM
      TMR(NRM)=(SUMA+QRADC)/SUMB
      IF(IDBG.NE.0)WRITE(60,509)NRM,TMR(NRM)
  240 CONTINUE
C
  500 FORMAT(1X,'MRTSWF:ZONE= ',I3,'ITER= ',I5/' FSV,F= '/
     +20(1X,2G13.5/))
  501 FORMAT(1X,'MRTSWF:ZONE= ',I3,'MAX ITER= ',I5/
     +' FINAL VALUES FOR FI ARE= '/
     +20(1X,G13.5/))
  502 FORMAT(1H0,'MRTSWF:MUST INCR NSF ABOVE ',I5)
  503 FORMAT(10X,'NRM,IZW,HRF= ',2I5,G13.5/
     +       10X,'SIGMA,FI,EPSLMI= ',3G13.5)
  504 FORMAT(1H0,'MRTSWF:TREF,TREF3,RADSOL,RADSFL= ',4G13.5/
     +       8X,'C1,C2,C4= ',3G13.5)
  505 FORMAT(1H0,'- - -BEGIN MRTHRI IN MRTSWF'/
     +       10X,'QINT,RADINT,RADSOL,RADSFL= ',4G13.5)
  506 FORMAT(8X,'NRM,TRL(NRM),C3= ',I5,2G13.5/
     +8X,'RQINT(NRM),QRADC,SOLARW= ',3G13.5)
  507 FORMAT(1H0,9X,'IZW,HRI AFTER ADJUSTMENT BY C3= ',I5,G13.5)
  508 FORMAT(12X,'QSI,SUMA,SUMB= ',3G13.5/
     +12X,'TISURF,XR= ',2G13.5)
  509 FORMAT(10X,'ZONE NO.= ',I4,'  MEAN RAD TEMP= ',G13.5)
  511 FORMAT(10X,'NRM,IZW,ID,HRI,TISRF= ',3I4,2G13.5/
     +10X,'XR,SUMA,SUMB,AWALLA(IZW)= ',4G13.5)
  512 FORMAT(12X,'TRL,SUMA,SUMB= ',3G13.5)
      END
