% This script minimizes (T(t) - a C(t - tau))^2 by finding a and tau.
% It minimizes function LagError with Fmins.  It returns a variable ctdlag:
%    ctdlag(1) = optimum C
%    ctdlag(2) = optimum tau
%    ctdlag(3) = optimum C
% cc lag = -0.05788   % 3/22/99
% k = -0.12;    
% k = [-0.1335  6.2940  0.0644];                %  Best estimate... X9827017
k = [-0.58 7.4  0.060];  % Use default CC lag value of -0.05788

%
% J. G. Bellingham

ctdlag = fminsearch('LagModelError', k, [], data, m_present_time, water_temp, water_cond, m_pressure, lag_method);

