function [T HE] = tempCalc(T0,w0,UA1,UA2,Th1in,wh1,...
                           Th2in,wh2,u)

w1 = u*w0;
w2 = (1-u)*w0;

NTU1 = UA1/w1;
NTU2 = UA2/w2;

C1 = w1/wh1;
C2 = w2/wh2;

if(C1>0.999 && C1<1.001)
    C1=0.999;
end

if(C2>0.999 && C2<1.001)
    C2=0.999;
end

e1 = (1-exp(-NTU1*(C1-1)))/(C1-exp(-NTU1*(C1-1)));
e2 = (1-exp(-NTU2*(C2-1)))/(C2-exp(-NTU2*(C2-1)));
eh1 = e1*C1;
eh2 = e2*C2;

T1  = e1*Th1in + (1-e1)*T0;
T2  = e2*Th2in + (1-e2)*T0;
Th1 = (1-eh1)*Th1in + eh1*T0;
Th2 = (1-eh2)*Th2in + eh2*T0;
Tmix = u*T1+(1-u)*T2;

T = [T1 T2 Th1 Th2 Tmix];
HE = [e1 eh1 e2 eh2 C1 C2 NTU1 NTU2];