function [unew,vnew]=tidesam2(ucoef,vcoef,tnew,fac);
%function [unew,vnew]=tidesam2(ucoef,vcoef,tnew,fac);
%         uses regression analysis (with mean, M2, M4 and M6) 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);
unew(i,:)=ucoef(i,1)*ones(tnew);
vnew(i,:)=vcoef(i,1)*ones(tnew);
for j=1:3
     unew(i,:)=unew(i,:)+real(fac(j)*(ucoef(i,j*2)+im*ucoef(i,j*2+1))*..
                                           exp(-im*freq(j)*tnew));
     vnew(i,:)=vnew(i,:)+real(fac(j)*(vcoef(i,j*2)+im*vcoef(i,j*2+1))*..
                                           exp(-im*freq(j)*tnew));
end
