function drawbar(x0, x1, y, color, textstring, option);

% drawbar(x0, x1, y, color, textstring, option);
%   Draws a bar from x0 to x1 centered at y.  
%
%   'color' and 'textstring' are optional.  Turn 'hold on;' after drawing 
%   the first bar.  The (optional) 'option' parameter positions 'textstring'
%   to the left, center, or right of the bar:
%     option < 0        xposition = left,   FontSize = -option
%     option < 100      xposition = center, FontSize =  option
%     option > 100      xposition = right,  FontSize =  option-100
%
%   Examples:
%     figure(1); clf;
%     drawbar(2, 3, 3)
%     hold on;
%     drawbar(3, 4, 2, 'r')
%     drawbar(4, 6, 1, 'g', 'September')
%     drawbar(5, 7, 6, 'b', 'October', -7)
%     drawbar(6, 9, 5, 'c', 'November', 7)
%     drawbar(7, 8, 4, [0.8,0.7,0], 'December', 107)
%     drawbar(0, 4, 4, [0.7,0.7,0.7], 'gray', 11)
%     drawbar(4, 6, 4, [0.5,0.5,0.5], 'gray', 11)

% 2024/03/08  Added more examples include RGB vector color (BB)
% 2000/02/15  Added option input parameter (BB)
% 2000/02/14  Written (BB)


%----- Init
deltaY = 0.4;     % bar height is 2*deltaY

%----- Input checking
if nargin <= 2,
   fprintf('Error: drawbar: Not enough input args\n');
   return;
end
if nargin <= 3,
   color = 'c';   % darker colors don't print well
end

%----- Main
fill([x0 x1 x1 x0], [y-deltaY y-deltaY y+deltaY y+deltaY], color);

if nargin == 5,
   text((x0+x1)/2, y, textstring, 'HorizontalAlignment','center', 'FontSize',9);
end

if nargin == 6,
   if option < 0
      %xpos = x0 - (x1-x0)/10;
      xpos = x0 * 1.00;
      text(xpos, y, textstring, 'HorizontalAlignment', 'right', ...
         'FontSize', -1 * option);
   elseif option < 100
      xpos = (x0+x1)/2;
      text(xpos, y, textstring, 'HorizontalAlignment', 'center', ...
         'FontSize', option);
   else
      %xpos = x1 + (x1-x0)/10;
      xpos = x1 * 1.00;
      text(xpos, y, textstring, 'HorizontalAlignment', 'left', ...
         'FontSize', option-100);
   end
end

