function [DATA,Tcentralina] = centralina(IDcentralina,DTcatena,catena,datainiTuL,tempoiniTuL,...
    datainiRL,tempoiniRL,datainiTLH,tempoiniTLH,datainiTLHRH,tempoiniTLHRH,...
    datainiPCL,tempoiniPCL,datainiPCLHR,tempoiniPCLHR,datainiLL,tempoiniLL,datainiPrL,...
    tempoiniPrL,datainiEL,tempoiniEL,dataini3DEL,tempoini3DEL,datainiWEL,tempoiniWEL,...
    datainiCrL,tempoiniCrL,dataini3DCrL,tempoini3DCrL,datainiMPBEL,tempoiniMPBEL,conn)

%% Temperatura
% cerco la temperatura nel primo nodo
i = 1;
z = 0;
while z==0
    if cell2mat(catena(i,3)) == 1
        z = 1;
    else
        i = i+1; % nodo numero 1
    end
end
i = cell2mat(catena(i,1));
if i == 17
   dataini = datainiTuL;
   tempoini = tempoiniTuL;
elseif i == 21
       dataini = datainiPrL;
       tempoini = tempoiniPrL;
elseif i == 16
       dataini = datainiEL;
       tempoini = tempoiniEL;
elseif i == 19
       dataini = dataini3DEL;
       tempoini = tempoini3DEL;
elseif i == 23
       dataini = datainiPCL;
       tempoini = tempoiniPCL;
elseif i == 18
       dataini = datainiRL;
       tempoini = tempoiniRL;
elseif i == 11
       dataini = datainiTLH;
       tempoini = tempoiniTLH;
elseif i == 12
       dataini = datainiTLHRH;
       tempoini = tempoiniTLHRH;
elseif i == 15
       dataini = datainiLL;
       tempoini = tempoiniLL;
elseif i == 24
       dataini = datainiPCLHR;
       tempoini = tempoiniPCLHR;
elseif i == 22
       dataini = datainiWEL;
       tempoini = tempoiniWEL;
elseif i == 36
       dataini = datainiCrL;
       tempoini = tempoiniCrL;
elseif i == 37
       dataini = dataini3DCrL;
       tempoini = tempoini3DCrL;
elseif i == 25
       dataini = datainiMPBEL;
       tempoini = tempoiniMPBEL;
end
    
NodeNum = '1';
comando = ['select Date, Time, Temperature from RawDataView where Date = ''' ...
        dataini ''' and Time >= ''' tempoini ''' and  ToolNameID = ''' DTcatena...
        ''' and UnitName = ''' IDcentralina ''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
BatTempo = curs.Data;
comando = ['select Date, Time, Temperature from RawDataView where Date > ''' ...
        dataini ''' and  ToolNameID = ''' DTcatena...
        ''' and UnitName = ''' IDcentralina ''' and NodeNum = ''' NodeNum ''' '];
curs = exec(conn,comando);
curs = fetch(curs);
BatData = curs.Data;
if strcmp(char(BatData(1)),'No Data')
   Tcentralina = BatTempo;
elseif strcmp(char(BatTempo(1)),'No Data')
        Tcentralina = BatData;
else
    Tcentralina = [BatTempo;BatData];
end
% Modifico il formato di data e ora in DATini.
DAT = [BatTempo(:,1:2); BatData(:,1:2)];
[rD,~] = size(DAT);
T = [cell2mat(DAT(:,1)) repmat(' ', [rD,1]) cell2mat(DAT(:,2))];
T = datenum(T);
% Converto da Cell Array a Matrice.
DATA = T;

end