function y=uvplot(adt,u,v,mid,flu,flv,yy);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Function routine to try and get around an
% annoying bug in the batch processing of
% plots from a scripts.  The xaxis keeps
% changing from plot to plot.  Try to 
% isolate things in this file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
velmin=-50; velmax=50;
cr=['r','b','g','y','m','c'];
dte=0.021;	% 30 minutes (may need to change to 1hr)
%if (mid==3)|(mid==2),
	dte=2.5/24;
%end
fpath=['/data/span9/bahr/perlprogs/'];
eval(['load ',fpath,'time.dat']);
eval(['gtime=time;']);
% Datetick bug use Year Day instead of datenum
%end_time=cal2yearday(gtime(1),gtime(2),gtime(3),gtime(4),gtime(5),0);
 end_time=datenum(gtime(1),gtime(2),gtime(3),gtime(4),gtime(5),0);
	lu=size(u,1);
	wu=size(u,2);
	cla reset;
	figure('Visible','off','Position',[200 200 650 600]);
	set(gcf,'Units','inches');
	set(gcf,'PaperPosition',[1.5 1.5 9 6.5]);
	clear ll;
	if isempty(u)==1,
		xfil=[0 1 1 0];
		yfil=[0 0 1 1];
		plot(xfil,yfil);
		axis([0 1 0 1]);
		text(0.4,0.5,'NO DATA','FontWeight','bold','FontSize',20);
	else,
% Need to find time gaps........
% First compute matlab datenum
% don't compute datenums because of bug!
%	xtc=adt;
	xtc=ydtostr(yy,adt);
% next get size of arrays
	lx=size(xtc,1);
	uu=size(u,2);
% start temp arrays with first value
	zc=[xtc(1)];
	iuz=[u(1,:)];
	ivz=[v(1,:)];
	ffu=[flu(1,:)];
	ffv=[flv(1,:)];
	for i=1:lx-1,
		cx=xtc(i+1)-xtc(i);
		if cx > dte,
			zc=[zc
			    xtc(i+1)
			    xtc(i+1)];
			ffu=[ffu
			    ones(1,uu)
			    flu(i+1,:)];
			ffv=[ffv
			    ones(1,uu)
			    flv(i+1,:)];
			iuz=[iuz
			    ones(1,uu).*NaN
			     u(i+1,:)];
			ivz=[ivz
			     ones(1,uu).*NaN
			     v(i+1,:)];
		else,
			zc=[zc
			    xtc(i+1)];
			ffu=[ffu
			    flu(i+1,:)];
			ffv=[ffv
			    flv(i+1,:)];
			iuz=[iuz
			     u(i+1,:)];
			ivz=[ivz
			     v(i+1,:)];
		end
	end
	adt=zc;
	flu=ffu;
	flv=ffv;
	u=iuz;
	v=ivz;
% Add code to plot gaps as gaps
	nu=flu==3;
	nv=flv==3;
% First set missing data values to NaN's
	u(nu)=NaN;
	v(nv)=NaN;
% Temperoary set up on flags....
	tu=u==-3276.8;
	tv=v==-3276.8;
	flu(tu)=1;
	flv(tv)=1;
	ugood=u;
	vgood=v;
	ubad=u;
	vbad=v;
	uoff=u;
	voff=v;
% set good values 
	gu=flu==0;
	ugood(~gu)=NaN;
	ubad(gu)=NaN;
	uoff(gu)=NaN;
	gv=flv==0;
	vgood(~gv)=NaN;
	vbad(gv)=NaN;
	voff(gv)=NaN;
% Find values that plot outside of plotting bounds
	ou=((ubad > velmax)|(ubad < velmin));
	ov=((vbad > velmax)|(vbad < velmin));
	ubad(ou)=NaN;
	uoff(~ou)=NaN;
	vbad(ov)=NaN;
	voff(~ov)=NaN;
% Now set off plot values to plot as symbols at edge of plot
	voff(ov)=velmin+2;
	uoff(ou)=velmax-2;
% set up x-axis time limits
	xmi=min(xtc);
	xma=end_time;
	dxt=xma-xmi;
	if dxt < 7.0,
		xmi=xma-7;
	end
	tiz=[floor(xmi):ceil(xma)];
	if length(tiz) > 7,
		tiz(1)=[];
	end
% Now to actually plot the time-seris
	subplot(2,1,1);
	lil=size(u,2);
	if lil > 30,
		lil=30;
	end
	ic=6;
	for i=lil:-1:1,
		switch(i)
			case 5,
				ic=1;
			case 10,
				ic=2;
			case 15,
				ic=3;
			case 20,
				ic=4;
			case 25,
				ic=5;
			case 30,
				ic=6;
		end
		plot(adt(:),ugood(:,i),cr(ic));
		hold on;
	end
	plot(adt,ubad,'k');
	plot(adt,uoff,'b^');
	set(gca,'XLimMode','manual');
	set(gca,'XTick',tiz);
	grid on
	ylabel(['U-Velocity (cm/s)'],'FontWeight','bold','FontSize',20);
	xlabel(['Year Day (',num2str(yy),')'],'FontWeight','bold','FontSize',20);
	set(gca,'FontWeight','bold','FontSize',20);
	datetick('x',6);
	set(gca,'Xlim',[xmi xma]);
	set(gca,'Ylim',[velmin velmax]);
% add second plot
	subplot(2,1,2);
	ic=6;
	for i=lil:-1:1,
		switch(i)
			case 5,
				ic=1;
			case 10,
				ic=2;
			case 15,
				ic=3;
			case 20,
				ic=4;
			case 25,
				ic=5;
			case 30,
				ic=6;
		end
		plot(adt(:),vgood(:,i),cr(ic));
		hold on;
	end
	plot(adt,vbad,'k');
	plot(adt,voff,'bv');
	set(gca,'XLimMode','manual');
	set(gca,'XTick',tiz);
	grid on;
	end
	ylabel(['V-Velocity (cm/s)'],'FontWeight','bold','FontSize',20);
	xlabel(['Year Day (',num2str(yy),')'],'FontWeight','bold','FontSize',20);
	set(gca,'FontWeight','bold','FontSize',20);
	datetick('x',6);
	set(gca,'Ylim',[velmin velmax]);
	set(gca,'Xlim',[xmi xma]);
	pltnm=[fpath,'m',num2str(mid),'_uvplot.ppm'];
	eval(['print -dppm ',pltnm,';']);
	clf;
	close all;
