function [unew,vnew]=tidesam3(ucoef,vcoef,tnew,which);
%function [unew,vnew]=tidesam3(ucoef,vcoef,tnew,which);
%          Which is 2,4 or 6, to determine how many coefficients
%         uses regression analysis (with mean, M2, M4)  to generate
%		resampled timeseries using time array tnew;
[imax,jmax]=size(ucoef);
unew=[];
vnew=[];
period=[12.42 6.21 4.14];
freq=2*pi*ones(period)./period;
i=1:imax;
im=sqrt(-1);
%...........................................   put in mean
unew(i,:)=ucoef(i,1)*ones(tnew);
vnew(i,:)=vcoef(i,1)*ones(tnew);
%............................................  put in tide freqs
for j=1:which/2
     unew(i,:)=unew(i,:)+real((ucoef(i,j*2)+im*ucoef(i,j*2+1))*..
                                           exp(-im*freq(j)*tnew));
     vnew(i,:)=vnew(i,:)+real((vcoef(i,j*2)+im*vcoef(i,j*2+1))*..
                                           exp(-im*freq(j)*tnew));
end
