      SUBROUTINE ROOFC(HO, TODBR4, ISKY, FAROOF, NSUBR, EATTC1, 
     +                 EATTC2, DTIM1, TR0, QLSRF, QSKYS, QCONRF,IDBG) 
C 
C  COMPUTE ROOF TEMPERATURES FOR EACH ATTIC 
C 
C - - - PARAMETER CONSTANTS 
C 
CMDK FTR
CMDK NZN
CMDK NIWL
CMDK NKONST
CMDK NWL
CMDK NWN
CMDK NZW
CMDK SIGMA
C 
C - - - COMMON BLOCKS 
C 
CMDK BLKQS
CMDK ENCBK1
CMDK IRDFQ
CMDK IZZQ
CMDK OWETHR
CMDK SOLARB
CMDK SURFAR
CMDK TCNBLK
CMDK TEMPB
      REAL QLOSRF(2),QSKY(2), SMA(2), SMT(2)
      DATA PATM/1./
C 
C  TCON VALUES WERE CALC WITH DTIM1 AND DTIM1/NSUBR IS NEEDED BELOW, SO 
C               TCON VALUES MUST BE MULTIPLIED BY DTR 
      DTR=1./NSUBR
      FASGE1=(1.-EATTC1)/EATTC1 
      FASGE2=(1.-EATTC2)/EATTC2 
C 
C  FIND ALL CEILINGS CONNECTED TO EACH ATTIC AND WEIGHT UPPER SURFACE 
C  TEMPERATURES BY CEILING AREA 
      SMT(1)=0. 
      SMT(2)=0. 
      SMA(1)=0. 
      SMA(2)=0. 
      DO 502 J=1,NROOMS 
      NRM=NRMA(J) 
      N2=NWALLA(NRM)
      DO 502 K2=1,N2
      IZW=NENC(NRM,K2)
      ID=IDEXP(IZW) 
      IF(ID.EQ.5)THEN 
          IF(NZNC(IZW).EQ.4)THEN
              SMT(1)=SMT(1)+TMP(1,IZW)*AWALLA(IZW)
              SMA(1)=SMA(1)+AWALLA(IZW) 
              ENDIF 
          IF(NZNC(IZW).EQ.5)THEN
              SMT(2)=SMT(2)+TMP(1,IZW)*AWALLA(IZW)
              SMA(2)=SMA(2)+AWALLA(IZW) 
              ENDIF 
          ENDIF 
  502 CONTINUE
C 
C  STORE WEIGHTED UPPER SURFACE TEMPS IN SMT ARRAY
      IF(SMA(1).NE.0.)SMT(1)=SMT(1)/SMA(1)
      IF(SMA(2).NE.0.)SMT(2)=SMT(2)/SMA(2)
C 
C  BEGIN ROOF CALCULATIONS
C 
      RRAD=FASGE1+1.+FASGE2 
      CON1=SIGMA/RRAD 
      QRADRF=0. 
      QLSRF=0.
      QSKYS=0.
      ACEIL(2)=0. 
      QRFSUM(2)=0.
C 
      DO 510 IA=1,NATC
      QRFSUM(IA)=0.
C  ACEIL(IA) IS CEILING AREA IN CONTACT WITH ATTICS IA
      ACEIL(IA)=SMA(IA) 
      SMT4=(SMT(IA)+FTR)**4 
      IQZ=IZT+IA
      T1=TMP(1,IQZ) 
      T14=(T1+FTR)**4 
      QLOSRF(IA)=FAROOF*ROFOM(IA)*SIGMA*(T14-TODBR4)*RAREA(IA)
C 
C     SKY RADIATION CORRELATION 
      PW=(PATM*WODHUM/(.62198+WODHUM))*29.92
      TDP=((ALOG(PW)*1.8893)+30.5790)*ALOG(PW)+79.047
      TDPC=(TDP-32.)*0.5555 
C     CHECK NIGHT OR DAY
      IF (SOLARL(1).EQ.0.) THEN 
         ESKY=0.741+0.0062*TDPC 
      ELSE
         ESKY=0.727+0.006*TDPC
         END IF 
      QSKY(IA)=ISKY*SIGMA*(1.-FAROOF)*(ROFOM(IA)*T14-ESKY*TODBR4) 
     +         *RAREA(IA) 
      RRAREA=1./RAREA(IA) 
      RARAT=SMA(IA)*RRAREA
