function x=bridge(x,istart,m,mm,lx,ii)

% Identical to Joseph's UVTBR2

% Modified from a FORTRAN program by jpx on 7-15-99
global g;
lxtnd=abs(lx);

[g,p]=peflt(x,istart,m,mm);

switch ii
case 1
	g=g(:);
	g=flipud(g);
	jstart=istart+m;
	jend=jstart+lxtnd-1;
	k=jstart-mm;
	for j=jstart:jend
		dotprd=sum(x(k:k+mm-1).*g(1:mm));
		x(j)=dotprd;
		k=k+1;
	end;
case 2
	g=g(:);
	jstart=istart-1;
	jend=jstart-lxtnd+1;
	iflag=0;
	k=0;
	frac=0;
	jsave=0;
	for j=jstart:-1:jend
		k=k+1;
		dotprd=sum(x(j+1:j+mm).*g(1:mm));
		if ~isnan(x(j))
			if iflag==0
				iflag=1;
				jsave=j;
				if  lx<0
					dfrac=.333333333;
				else
					if lxtnd==1
						dfract=.5;
					else
						dfrac=1/(lxtnd-k+1);
					end;
				end;
			else
				frac=frac+dfrac;
			end;
			scrtch(k)=frac*x(j)+(1-frac)*dotprd;
		end;
		x(j)=dotprd;
	end;
	if jsave~=0
		k=jstart-jsave;
		for j=jsave:-1:jend
			k=k+1;
			x(j)=scrtch(k);
		end;
	end;
end;
				
return;	
