function [tdoff,m]=click_doff_time(t,alpha,alpha2,drogue,W);

% click_doff_time
%
% Allow the user to
% click to the right of where he thinks the drogue 
% was lost to fit a line and extrapolate back to 
% find drogue off time.
 
if (ishold)
    plot_integrated_alpha(t,alpha,alpha2,drogue,W);
end;

t2=t-t(1);
y=cumsum(alpha)*median(diff(t2));

 

[i,j]=ginput(2);
if min(i)<max(t2)
    q=find(t2>i(1) & t2<i(2));
    [p,s]=polyfit(t2(q),y(q),1);
    % slope is nondimensional
    m=p(1);
    text(.1*max(t2),.9*max(y), ...
        ['slope: ',num2str(m,'%3.3f')],'fontsize',12);
     
    % find earliest time when resid=y-polyval(p,t2) is 
    % < standard deviation of resid in "drogue off" period,
    % and take that to be drogue off time
    resid=y-polyval(p,t2);
    q2=find(resid<std(resid(q))); 
    tdoff=t2(min(q2)); 
    %tdoff=-p(2)/p(1);
    
    hold on;
    xl=get(gca,'xlim'); yl=get(gca,'ylim');
    plot(t2,polyval(p,t2),'k');
    set(gca,'xlim',xl,'ylim',yl);
    plot([tdoff tdoff],ylim,'k','linewidth',2);
    hold off;
    q=find(t2>=tdoff);
    tdoff=t(q(1));  
else
    tdoff=NaN; m=NaN;
end;


