% 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.1172    3.9582    0.0889]; 	%  Best estimate... X9827215
%
% J. G. Bellingham

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