function viewingadcp(mychoice)

global xhand adcp;

colordepth=100;
delt=24*mean(diff(adcp.time)); %hours
plotlength=ceil(72/delt); % only ploting 72 hrs of data at a time
midpoint=ceil(plotlength/2);
[m,n]=size(adcp.spd);
set(xhand.ensambleslide,'sliderstep',[1/m,1/plotlength]);

switch mychoice

case 1
	start=1+floor(m*get(xhand.ensambleslide,'value'));
	if start>=m-midpoint, start=m-midpoint; end;
	stop=start+plotlength-1;
	if stop>m, stop=m; end;
	pens=start+midpoint-1;
		
	axes(xhand.spdimage);
	maxspd=10*ceil(max(adcp.spd(start:stop,1:n-5))/10);
	maxspd=max(maxspd);
	if isnan(maxspd), maxspd=20; end;
	image(start:stop,1:n,adcp.spd(start:stop,:)' /(maxspd/colordepth),...
		'erasemode','xor',...
		'buttondownfcn','viewingadcp(2)');
	axis xy;
	ylabel('Bin #');
	hold on;
	adcp.spdmarker=plot([pens pens],[1 n],'w:','linewidth',2);
	hold off;

	% set(adcp.his,'cdata',adcp.spd(start:stop,:)','xdata',start:stop);
	hh=colorbar;
	set(hh,'ytick',20:20:100,'yticklabel',maxspd/colordepth*(20:20:100));
	hhh=get(hh,'title');
	set(hhh,'string','Speed','rotation',90,'pos',[-1 50 10]);

	axes(xhand.dirimage);
	image(start:stop,1:n,adcp.dir(start:stop,:)'/(360/colordepth),...
		'erasemode','xor',...
		'buttondownfcn','viewingadcp(2)');
	axis xy;
	ylabel('Bin #');
	pgreg=gregorian(adcp.time(start));
	pdate0=[num2str(pgreg(1)),'-',num2str(pgreg(2)),'-',num2str(pgreg(3))];
	pgreg=gregorian(adcp.time(stop));
	pdate1=[num2str(pgreg(1)),'-',num2str(pgreg(2)),'-',num2str(pgreg(3))];
	halfway=(start+stop)/2;
	halfwaystr='Click image to see a profile';
	set(gca,'xtick',[start halfway stop],'xticklabel',{pdate0 halfwaystr pdate1});
	hold on;
	adcp.dirmarker=plot([pens pens],[1 n],'w:','linewidth',2);
	hold off;
	hh=colorbar;
	set(hh,'ytick',[25 50 75 100],'yticklabel',[90 180 270 360]);
	hhh=get(hh,'title');
	set(hhh,'string','Direction','rotation',90,'pos',[-1 50 10]);
	
	if pens>=m, pens=m-1;end;
	axes(xhand.spdprofile);
	adcp.hps=plot(adcp.spd(pens,:),1:n,'bs');
% 	maxspd=10*ceil(max(adcp.spd(pens,1:n-5))/10);
	axis([0 maxspd 1 n]);
	set(gca,'xtick',[0 maxspd/2 maxspd],...
		'xgrid','on',...
		'xticklabel',[0 maxspd/2 maxspd]);
	xlabel('Speed');

	axes(xhand.dirprofile);
	adcp.hpd=plot(adcp.dir(pens,:),1:n,'rs');
	axis([0 360 1 n]);
	set(gca,'xtick',[0 90 180 270 360],...
		'xgrid','on',...
		'xticklabel',[0 90 180 270 360]);
	xlabel('Direction');

	pgreg=gregorian(adcp.time(pens));
	pdate=[num2str(pgreg(1)),'-',num2str(pgreg(2)),'-',num2str(pgreg(3))];
	ptime=[num2str(pgreg(4)),':',num2str(pgreg(5)),':',num2str(pgreg(6))];
	pens=num2str(pens);
	set(xhand.tstamp,'string',{['Ensamble: ' pens],['Date: ' pdate],['Time: ' ptime]});

case 2
	pens=get(gca,'currentpoint');
	pens=ceil(pens(1));
	set(adcp.spdmarker,'xdata',[pens pens]);
	set(adcp.dirmarker,'xdata',[pens pens]);
% 	axes(xhand.spdprofile);
% 	plot(adcp.spd(pens,:),1:n,'bs');
	set(adcp.hps,'xdata',adcp.spd(pens,:));
% 	maxspd=10*ceil(max(adcp.spd(pens,1:n-5))/10);
% 	axis([0 maxspd 1 n]);
% 	set(gca,'xtick',[0 maxspd/2 maxspd],'xticklabel',[0 maxspd/2 maxspd]);

set(adcp.hpd,'xdata',adcp.dir(pens,:));
	
	pgreg=gregorian(adcp.time(pens));
	pdate=[num2str(pgreg(1)),'-',num2str(pgreg(2)),'-',num2str(pgreg(3))];
	ptime=[num2str(pgreg(4)),':',num2str(pgreg(5)),':',num2str(pgreg(6))];
	pens=num2str(pens);
	set(xhand.tstamp,'string',{['Ensamble: ' pens],['Date: ' pdate],['Time: ' ptime]});

end;	
