      SUBROUTINE TVD
C
C  COMPUTE VEL HEAD LOSS COEF FOR THERMAL VENT DAMPER
C
CMDK BLK10
CMDK BLKTVD
C
C  POPEN     OPENING PERIOD,SEC
C  PCLOSE    CLOSING PERIOD,SEC
C  RCLOSE    VEL HEAD LOSS WITH TVD CLOSED
C  ROPEN     VEL HEAD LOSS WITH TVD OPEN
C  TCYCVD    CYCLE TIME FROM GAS VALVE ON OR OFF,HR
C  IBRNVD   =0  GAS VALVE OFF         =1  GAS VALVE ON
C
C
C-----THERMAL VENT DAMPER SUBMODEL
C              (SUPPLIES DIMENSIONLESS HEAD LOSS
C               COEFFICIENT AS A FUNCTION OF TIME
C               FOLLOWING FURNACE ON/OFF EVENTS.)
C
      DATA NJAN/120/,NTIM/120/
C  NRDF1 IS ZERO FOR FIRST CALL OF TVD
      IF(NRDF1.GT.0)GO TO 100
      POP=POPEN/3600.
      PCL=PCLOSE/3600.
      IBRNLS=0
      RLAST=RCLOSE
      AK1=(-1.)*ALOG(RCLOSE/ROPEN)/POP
      AK2=ALOG(RCLOSE/ROPEN)/PCL
      C1=1./ALOG(RCLOSE/ROPEN)
  100 IF(IBRNLS.LT.1.AND.IBRNVD.LT.1) GO TO 1450
      IF(IBRNLS.LT.1.AND.IBRNVD.GE.1) GO TO 1310
      IF(IBRNLS.GE.1.AND.IBRNVD.LT.1) GO TO 1320
      IF(IBRNLS.GE.1.AND.IBRNVD.GE.1) GO TO 1400
C  GAS VALVE WAS OFF AND IS NOW ON
 1310 IF(RLAST.NE.RCLOSE)THEN
C  TVD DIDNT CLOSE COMPLETELY BEFORE GAS VALVE CAME BACK ON
          DTM=POP*ALOG(RCLOSE/RLAST)*C1
          GO TO 1400
      ELSE
C   TVD CLOSED COMPLETELY BEFORE GAS VALVE CAME BACK ON
          DTM=0.
          GO TO 1400
      ENDIF
C   GAS VALVE WAS ON AND IS NOW OFF
 1320 IF(NTIM.LE.0)NJAN=0
      NTIM=1
      IF(RLAST.NE.ROPEN)THEN
C   TFD DIDNT OPEN COMPLETELY BEFORE GAS VALVE WENT OFF
          DTM=PCL*ALOG(RLAST/ROPEN)*C1
          GO TO 1450
      ELSE
C   TVD OPENED COMPLETELY BEFORE GAS GAVLE WENT OFF
          DTM=0.
          GO TO 1450
      ENDIF
C  GAS VALVE ON
 1400 DTIM=TCYCVD + DTM
      IF(DTIM.LE.POP)THEN
          R=RCLOSE*EXP(AK1*DTIM)
      ELSE
          R=ROPEN
      ENDIF
      GO TO 1500
C  GAS VALVE OFF
 1450 DTIM=TCYCVD + DTM
      IF(DTIM.LE.PCL)THEN
          R=ROPEN*EXP(AK2*DTIM)
      ELSE
          R=RCLOSE
      ENDIF
 1500 IBRNLS=IBRNVD
      RLAST=R
C   VHLTFD IS VEL HEAD LOSS FOR TFD
      VHLTVD=R
      NJAN=NJAN+1
      IF(NJAN.LT.100)WRITE(60,500)TCYCVD,IBRNVD,VHLTVD
  500 FORMAT(1X,'TCYCVD,IBRNVD,VHLTVD= ',F12.5,I5,F7.1)
      RETURN
      END
