function xnew=trifilt(x,n)
%function xnew=trifilt(x,n)
%                     tri filter [0.25 0.5 0.25]
%                     the time base is maintained, and the points
%                     at the beginning and end are returned as their 
%                     original values.
good=find(x(:)~=NaN)';
lg=length(good);
filt=[0.25 0.5 0.25];
xg=conv(x(good),filt);
nbeg=2;
xg=xg(nbeg:nbeg-1+lg);
xg(1:nbeg-1)=ones(1,nbeg-1)*xg(nbeg);
xg(lg-nbeg+2:lg)=ones(1,nbeg-1)*xg(lg-nbeg+1);
xnew=ones(x)*nan;
xnew(good)=xg;

[nrow,ncol]=size(x);
if nrow>1
    xnew(1,:)=xnew(2,:);
    xnew(nrow,:)=xnew(nrow-1,:);
end
