function [u,v,t,fs]=dec_fil(files)
disp(['files have different time bases...decimating one'])
vars={'u1','v1','t1','u2','v2','t2'};
st=ncattr(files,'st');
[u1,v1,t1,T1]=ncload(files(1),'uvtT');
[u2,v2,t2,T2]=ncload(files(2),'uvtT');
if all(isnan(T1))
  dt=[1,1];
else
  dt=[T1(2)-T1(1),T2(2)-T2(1)];
end

for i=1:2
  if dt(i)>1
    dt=dt/(24*3600);
    eval(['T',int2str(i),'=T',int2str(i),'/(24*3600);']);
  end
end
T1=T1+st(1);T2=T2+st(2);

if rem(dt(2),dt(1))~=0&rem(dt(1),dt(2))~=0
  error('noncompatible time bases')
end

if dt(2)>dt(1)%first series needs to be filtered
  [var1,var2]=filt_sort([u1,v1,t1],T1,[u2,v2,t2],T2);
else
  [var2,var1]=filt_sort([u2,v2,t2],T2,[u1,v1,t1],T1);
end
l1=size(var1,1);l2=size(var2,1);
if l2>l1
  var1=[var1;NaN*ones(l2-l1,3)];
elseif l1>l2
  var2=[var2;NaN*ones(l1-l2,3)];
end
u=[var1(:,1),var2(:,1)];
v=[var1(:,2),var2(:,2)];
t=[var1(:,3),var2(:,3)];
fs=1/max(dt);


function [varn1,varn2]=filt_sort(var1,T1,var2,T2)
dt=[T1(2)-T1(1),T2(2)-T2(1)];
tim_dif=T2(1)-T1(1);
[b,a]=butter(2,dt(1)/dt(2));
uf=NaN*ones(size(var1));
for i=1:3
  isn=~isnan(var1(:,i));
  uf(isn,i)=filtfilt(b,a,var1(isn,i));
end
lf=size(uf,1);

if tim_dif>0%2nd series starts after 1st
  nst2=1;nst1=tim_dif/dt(1)+1;
else
  nst2=round(-tim_dif/dt(2)+1);nst1=round((T2(nst2)-T1(1))/dt(1)+1);
  tim_dif=T2(nst2)-T1(nst1);
  while tim_dif<0
    nst2=round(nst2-tim_dif/dt(2));nst1=round((T2(nst2)-T1(1))/dt(1)+1);
    tim_dif=T2(nst2)-T1(nst1);
  end
end
nsub=dt(2)/dt(1);
varn1=uf(nst1:nsub:end,:);
varn2=var2(nst2:end,:);
  
  
      
    
  

