%% Funzione che definisce i parametri specifici di elaborazione

function [NdatiMedia,Ndatidespike,MEMS,tolleranzaAcc,Tmax,Tmin,Ndevst,Wdevst,...
    Ndevst_HR,Wdevst_HR,NumBasi,elab_option,Calcolo_Carico,Area,Mod_Elastico,...
    Carico_Ini] = Parametri_Installazione(idTool,conn,yesTuL,yesRL,...
    yesTLH,yesTLHRH,yesPCL,yesPCLHR,yesMPBEL,yesWEL,yesEL,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));

%% MEMS
if yesTuL == 1 || yesTLH == 1 || yesRL == 1 || yesPCL == 1
   comando = ['select mems, toll_Acc, num_Ds, win_Ds from software where tool_id like ''' idTool ''' '];
   Dati = fetch(conn,comando);
   MEMS = cell2mat(Dati(1)); 
   tolleranzaAcc = cell2mat(Dati(2)); 
   Ndevst = cell2mat(Dati(3)); 
   Wdevst = cell2mat(Dati(4)); 
else
    MEMS = [];
    tolleranzaAcc = [];
    Ndevst = [];
    Wdevst = [];
end

%% Elettrolitici   
if yesTLHRH == 1 || yesPCLHR == 1
    comando = ['select num_Ds_HR, win_Ds_HR from software where tool_id like ''' idTool ''' '];
    Dati = fetch(conn,comando);
    Ndevst_HR = cell2mat(Dati(1));
    Wdevst_HR = cell2mat(Dati(2));
else
   Ndevst_HR = [];
   Wdevst_HR = [];
end

if yesTuL == 1 || yesTLH == 1 || yesRL == 1 || yesPCL == 1 || yesTLHRH == 1 || yesPCLHR == 1 || ...
        yesWEL == 1
    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));
else
    Tmax = [];
    Tmin = [];
end

if yesRL == 1 || yesTLH == 1 || yesPCL == 1
   comando = ['select orientation from software where tool_id like ''' idTool ''' '];
   Dati = fetch(conn,comando);
   elab_option = cell2mat(Dati(1));
else
    elab_option = [];
end

if yesEL == 1
    comando = ['select calcolo_carico, area, mod_elastico, carico_iniziale '...
        'from software where tool_id like ''' idTool ''' '];
    Dati = fetch(conn,comando);
    Calcolo_Carico = cell2mat(Dati(1));
    Area = cell2mat(Dati(2));
    Mod_Elastico = cell2mat(Dati(3));
    Carico_Ini = cell2mat(Dati(4));
else
    Calcolo_Carico = [];
    Area = [];
    Mod_Elastico = [];
    Carico_Ini = [];
end

if yesMPBEL == 1
   comando = ['select base_num from software where tool_id like ''' idTool ''' '];
   Dati = fetch(conn,comando);
   NumBasi = cell2mat(Dati(1));
else
    NumBasi = [];
end

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

end