function y=surftplot(y1,fl1,y2,fl2,time,y3,fl3);
% y=surftplot(y1-y5,yy,mid,oi,varnum,fl1-fl5);
% call requires:
% y1-y5   = Variable arrays
% yy      = current year YYYY
% mid     = mooring id number
% oi      = upper(1) or lower(2);
% varnum  = temp(1),salt(2);
% fl1-fl5 = flag arrays
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
varnum=1;
y3=[time(:) y3(:)];
fpath=['/data/span9/bahr/perlprogs/'];
car=['m','g','b'];
% sym = symbol array [ circle, square, diamond]
sym=['o','s','d'];
yylim=[ 8 18];
eval(['load ',fpath,'mooringid.dat']);
eval(['mid=mooringid;']);
eval(['load ',fpath,'time.dat']);
eval(['gtime=time;']);
end_time=datenum(gtime(1),gtime(2),gtime(3),gtime(4),gtime(5),0);
maxylim=yylim(2);
minylim=yylim(1);
xma=-99;
xmi=1e32;
ylab=['Temperature (^o C)'];
cla reset;
figure('Visible','off','Position',[200 200 600 270]);
set(gcf,'Units','inches');
set(gcf,'PaperPosition',[1.5 1.5 8 6]);
hold on;
zid=0;
dt=[0.008 .021];
for j=1:3,
	eval(['jk=y',num2str(j),';']);
	if j < 3,
		dvt=dt(1);
		if (j==2)&(mid==2),
			dvt=0.0486;
		end
		if (j==2)&(mid==4),
			dvt=0.0486;
		end
	else,
		dvt=dt(2);
%		if (mid==3)|(mid==2),
			dvt=(2.5)/24;
%		end
	end
	if isempty(jk)==0,		
	clear ll; clear xtc; clear zzva;
	clear zc; clear iz; clear lq;
%# Set ll to good data
	eval(['ll=fl',num2str(j),'(:)==0;']);
%# Set lq to missing data.
	eval(['lq=fl',num2str(j),'(:)==3;']);
% Don't need to do the following since it is done.
%	eval(['xtc=ydtostr(yy,y',num2str(j),'(:,1));']);
	eval(['xtc=y',num2str(j),'(:,1);']);
	if (size(xtc(~lq),1) > 0),
		zid=1;
	end
	clear xtc;
%# compute the matlab datestring.
%	eval(['xtc=ydtostr(yy,y',num2str(j),'(:,1));']);
	eval(['xtc=y',num2str(j),'(:,1);']);
%# create temporary arrays to fill up...
	eval(['zzva=y',num2str(j),'(:,2);']);
	eval(['fc=fl',num2str(j),'(:);']);
	lx=size(xtc,1);
%# assume we have some data.
	if (lx > 0)&(zid > 0),
%# set up the initial values of the temporary arrays.
		zc=[xtc(1)];
		iz=[zzva(1)];
		fz=[fc(1)];
%# loop through the data looking for gaps.
		for i=1:lx-1,
			cx=xtc(i+1)-xtc(i);
			if cx > dvt,
				zc=[zc
			    	xtc(i+1)
			    	xtc(i+1)];
				iz=[iz
			    	NaN
			    	zzva(i+1)];
				fz=[fz
				    1
				    fc(i+1)];
			else,
				zc=[zc
			    	xtc(i+1)];
				iz=[iz
			    	zzva(i+1)];
				fz=[fz
				    fc(i+1)];
			end
		end
%# Overwrite the arrays and fill them with "gap filled data."
		xtc=zc;
		zzva=iz;
		fc=fz;
%# Set up the sepcial plotting arrays
		ygood=zzva;
		ybad=zzva;
		yoff=zzva;
%# Define good of gappy points
		ll=(fc==0);
%# Set all bad points in ygood to NaN
		ygood(~ll)=NaN;
%# Set all good points to NaN in ybad and yoff
		ybad(ll)=NaN;
		yoff(ll)=NaN;
%# Now find all points outside of plotting area
		lb=(ybad > maxylim)|(ybad < minylim)&(fc~=3);
%# Remove outside points from ybad and set those in yoff to max
%# ylimint.
		ybad(lb)=NaN;
		yoff(~lb)=NaN;
%# Find flags set to 3 missing values and set to NaN
		lmis=(fc==3);
		ybad(lmis)=NaN;
		yoff(lmis)=NaN;
%# Set nonplotting vlaues to maxylimit.
		yoff(lb)=maxylim-0.5+(j-1)*0.1;
		w1=min(xtc);
		w2=max(xtc);
		if xma < w2,
			xma=w2;
		end
		if xmi > w1,
			xmi=w1;
		end
		csym=[ car(j) sym(j)];
% plot good data
		plot(xtc,ygood,car(j));
		hold on
% plot bad data in black
		plot(xtc,ybad,'k');
% plot data out of bounds as colored symbol
		plot(xtc,yoff,csym);
		drawnow;
	end
	end
end
%if zid==0,
%	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,
% add in gap plotting...
%# Note: xmi and xma are determined above.
	xma=end_time;
	dxt=xma-xmi;
	set(gca,'XLimMode','manual');
	hold on;
	if (dxt < 7.0)|(dxt > 7.0),
		xmi=xma-7;
	end
	tiz=[floor(xmi):ceil(xma)];
	set(gca,'XTick',tiz);	
	datetick('x',6);
	set(gca,'XLim',[xmi xma]);
	set(gca,'YLim',[minylim maxylim]);
	grid on;
%end
xlabel(['Date (',num2str(gtime(1)),')'],'FontWeight','bold','FontSize',20);
ylabel(ylab(varnum,:),'FontWeight','bold','FontSize',20);
set(gca,'FontWeight','bold','FontSize',20);
set(gca,'Box','on');
	pltnm=['m',num2str(mid),'_multiT.ppm'];
eval(['print -dppm ',fpath,pltnm,';']);
clf;
close all;
%close;
%clf;
