% Funzione che definisce accelerazioni, dati magnetici, temperature, date e
% livello della batteria per i nodi di tipo Weir Link
function [TimeWL,lev_WL,temp_WL,ErrWeirLink] = defDatiWL(DatiWeirLink,...
    DatiNTCWeirLink,ErrWeirLink,FileName)

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

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

TimeWL = DatiWeirLink(:,1); % data
lev_WL = DatiWeirLink(:,2:end);
temp_WL = DatiNTCWeirLink(:,2:end);

text = 'Data of Weir Link defined correctly, defDatiWL function closed';
fprintf(fileID,fmt,text);
fclose(fileID);

end
