 % funzione che definisce i dati per il sensore analogico, in particolare
% tempo (TimeAL) e ADC (ADCAnalog)

function [TimeAL,ADCAnalog,ErrAnalogLink] = defDatiAL(DatiAnalogLink,ErrAnalogLink,FileName)

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

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

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

TimeAL = DatiAnalogLink(:,1); % data
ADCAnalog = zeros(r,c-1);

b = 2; % colonna del primo analog link    
ADCAnalog(:,:) = DatiAnalogLink(:,b:end); % dati ADC Analog Link

text = 'Data of Analog Link defined correctly. defDatiAL function closed';
fprintf(fileID,fmt,text);
fclose(fileID);
end
