CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C                  THERMAL CAPACITANCE
C
C             INPUTS : 1 : SUPPLY TEMPERATURE
C                      2 : MASSFLOW RATE
C
C             PARAMETERS : 1 : THERMAL CAPACITANCE
C                          2 : CP
C
C             OUTPUTS : 1 : CAPACITANCE TEMPERATURE 
C                       2 : MASSFLOW RATE
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C     SAMPLE INPUT AND OUTPUT VALUES
C
C     PARAMETERS                          SAMPLE VALUES
C     PAR(1) THERMAL CAPACITANCE               14800.0
C     PAR(2) CP                                 4187.0
C
C     INPUTS
C     XIN(1) Water supply temperature             68.0
C     XIN(2) Water mass flow rate                  2.4
C
C     OUTPUTS
C     OUT(1) Exhaust temperature                  68.0
C     OUT(2) Water mass flow rate                  0.15
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

!  This component has been assigned Type Number 202. If that number conflicts with 
!  another user Type number, you will need to change it and recompile the appropriate
!  dll.

      SUBROUTINE TYPE202(TIME,XIN,OUT,T,DTDT,PAR,INFO,ICNTRL,*)

!DEC$ATTRIBUTES DLLEXPORT :: TYPE202



      DIMENSION XIN(2),OUT(3),INFO(15),PAR(2)

!    Set the version information for TRNSYS
      IF (INFO(7).EQ.-2) THEN
	  INFO(12) = 15
	  RETURN 1
	ENDIF


C
C             FIRST CALL
C
      IF(INFO(7).EQ.-1) THEN
      CALL TYPECK(1,INFO,2,2,0)
      OUT(3)=XIN(1)
      ENDIF
C
C             TEMPERATURE LAST TIME STEP
C
      IF(INFO(7).EQ.0) OUT(3)=OUT(1)
C
C             INPUTS
C
      TSU=XIN(1)
      XM=XIN(2)
C
C             PARAMETERS 
C
      C=PAR(1)
      CP=PAR(2)
C
C             IS THE CAPACITANCE EQ. TO 0 ?
C
      IF(C.EQ.0.0) THEN
      OUT(1)=TSU
      GOTO 100
      ENDIF
C   
C             THE CAPACITANCE TEMPERATURE IS CALCULATED USING DIFFEQ       
C
C             COEFFICIENTS CALCULATION
C
      AA=-XM*CP/C
      BB=XM*CP/C*TSU
      TI=OUT(3)
      CALL DIFFEQ(TIME,AA,BB,TI,TF,TBAR)
C
C             OUTPUTS
C
      OUT(1)=TBAR
 100  OUT(2)=XM
      RETURN 1
      END   

