function [TimePL,ADCPiez,tempPiez,ErrPiezoLink] = defDatiPL(DatiPiezoLink,ErrPiezoLink,rPL,FileName)

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

[r,c]=size(DatiPiezoLink);
Ncorr = 0;
% Elimino gli eventuali Not a Number
for a = 2:r
    for b = 1:c
        check = isnan(DatiPiezoLink(a,b));
        if check == 1
            DatiPiezoLink(a,b) = DatiPiezoLink(a-1,b);
            ErrPiezoLink(a,b-1) = 1;
            Ncorr = Ncorr+1;
        end
    end
end

text = [num2str(Ncorr) ' NaN of Piezo Link corrected by defDatiPL function'];
fprintf(fileID,fmt,text);

% Definisco Data (gg:mm:aaaa hh:mm)ed i 2 dati 
% per il piezometro 
[r,c] = size(DatiPiezoLink);
TimePL = DatiPiezoLink(:,1); % data
ADCPiez = zeros(r,rPL);
tempPiez = zeros(r,rPL);
s = 1;
b = 2; % colonna del primo piezometro
while b <= c      
      ADCPiez(:,s) = DatiPiezoLink(:,b); % dati ADC piezometro
      tempPiez(:,s) = DatiPiezoLink(:,b+1); % dati temperatura ADC piezometro
      b = b+2;
      s = s+1;
end

text = 'Data of Piezo Link defined correctly. defDatiPL function ended';
fprintf(fileID,fmt,text);
fclose(fileID);

end