93 lines
3.0 KiB
Matlab
Executable File
93 lines
3.0 KiB
Matlab
Executable File
%% Funzione che elabora i Load Link
|
|
|
|
function [LoadDef,ErrLoadLink,ARRAYdateLL] = loadcell(LoadDef,ErrLoadLink,...
|
|
ARRAYdateLL,NuovoZeroLL,NdatiMedia,Ndatidespike,yesRSN,IDcentralina,DTcatena,FileName)
|
|
|
|
% Inizio del ciclo di elaborazione
|
|
text = 'loadcell function started';
|
|
fileID = fopen(FileName,'a');
|
|
fmt = '%s \r';
|
|
fprintf(fileID,fmt,text);
|
|
fclose(fileID);
|
|
|
|
if NuovoZeroLL == 1
|
|
if NdatiMedia > Ndatidespike
|
|
Ndati = NdatiMedia;
|
|
else
|
|
Ndati = Ndatidespike;
|
|
end
|
|
ini = round(Ndati/2)+1;
|
|
if rem(Ndati,2) == 0
|
|
ini = ini+1;
|
|
end
|
|
clear NDati
|
|
LoadDef = LoadDef(ini:end,:);
|
|
ARRAYdateLL = ARRAYdateLL(ini:end,1);
|
|
ErrLoadLink = ErrLoadLink(ini:end,:);
|
|
end
|
|
|
|
if yesRSN == 1 % filtro SOLO le celle connesse a un modulo BPM
|
|
newdata = 0; % n° dati filtrati
|
|
[rLL,cLL]=size(LoadDef);
|
|
CelleUpdate = ['' IDcentralina '-' DTcatena '-LoadCell.csv'];
|
|
if isfile(CelleUpdate) == 1
|
|
ValoriCelle = csvread(CelleUpdate);
|
|
ValoriCelle(:,1) = ValoriCelle(:,1) + 730000;
|
|
for n = 1:cLL % celle
|
|
for d = 1:rLL %date
|
|
if LoadDef(d,n) < -50 % kN
|
|
if d == 1
|
|
[~,cC] = size(ValoriCelle);
|
|
if cC ~= 1
|
|
LastData = find(ValoriCelle(:,1)<datenum(ARRAYdateLL(1,1)));
|
|
if isempty(LastData) == 0
|
|
LoadDef(d,n) = ValoriCelle(LastData(end),n+1);
|
|
ErrLoadLink(d,n) = 1;
|
|
newdata = newdata+1;
|
|
end
|
|
end
|
|
else
|
|
LoadDef(d,n) = LoadDef(d-1,n);
|
|
ErrLoadLink(d,n) = 1;
|
|
newdata = newdata + 1;
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
text = ['--- Load Link elaboration: ' num2str(newdata) ' data filtered. ---'];
|
|
fileID = fopen(FileName,'a');
|
|
fmt = '%s \r';
|
|
fprintf(fileID,fmt,text);
|
|
fclose(fileID);
|
|
|
|
if isempty(LoadDef) == 0 && isfile(CelleUpdate) == 1
|
|
Nuovedate = [ValoriCelle(:,1); ARRAYdateLL];
|
|
Nuovivalori = [ValoriCelle(:,2); LoadDef];
|
|
Nuovofile = [Nuovedate Nuovivalori];
|
|
elseif isempty(LoadDef) == 0
|
|
Nuovofile = [ARRAYdateLL LoadDef];
|
|
else
|
|
Nuovofile = [ValoriCelle(:,1) ValoriCelle(:,2)];
|
|
end
|
|
[rN,~] = size(Nuovofile);
|
|
% scrivo sul csv solo dati compresi al massimo nei 30 gg precedenti
|
|
Datimese = find(Nuovofile(:,1) < now-30);
|
|
if isempty(Datimese) == 0 && Datimese(end) ~= rN
|
|
Nuovofile = Nuovofile(Datimese(end)+1:end,:);
|
|
end
|
|
if isfile(CelleUpdate) == 1
|
|
delete(CelleUpdate);
|
|
end
|
|
Nuovofile(:,1) = Nuovofile(:,1) - 730000;
|
|
csvwrite(CelleUpdate,Nuovofile);
|
|
end
|
|
|
|
text = 'Load Link elaborated correctly';
|
|
fileID = fopen(FileName,'a');
|
|
fmt = '%s \r';
|
|
fprintf(fileID,fmt,text);
|
|
fclose(fileID);
|
|
|
|
end |