function [dtbest r2best trange r2range] = acs_findtimelag(a740, Temp, Time);


sizep = 100;
a740pad(1:sizep) = NaN;
a740pad(sizep+1:sizep+length(a740)) = a740;
a740pad(sizep+1+length(a740): sizep+1+length(a740)+sizep) = NaN;

for tt = 1:2*sizep+1
a740i = a740pad(tt+1:tt+length(a740));

[r p] = nancorrcoef_MMO(a740i, Temp);
rk(tt) = r(1,2).^2;

end

tlag = -sizep:sizep;

dt = diff(Time);
findmax = find(rk == max(rk));
dtbest = tlag(findmax).*dt(1);
r2best = max(rk);
r2range = rk;
trange = tlag.*dt(1);


