CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C         INSULATED PIPE : CONSTANT HEAT EXCHANGE COEFFICIENT
C
C             PARAMETERS: PAR(1):HEAT EXCHANGE COEFFICIENT PER LENGTH
C                                UNIT XK
C                         PAR(2):PIPE LENGTH XL
C                         PAR(3):CP OF THE FLUID
C
C             INPUTS:     INP(1):SUPPLY TEMPERATURE  TSU
C                         INP(2):MASSFLOW RATE XM
C                         INP(3):AMBIENT TEMPERATURE TAMB
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C     SAMPLE INPUT AND OUTPUT VALUES
C
C     PARAMETERS                                       SAMPLE VALUES
C     PAR(1) AU'  Heat exchange coefficient per meter        .22
C     PAR(2) XL   Pipe length                               3.5
C     PAR(3) cp   Cp                                     4187.0
C
C     INPUTS
C     XIN(1) TSU  Supply Water Temperature                 68.65
C     XIN(2) dM   Water mass flow rate                      2.4
C     XIN(3) Tamb Ambient temperature                      15.0
C
C     OUTPUTS
C     OUT(1) Tex  Water exhaust temperature                68.65
C     OUT(2) dM   Water mass flow rate                      2.4
C     OUT(3) dQ   Heat exchange with the ambiance          15.0
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C

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

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

!DEC$ATTRIBUTES DLLEXPORT :: TYPE204

C
	DOUBLE PRECISION XIN, OUT
      DIMENSION XIN(3),PAR(3),OUT(3),INFO(10)
	COMMON/LUNITS/LUR,LUW,IFORM,LUK


!    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) CALL TYPECK(1,INFO,3,3,0)
C
C             INPUTS
C
      TSU=XIN(1)
      XM=XIN(2)
      TAMB=XIN(3)
C
C             PARAMETERS
C
      XK=PAR(1)
      XL=PAR(2)
      CP=PAR(3)
C
C             ARE XM AND XL GE 0?
C
      IF((XM.LT.0.0).OR.(XL.LT.0.0)) THEN
      WRITE(LUW,*)'MASSFLOW RATE OR PIPE LENGTH LOWER THAN 0 IN TYPE 69'
      CALL MYSTOP(1001)
	RETURN 1
      ENDIF
C
C             LOW MASSFLOW RATE
C
      IF(XM.LT.1E-5) THEN
      TEX=TAMB
      GO TO 10
      ENDIF
C
      AU=XL*XK
C
C             HEAT EXCHANGE VERY LOW
C
      IF(AU.LT.1E-5) THEN 
      TEX=TSU
      GO TO 10
      ENDIF
C
      PROV1=AU/XM/CP
      IF(PROV1.GT.20) THEN
      TEX=TAMB
      ELSE
      PROV=EXP(PROV1)
      TEX=(TSU-TAMB*(1-PROV))/PROV
      ENDIF
 10   Q=CP*(TSU-TEX)*XM
C
C             OUTPUTS
C
C        EXHAUST TEMPERATURE 
      OUT(1)=TEX      
C        MASSFLOW RATE
      OUT(2)=XM
C        HEAT EXCHANGE
      OUT(3)=Q
C
      RETURN 1
C
      END
