function threshold(yesEL,ARRAYdate_EL,DatiExtensometer,NodoExtensometerLink,...
    yesCrL,ARRAYdate_CrL,DatiCrack,NodoCrackLink,...
    unitID,idTool,IDcentralina,DTcatena,conn,FileName)

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

% Scarico la data di riferimento
comando = ['select graph_prod_date from tools where unit_ID like ''' unitID ''' and name like ''' DTcatena ''' '];
data_ini = fetch(conn,comando);
stringa = cell2mat(data_ini);
[lS] = length(stringa);
if lS == 4  % Codice null - non c'è data di riferimento
    Riferimento = 0;
    dataRif = [];
    timeRif = [];
else
    Riferimento = 1;
    dataRif = stringa(1,1:10);
    timeRif = stringa(1,12:lS);
end

comando = ['select soglie from tools where unit_id like ''' ...
    unitID ''' and name like ''' DTcatena ''' '];

Soglie = fetch(conn,comando);
value = jsondecode(char(Soglie));
if isempty(value) == 0
    
    %% Extensometer Link
    if yesEL == 1
        threshold_ExtensometerLink(value,ARRAYdate_EL,DatiExtensometer,...
            Riferimento,dataRif,timeRif,NodoExtensometerLink,IDcentralina,DTcatena,idTool,conn,FileName);
    end
    
%     %% Crack Link
%     if yesCrL == 1
%         threshold_CrackLink(value,ARRAYdate_CrL,DatiCrack,...
%             Riferimento,dataRif,timeRif,NodoCrackLink,IDcentralina,DTcatena,conn,FileName);
%     end
end

fileID = fopen(FileName,'a');
fmt = '%s \r';
text = 'threshold function closed';
fprintf(fileID,fmt,text);
fclose(fileID);