function [SPP,ARRAYdateSPP] = CalcoloSPP(DatiSPPLink,FileName)

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

[r,c]=size(DatiSPPLink);
Ncorr = 0;
% Elimino gli eventuali Not a Number
for a = 2:r
    for b = 1:c
        check = isnan(DatiSPPLink(a,b));
        if check == 1
            DatiSPPLink(a,b) = DatiSPPLink(a-1,b);
            Ncorr = Ncorr+1;
        end
    end
end
text = [num2str(Ncorr) ' NaN of SPP Link corrected by CalcoloSPP function'];
fprintf(fileID,fmt,text);

ARRAYdateSPP = DatiSPPLink(:,1); % data
val_SPP = DatiSPPLink(:,2:end); % dati presenza acqua
[r,c] = size(val_SPP );
SPP = zeros(r,c);
for ii = 1:r
    for jj = 1:c
        if val_SPP(ii,jj) >2.1 % V
            SPP(ii,jj) = 1; % Modificato 28/06/23
        end
    end
end

text = 'SPP sensor calculated correctly. CalcoloSPP function closed';
fprintf(fileID,fmt,text);
fclose(fileID);

end