% funzione che definisce i dati per la Cella di Carico, in particolare
% tempo (TimeMPBEL) e Dato (DatiMultiPointExtensometer)

function [TimeMPBEL,DatiMPBEL,DatiNTC_MPBEL,ErrMultiPointExtensometer] = ...
    defDatiMPBEL(DatiMultiPointExtensometer,DatiNTCMultiPointExtensometer,...
    ErrMultiPointExtensometer,FileName)

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

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

text = ['' num2str(Ncorr) ' NaN of Multi Point Extensometer Link corrected by defDatiMPBEL function'];
fprintf(fileID,fmt,text);

TimeMPBEL = DatiMultiPointExtensometer(:,1); % data
DatiMPBEL = DatiMultiPointExtensometer(:,2:end);
DatiNTC_MPBEL = DatiNTCMultiPointExtensometer(:,2:end);

text = 'Data of MultiPoint Borehole Rod Estensometer defined correctly. defDatiMPBEL function closed';
fprintf(fileID,fmt,text);
fclose(fileID);
end