% Funzione che definisce accelerazioni, dati magnetici, temperature, date e
% livello della batteria per i nodi di tipo Therm Link
function [TimePT100,val_PT100,ErrPT100Link] = defDatiPT100(DatiPT100Link,ErrPT100Link,FileName)

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

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

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

TimePT100 = DatiPT100Link(:,1); % data
val_PT100 = DatiPT100Link(:,2:end); % temperatura

text = 'Data of PT100 Link defined correctly. defDatiPT100 function closed';
fprintf(fileID,fmt,text);
fclose(fileID);

end
