function h = cbar(varargin)

%CBAR Display color bar (color scale) with contour levels.
%
%       This function generalizes COLORBAR.
%
%       CBAR('vert',clevs) appends a vertical color scale to the
%       current axis, with horizontal lines drawn at the values in CLEVS.
%
%       CBAR('horiz',clevs) appends a horizontal color scale to the
%       current axis, with vertical lines drawn at the values in CLEVS.
%
%       Additional arguments are used to modify the properties of the
%       colorbar axis, e.g. CBAR('horiz',clevs,'XScale','log') draws
%       a horizontal color bar with logarithmic scaling.
%
%       H = CBAR(...) returns a handle to the colorbar axis.
%
%       CBAR with fewer than 2 arguments simply calls COLORBAR.

%03Sep98 Dick Dee (dee@dao.gsfc.nasa.gov)

if nargin==0,

   hc = colorbar;

else,

   narg = length(varargin);

   if narg==1,

      hc = colorbar(varargin{1});

   else,

      orien = varargin{1};
      clevs = varargin{2};

      if ~isnumeric(clevs),
         help(mfilename)
         error([mfilename ': Invalid second argument.'])
      end

      switch orien

        case 'vert',

           caxis([clevs(1) clevs(end)])
           hc = colorbar('vert');
           set(hc,'GridLinestyle','-',...
                  'YGrid','on',...
                  'Ytick',clevs)

        case 'horiz',

           caxis([clevs(1) clevs(end)])
           hc = colorbar('horiz');
           set(hc,'GridLinestyle','-',...
                  'XGrid','on',...
                  'Xtick',clevs)

        otherwise,

           help(mfilename)
           error([mfilename ': Invalid first argument.'])

      end

      if narg>2,

         set(hc,varargin{3:end})

      end

   end

end

if nargout>0,

   h = hc;

end

