function [out]=c_getchunk(x,y)
%C_GETCHUNK Select chunks of data
%   n = c_getchunk(x,y) get indices n of 
%   data x,y selecten interactively
%
%   to use, do:
%   1) n = c_getchunk(x,y) % this will generate a plot
%   2) you can zoom in, if you need to
%   3) press 'enter'
%   4) select the begining and end of 'bad period' (after second click,
%   data is highlighted). 
%   5) press enter, repeat 4
%   6) when done, press 'enter' twice.
%
%   the bad data are x(n), y(n)
%

% @ Carlos Moffat, 2005 (Distribute Freely!)

out=[];
plot(x,y,'b.-'); hold on
k=1;
while k~=0
    pause
    a=ginput(1);
    if ~isempty(a)
        n=find(x>a(1)); out2(k,1)=n(1);
        a=ginput(1);
        n=find(x<a(1)); out2(k,2)=n(end);
        out=[out; (out2(k,1):out2(k,2))'];
        plot(x(out2(k,1):out2(k,2)),y(out2(k,1):out2(k,2)),'r.-')
        k=k+1;
    else
        k=0;
    end
end




