  function [a,b] = BWindow(x,y,foundRoots, message) 
% x and y are row vectors having length n.
% The components of x satisfy x(1) < ... < x(n)
% foundRoots is a row m-vector, possibly empty.
% Message is a string. 
% After closing all figures, this function opens up a new figure
% and
%       (a) Draws a bisection window based on x and y.
%       (b) Plots y versus x and the points (foundRoots(k),0), k=1:m.
%       (c) Solicits a mouseclick.
%       (d) Returns the x and y coordinates of the mouseclick in a and b.

  close all
  figure
  
% Make the figure window big
  set(gcf,'position',[100 100 800 600])

% Compute important and x and y-values...
  n = length(x);
  xMin = x(1); 
  xMax = x(n); 
  dx = x(n)-x(1); 
  delx = dx/20;
  L = xMin + dx/4;
  R = xMax - dx/4;
  yMax = max(abs(y));
  yMin = -yMax; 
  dy = yMax-yMin; 
  dely = dy/20;
  title({message, sprintf('L =%10.6f   R = %10.6f', L,R)},'Fontsize',14) 
  
% Set the axis ranges, establish and label the ticks
  axis([xMin-delx xMax+delx yMin-dely yMax+dely])
  set(gca,'xTick',[xMin L  R xMax])
  set(gca,'xTickLabel',{'xMin','L','R','xMax'},'Fontsize',14)
  set(gca,'yTick',[yMin yMax]) 
  set(gca,'yTickLabel',{'yMin','yMax'},'Fontsize',14)
  grid on
  
% Add in the bisection click box and the x-axis
  hold on
  axis manual
  DrawRect(L,yMin-dely,R-L,dely,'b')
  plot([xMin L],[0 0],'r','linewidth',3);
  plot([L R],[0 0],'g','linewidth',5);
  plot([R xMax],[0 0],'r','linewidth',3);
  
% Plot y vs x and foundroots
  plot(x,y,'k')
  for k=1:length(foundRoots)
     plot(foundRoots(k),0,'.k','Markersize',20)
  end
  
  v = [xMin-delx xMax+delx yMin-dely yMax+dely];
  plot([v(1) v(2) v(2) v(1) v(1)],[v(3) v(3) v(4) v(4) v(3)],'k','linewidth',5)

% The mouseclick...
  [a,b] = ginput(1);

