      SUBROUTINE ELCFUR(IBURN,TCYCLE,WAIR,TA1,PCTJAC,TA2,QIN)
C
C  ELECTRIC FURNACE MODEL
C
C  IBURN = 0, TSTAT OFF        IBURN=1, TSTAT ON
C  TCYCLE = TIME FROM TSTAT EVENT(END OF THIS DTIME INTERVAL),HR
C  WAIR = BLOWER AIR FLOW, LB/HR
C  TA1 = RETURN AIR TEMP TO BLOWER, F
C        (BLOWER PWR IS LUMPED WITH ELEC FUR PWR)
C  PCTJAC  JACKET LOSS IN PCT OF INPUT ENERGY
C  TA2 = OUTLET AIR TEMP, F
C  QIN = INTEG INPUT ENERGY FOR THIS TIMESTEP,BTU/HR
CMDK EFUR
      NAMELIST/INPELC/FACKW,TMOF,TMON,XKWOF,XKWON
C INPUTS FROM NAMELIST INPELC:
C  FACKW - CAPACITY MULTIPLIER (APPLIED TO BOTH XKWOF AND XKWON 
C  TMOF  - (1) TIME AFTER OFF EVENT AT STEP TO XKWOF(2),SEC
C          (2) TIME AFTER OFF EVENT AT STEP TO XKWOF(3),SEC
C          (3) TIME AFTER OFF EVENT AT STEP TO XKWOF(4),SEC
C  TMON  - (1) TIME AFTER ON EVENT AT STEP TO XKWON(2),SEC
C          (2) TIME AFTER ON EVENT AT STEP TO XKWON(3),SEC
C          (3) TIME AFTER ON EVENT AT STEP TO XKWON(4),SEC
C          (4) TIME AFTER ON EVENT AT STEP TO XKWON(5),SEC
C  XKWOF - HEATING RATE IN STEPS FROM MAX FOR XKWOF(1) AT OFF EVENT
C          TO 0. AT XKWOF(4),KW
C  XKWON - HEATING RATE IN FIVE STEPS FROM 0. FOR XKWON(1) AT THE 
C          ON EVENT TO MAXIMUM AT XKWON(5),KW
C
C  PROGRAM LOGIC SETUP FOR LENNOX ELECTRIC FURNACE
C     TIMES IN TMON AND TMOF ARE SEC AND WERE ADJUSTED SO THAT
C          RUN KWH WILL BE MATCHED WHEN PROCESSING EVENT FILE
      DATA TCYCSL/0./
      DATA IBRNLS/0/
      DATA IONE/0/
      IF(IONE.EQ.0)THEN
          FACJAC=1.-.01*PCTJAC
C
          OPEN(13,FILE='TAPE13',STATUS='OLD',IOSTAT=IO13)
          IF(IO13.NE.0)THEN
            WRITE(60,*)' ELCFUR: CANT OPEN TAPE13 WITH NAMELIST INPELC'
            STOP 'ELCFUR: CANT OPEN TAPE13 WITH NAMELIST INPELC'
            END IF
          READ(13,INPELC,END=90)
          CLOSE(13)
          WRITE(60,INPELC)
C
          DO 4 I=1,5
          IF(I.EQ.5)GO TO 2
          XKWOF(I)=XKWOF(I)*FACKW
    2     XKWON(I)=XKWON(I)*FACKW
    4     CONTINUE
          WRITE(60,500)PCTJAC
          WRITE(60,503)TMON,XKWON
          WRITE(60,501)TMOF,XKWOF
          IONE=1
          ENDIF
C
      WACP=WAIR*.24
C  FIND CONTROL INTERVAL FOR ELECT FURNACE
      TCYCS=TCYCLE*3600.
      IF(IBURN.EQ.0)THEN
C  TSTAT OFF - - - - - -
      IF(IBURN.NE.IBRNLS)TCYCSL=0.
          CALL EFUROF(TCYCSL,TCYCS,IEON,TA1,FACJAC,TA2,QIN)
      ELSE
C  TSTAT ON  - - - - - - -
      IF(IBURN.NE.IBRNLS)TCYCSL=0.
          CALL EFURON(TCYCSL,TCYCS,IEON,TA1,FACJAC,TA2,QIN)
          ENDIF
      TCYCSL=TCYCS
      IBRNLS=IBURN
      RETURN
   90 STOP 'ELCFUR: EOF ON TAPE13'
  500 FORMAT(1H0,'ELECTRIC FURNACE CALIBRATION DATA'/
     +10X,'UNIT HAS JACKET LOSS OF ',G13.5,
     +' PERCENT OF INPUT ENERGY WHEN ON')
  501 FORMAT(1H0,' TIME(SEC)OFF= ',13X,4G13.5/
     +' KW INPUT    = ',5G13.5)
  503 FORMAT(' TIME(SEC) ON= ',4G13.5/
     +' KW INPUT    = ',5G13.5)
      END
      SUBROUTINE EFUROF(TCYCSL,TCYCS,IEON,TA1,FACJAC,TA2,QIN)
C
C  CALCULATE OUTLET TEMP OF ELEC FURN WHEN TSTAT TURNED OFF
C  INPUTS: TCYCSL  "ON" CYCLE TIME AT LAST TIMESTEP,SEC
C          TCYCS  "ON" CYCLE TIME AT THIS TIMESTEP,SEC
C          IEON  INTERVAL NO. AT LAST TSTAT "ON" STEP
C          TA1  INLET AIR TEMP(UPSTREAM OF BLOWER OR
C              DOWNSTREAM OF BLOWER WITH BLOWER POWER=0.
C OUTPUT: TA2  OUTLET AIR TEMP,F
C ASSUMPTIONS: NO THERMAL LAG IN ELECTRIC HEATER
CMDK EFUR
C
C  FIND IEOFL AND IEOF
      IEOFL=4
      IEOF=4
      I=4
      JI=1
      DTQ=0.
      IF(IEON.EQ.4)THEN
          DTQ=TMOF(1)
          JI=2
          ENDIF
      DO 10 J=JI,3
      I=I-1
      IF((TMOF(I)-DTQ).GT.TCYCS)IEOF=I
   10 IF((TMOF(I)-DTQ).GT.TCYCSL)IEOFL=I
C
C  SELECT INTERVAL ON SAME IEOF'S
      DO 20 J=1,4
   20 IF(IEOFL.EQ.J.AND.IEOF.EQ.J)GO TO 30
      GO TO 40
C  INTERVAL WITH SAME IEOF'S
   30 DTMS2=TCYCS-TCYCSL
      DTMS1=0.
      QIN1=0.
      GO TO 70
C  INTERVAL WITH CONSEQUTIVE IEOF'S
   40 DO 50 I=JI,3
      IF(IEOFL.EQ.I.AND.IEOF.EQ.I+1)THEN
          DTMS1=(TMOF(I)-DTQ)-TCYCSL
          DTMS2=TCYCS-(TMOF(I)-DTQ)
          GO TO 60
          ENDIF
   50 CONTINUE
      WRITE(60,500)IEOFL,IEOF,TCYCSL,TCYCS
      STOP 'EFUROF: TROUBLE WITH INTERVALS'
C  FIRST SEGMENT OF INTERVAL
   60 QIN1=3413.*XKWOF(IEOFL)
C  SECOND SEGMENT OF INTERVAL
   70 QIN2=3413.*XKWOF(IEOF)
C
C  INTEGRATED QIN
      QIN=(QIN1*DTMS1+QIN2*DTMS2)/(DTMS1+DTMS2)
      TA2=TA1+QIN*FACJAC/WACP
      RETURN
  500 FORMAT(1H0,'---OOPS,COULD NOT FIND IEOF INTERVALS',
     +' IEOFL,IEOF= ',2I5,' TCYCSL,TCYCS= ',2G13.5)
      END
      SUBROUTINE EFURON(TCYCSL,TCYCS,IEON,TA1,FACJAC,TA2,QIN)
C
C  CALCULATE OUTLET TEMP OF ELEC FURN WHEN TSTAT TURNED ON
C  INPUTS: TCYCSL  "ON" CYCLE TIME AT LAST TIMESTEP,SEC
C          TCYCS  "ON" CYCLE TIME AT THIS TIMESTEP, SEC
C          TA1  INLET AIR TEMP(UPSTREAM OF BLOWER OR
C               DOWNSTREAM OF BLOWER WITH BLOWER POWER=0.),F
C  OUTPUTS: IEON  INTERVAL NO. UPON EXITING
C           TA2  OUTLET AIR TEMP,F
C  ASSUMPTION:  NO THERMAL LAG IN ELECTRIC HEATER
C
CMDK EFUR
C
C  FIND IEONL AND IEON
      IEONL=5
      IEON=5
      I=5
      DO 10 J=1  ,4
      I=I-1
      IF(TMON(I).GT.TCYCS)IEON=I
   10 IF(TMON(I).GT.TCYCSL)IEONL=I
C
C  SELECT INTERVAL ON SAME IEON'S
      DO 20 J=1,5
   20 IF(IEONL.EQ.J.AND.IEON.EQ.J)GO TO 30
      GO TO 40
C  INTERVAL WITH SAME IEON'S
   30 DTMS2=TCYCS-TCYCSL
      DTMS1=0.
      QIN1=0.
      GO TO 70
C  INTERVAL WITH CONSECUTIVE IEON'S
   40 IF(IEONL.EQ.1.AND.IEON.EQ.2)THEN
      DTMS1=0.
      QIN1=0.
      DTMS2=TCYCS-TMON(1)
      GO TO 70
      ENDIF
      DO 50 I=2,4
      IF(IEONL.EQ.I.AND.IEON.EQ.I+1)THEN
          DTMS1=TMON(I)-TCYCSL
          DTMS2=TCYCS-TMON(I)
          GO TO 60
          ENDIF
   50 CONTINUE
      WRITE(60,500)IEONL,IEON,TCYCSL,TCYCS
      STOP 'EFURON:TROUBLE WITH INTERVALS'
C  FIRST SEGMENT OF INTERVAL
   60 QIN1=3413.*XKWON(IEONL)
C  SECOND SEGMENT OF INTERVAL
   70 QIN2=3413.*XKWON(IEON)
C
C  INTEGRATED QIN
      QIN=(QIN1*DTMS1+QIN2*DTMS2)/(DTMS1+DTMS2)
      TA2=TA1+QIN*FACJAC/WACP
      RETURN
  500 FORMAT(1H0,'- - -OOPS,COULD NOT FIND IEON INTERVALS,'/
     +' IEONL,IEON= ',2I5,' TCYCSL,TCYCS= ',2G13.5)
      END
