function n = clegend3(z,label,width)
%CLEGEND3 Plot color bar legend below a plot.
%
%	CLEGEND2(Z) produces a color bar legend with axis Z.
%	The matrix Z is used to determine the minimum and maximum axis 
%	labels for the color bar.  If Z is a vector then it is used directly
%	to generate the colors in the legend using PCOLOR(Z).  If Z is
%	a matrix then it is used only to determine the axis limits.  
%	Sixteen equally spaced color values between these extemes are 
%	then used as the color bar.  The look of the legend depends on the 
%	SHADING style in effect.
%
%	CLEGEND2 without the Z parameter uses default [0:16:256] color axis. 
%	CLEGEND2(Z,CLABEL) labels the axis of the color legend with the
%	string CLABEL.  CLEGEND2(Z,CLABEL,WIDTH) uses WIDTH to specify 
%	the fractional width of the main plot area.  The default width is 0.83

%	Clay M. Thompson  5-28-91
%	Copyright (c) 1991 by the MathWorks, Inc.
%       Fudged by me (RP) 9/jan/92 for beta 2, and again on 20/Mar/92 for 
%       beta 3.

if nargin==0, z = [0:16]/16; end
if nargin>=1, if isempty(z), z = [0:16]/16; end, end
if nargin<3, width = .83; end;


[m,n] = size(z);

if (m==1) | (n==1),
  z = z(:)';     % Make sure it is a row vector
  if (length(z)==2),
     z = z(1) + [0:16]*(z(2)-z(1))/16;
  end;
else
  zmin = min(z(z~=NaN));
  zmax = max(z(z~=NaN));
  z = zmin + [0:16]*(zmax-zmin)/16;   % Generate 17 equally spaced points
end

%   clf;
%   HH=axes('position',[.195 .15 .7 (1-width-.12)]);
   pcolor(z,[0 10]',[z;z]);
%   set(gca,'position',[.195 .15 .7 (1-width-.12)]);
   caxis([min(z) max(z)]); 
   shading('interp');
   if nargin>=2, xlabel(label), end
%   text(.1,-2.5,[ 'NMFS FOI ' date],'sc','fontsize',6);
%   set(gca,'tickdir','out','ticklength',[.15 1],'YTick',[]);
%    set(gca,'Xtick',z)
%    set(gca,'Ytick',[ ])
  % Set up subplot for main graph
  axes('position', [.12 (1-width+.15) .85 width-.23]);


