function Temp = get_Temperature(stage,t,states)
%[Temp] = get_Temperature(stage,t,states)
%returns the linear approximated Temperature for given
%Stage and time of the state matrix "states".
%Temp: Output of Temperature in matrix "time x stage"

%t (time): scalar or ":" for all

%init
global coldata NI
Temp=[];
section=zeros(1,size(stage,2));

%check if X is row vector, if yes: transform matrix and set time to "1"
if size(states,2)==1
    states=states';
    t=1;
end

%get number of section for each stage
for k=1:size(stage,2), %stage loop  
    for i=1:6,  %section loop
        if 2*sum(coldata.Nt(1:i))>=stage(k)
            section(k)=i;
            break
        end
    end
end

%calculate
for i=1:size(stage,2),%get single composition vector for stage i "t x [A B C]"
    composition=[states(t,stage(i)) states(t,stage(i)+coldata.Nt(section(i)))];
    composition=[composition 1-sum(composition,2)];
    %get single Temperature vector for stage i "t x Temp"
    Temp_stage = composition*[78.37 97 117.4]';
    %add Temp vector for stage i to prevoious stages
    Temp=[Temp Temp_stage];
end
