% Function frepeated
% Check for repeated data based on day of year vector, which must be sorted
% in ascending order.
% Written by Luciana Rizzo
%
% input: data (doy | values)
% col (data column number to check for consistency)
% output: newdata; erro
%
function [newdata,erro,linha] = frepeated(data,col)
aux=find(diff(data(:,1))==0);
aux1=diff(aux);
erro='none';
linha=0;
if(~isempty(aux))
jtarget=1;
for j=1:length(aux)
if(j<jtarget)
continue
end
if(j<=length(aux1))
if(aux1(j)==1) % mais de uma repeticao
conta=2;
for jj=1:10
if(aux1(j+jj)==1)
conta=conta+1; % conta o numero de repeticoes
else
break
end
end
jtarget=j+conta;
else
conta=1;
jtarget=j+1;
end
else
conta=0;
end
incons=zeros(1,conta);
for k=1:conta
if(data(aux(j)+k,col)~=data(aux(j),col))
incons(1,k)=1;
end
end
if(sum(incons)==0)
for k=1:conta
data(aux(j)+k,:)=zeros(1,size(data,2));
end
else
linha=aux(j);
erro=['Different concentrations registred at the same time stamp on line ',num2str(linha)];
newdata=[];
% disp('!!! Error: different concentrations registred at the same time stamp on lines:')
% disp(aux(j))
% for k=1:conta
% disp(aux(j)+k)
% end
return
end
end
end
aux2=find(data(:,1)==0);
data(aux2,:)=[]; % remove repeated data
newdata=data;
clear aux aux1 aux2 k j jj incons jtarget conta