function sl(ax)
% function sl(ax)
% "Scattering Layer" : using the mouse, select a region
% where the bottom flagging should be unset.
%     ax: (optional) [x0, x1, y0, y1] of region, in place of mouse selection
%

%editglob
global EDIT_MODE CURRX DISP YAXIS BOTTOM BOTTOM_BAK NBINS
global LASTCOMM LASTPLOT IBLKPRF DEPTH

if ~EDIT_MODE
  error('You are not in edit mode.  Set EDIT_MODE = 1 to enable.')
end

if isempty(CURRX)
  error('You must plot a variable first before running sl')
end

if nargin < 1
   if v4,
        disp('Click on upper left and bottom right corners to select region')
        [x y] = ginput(2);
        ax = [x(1) x(2) y(2) y(1)];
   else
      ax = mousebox;
   end
end

[pmin pmax bmin bmax] = inside1(CURRX+DISP, YAXIS, ax);
if ~isempty(pmax)
  BOTTOM_BAK = BOTTOM;
  BOTTOM(pmin:pmax) = NBINS * ones(1,pmax-pmin+1) + 1;
  LASTCOMM = 'bottom';
  eval(LASTPLOT)
  ibot = find(BOTTOM <= NBINS);
  Blk_Prf_Bin_Z_Gap = [IBLKPRF(ibot,1)'; IBLKPRF(ibot,2)'; abs(BOTTOM(ibot)); ...
                       DEPTH(NBINS * (ibot-1) + abs(BOTTOM(ibot))); diff([0 ibot])-1]
end


