%% Funzione che definisce i parametri specifici di elaborazione

function [NdatiMedia,Ndatidespike,MEMS,tolleranzaAcc,pos_inst,Tmax,Tmin,SEL,...
    MEL] = Parametri_Installazione(yesRSN,yesRSNHR,yesDL,idTool,conn,FileName)

fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'Parametri_Installazione function started';
fprintf(fileID,fmt,text);

comando = ['select avg, despike from software where tool_id like ''' idTool ''' '];
Dati = fetch(conn,comando);

NdatiMedia = cell2mat(Dati(1));
Ndatidespike = cell2mat(Dati(2));

if yesRSN == 1 || yesRSNHR == 1 || yesDL == 1 
    %% Temperature 
    comando = ['select max_temp, min_temp from software where tool_id like ''' idTool ''' '];
    Dati = fetch(conn,comando);
    Tmax = cell2mat(Dati(1));
    Tmin = cell2mat(Dati(2));
    %% MEMS
    if yesRSN == 1 || yesDL == 1
       comando = ['select mems, toll_Acc, pos_inst, sel, mel from software where tool_id like ''' idTool ''' '];
       Dati = fetch(conn,comando);
       MEMS = cell2mat(Dati(1)); 
       tolleranzaAcc = cell2mat(Dati(2)); 
       pos_inst = cell2mat(Dati(3));
       SEL = cell2mat(Dati(4));
       MEL = cell2mat(Dati(5));
    else
        MEMS = [];
        tolleranzaAcc = [];
        pos_inst = [];
        SEL = [];
        MEL = [];
    end
else
    MEMS = [];
    tolleranzaAcc = [];
    Tmax = [];
    Tmin = [];
    pos_inst = [];
    SEL = [];
    MEL = [];
end 

text = 'Chain parameters defined correctly and Parametri_Installazione function ended';
fprintf(fileID,fmt,text);
fclose(fileID);
end