C    -----CALCULATE TEMPERATURES OF EACH ROOF LUMP
      TR0=(SOLARL(IA)-(QLOSRF(IA)+QSKY(IA)*ISKY)*RRAREA)/HO+TODDB 
      QCONRF=QCONRF+(TMP(1,IQZ)-TODDB)*HO*RAREA(IA)
      K=KONRF(IA) 
      TR1=TMP(1,IQZ)
      TR2=TMP(2,IQZ)
      TR3=TMP(3,IQZ)
      TR4=TMP(4,IQZ)
      IF(IDBG.NE.0)THEN 
          TR1S=TR1
          TR2S=TR2
          TR3S=TR3
          TR4S=TR4
          ENDIF 
      TC1=TCON(1,K) 
      TC2=TCON(2,K) 
      TC3=TCON(3,K) 
      TC4=TCON(4,K) 
      TC5=TCON(5,K) 
      TC6=TCON(6,K) 
      TC7=TCON(7,K) 
      TC8=TCON(8,K) 
      DO 504 I=1, NSUBR 
         TR1N=(TC1*(TR2-TR1)+HO*TC2*(TR0-TR1))*DTR+TR1
         TR2N=(TC3*(TR1-TR2)+TC4*(TR3-TR2))*DTR+TR2 
         TR3N=(TC5*(TR2-TR3)+TC6*(TR4-TR3))*DTR+TR3 
         QRFATC=CON1*(SMT4-(TR4+FTR)**4)
         QRFSUM(IA)=QRFSUM(IA)+QRFATC
         TR4N=(TC7*(TR3-TR4)+TC8*(QROOF(IA)/RAREA(IA) 
     1             +QRFATC*RARAT))*DTR+TR4
         TR1=TR1N 
         TR2=TR2N 
         TR3=TR3N 
         TR4=TR4N 
504      CONTINUE 
      TMPN(1,IQZ)=TR1 
      TMPN(2,IQZ)=TR2 
      TMPN(3,IQZ)=TR3 
      TMPN(4,IQZ)=TR4 
      QRFSUM(IA)=QRFSUM(IA)/NSUBR 
      QRADRF=QRADRF+QRFSUM(IA)*SMA(IA)
      QLSRF=QLSRF+QLOSRF(IA)
      QSKYS=QSKYS+QSKY(IA)
      IF(IDBG.NE.0)THEN 
          WRITE(60,600)IA,HO, TODBR4, TODDB, ISKY, FAROOF, 
     +                NSUBR, EATTC1, EATTC2, DTIM1, TR0, QRFSUM,
     +                QRADRF, QLOSRF(IA), QSKY(IA), QROOF(IA) 
          WRITE(60,601)DTR,   FASGE1,FASGE2,SMT(IA),SMA(IA), 
     +    IQZ,TR4,         T1,T14,TDP,TDPC,SOLARL(IA),ESKY, 
     +    ISKY,SIGMA,FAROOF,ROFOM(IA),RAREA(IA),
     +    TR0,SOLARL(IA),K,TATTA(IA), 
     +    TR1S,TR1,TR2S,TR2,TR3S,TR3,TR4S,TR4,
     +    RRAD,QRFATC,    DTIM1,ACEIL(IA),
     +    TC1,TC2,TC3,TC4,TC5,TC6,TC7,TC8 
          ENDIF 
  510 CONTINUE
      RETURN
  600 FORMAT(10X,'ROOFC:IA,HO,TODBR4,TODDB= ',I3,3G13.5/
     +10X,'            ISKY,FAROOF,NSUBR= ',       I5,G13.5,I5/ 
     +10X,'EATTC1,EATTC2,DTIM1    = ',3G13.5/ 
     +10X,'TR0,QRFSUM(1),QRFSUM(2),QRADRF,QLOSRF= ',5G13.5/ 
     +10X,'QSKY,QROOF(IA)= ',2G13.5)
  601 FORMAT(10X,'DTR,   FASGE1,FASGE2,SMT(1),SMA(1)= ',5G13.5/ 
     +10X,'IQZ,T4,        T1,T14= ',I5,3G13.5/
     +10X,'TDP,TDPC,SOLARL(1),ESKY= ',4G13.5/ 
     +10X,'ISKY,SIGMA,FAROOF,ROFOM(1),RAREA(1)= ',I5,4G13.5/
     +10X,'TR0,SOLARL(1),K,TATTA(1)= ',2G13.5,I5,G13.5/ 
     +10X,'TR1,TR1N= ',2G13.5/
     +10X,'TR2,TR2N= ',2G13.5/
     +10X,'TR3,TR3N= ',2G13.5/
     +10X,'TR4,TR4N= ',2G13.5/
     +10X,'RRAD,QRFATC,    DTIM1,ACEIL(1)= ',4G13.5/
     +10X,'TC1= ',G13.5,'  TC2= ',G13.5/
     +10X,'TC3= ',G13.5,'  TC4= ',G13.5/
     +10X,'TC5= ',G13.5,'  TC6= ',G13.5/
     +10X,'TC7= ',G13.5,'  TC8= ',G13.5)
  602 FORMAT(1X,'ROOFC:TC1,TC2,TC3,TC4= ',4G13.5/ 
     +1X,'TC5,TC6,TC7,TC8= ',4G13.5/
     +1X,'HO,DTR,RRAD,    SIGMA= ',4G13.5/
     +1X,'SMT(IA),FTR,SMT4,CON1= ',4G13.5/
     +1X,'DT,HIR,DTRC8,SMA(IA),RRAREA,RARAT= ',6G13.5)
  603 FORMAT(1X,'TR0,TR1,TR2,TR3,TR4,TATTA(IA)= ',6G13.5) 
  604 FORMAT(1X,'TR1N,TR2N,TR3N,TR4N,QRFATC,QRFSUM(IA)= ',6G13.5) 
      END 
