function [yax,xax,npt,h]=ekw_get_xy(pcol,instructions)
%
% Call [yax,xax,h]=ekw_get_xy(pcol);
%
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
if nargin<1, pcol='m'; end
if nargin<2, instructions=[]; end
%
if ~isempty(instructions),
    disp(instructions);
else
    disp('Click on desired (x,y) points: <CR> to end, "n" or "N" to insert NaN, ');
    disp('   "x" or "X" to delete nearest point');
end
%
done=0; yax=NaN*ones(100,1); xax=yax; h=[]; npt=0; hold on;
while ~done,
    [d,t,button]=ginput(1);
    if isempty(button); done=1; break; end
    if button==110 | button==78,
        npt=npt+1; yax(npt)=NaN; xax(npt)=NaN;
    elseif button==120 | button==88,
        dist=(d-yax(1:npt)).^2 + (t-xax(1:npt)).^2; [dmin,iix]=min(dist);
        ii=[1:iix-1,iix+1:npt]; npt=npt-1; 
        yax(1:npt)=yax(ii); xax(1:npt)=xax(ii);
    else
        npt=npt+1; yax(npt)=d; xax(npt)=t;
    end
    if npt>1 & xax(npt)<xax(npt-1),
        [tsort,iisort]=sort(xax(1:npt));
        xax(1:npt)=xax(iisort); yax(1:npt)=yax(iisort);
    end
    if ~isempty(h), delete(h); end
    h=plot_cfill(yax(1:npt),xax(1:npt),'o',pcol,6,'-',1.75);
end
yax=yax(1:npt); xax=xax(1:npt);
