% Compare all indices to cable transport
%

% 
% first load cable data
%
load /Molly/work/data/cable/monthly_cable_transports.mat
% cable_monthly_date cable_monthly

monthly_cable_transport = gapfill (cable_monthly);

%
% get rid of Nans (will by definition be beginning and trailing Nans)
% because we just interpolated over interior gaps
%
LL=isnan(monthly_cable);
if length(LL) > 0
    monthly_cable_transport(LL) = [];
    cable_monthly_date(LL) = [];
end

d=dir('*.mat');

for II = 1: length(d)
    eval( ['load ' d(II).name] )
    L = find(d(II).name == '_');
    index_name = d(II).name(1:L(1)-1)
    eval(['new_' index_name ' = interp1 (' index_name '_date , ' index_name ' ,  cable_date);'])

%    figure
%    eval(['plot(' index_name '_date, ' index_name ')'])
%    hold on
%    datetick
%    eval(['plot(cable_date, new_' index_name ', ''k'')'])
%    title(index_name);
    %plot(cable_date, cable_transport)
    
    % get rid of beginning/trailing blanks
    % Note there are no Nans in Cable_transport
    temp_cable_transport = cable_transport;
    temp_cable_date = cable_date;
    eval(['LL = find(isnan(new_' index_name '));'])

    eval(['new_' index_name ' (LL) = [];'])
    temp_cable_transport(LL) = [];
    temp_cable_date(LL) = [];
    
    eval(['[max_ccx, max_lag] = check_corr4(new_' index_name ', temp_cable_transport, [''' index_name ' vs cable_transport''], ''days'', 900, 1)'])

end

%
%  Very interesting!
%  *many* indices are related to the FC transport.
%  I should do a ships type analysis to see if the FC transport can be
%  "predicted" by using some combination of these indices.
%  Those that need to be examoned include:
%   car lead cable by 284 days + corr
%   nta lags cable by 674 days + corr
%   aao lead cable by 204 days + corr
%   ammsst leads cable by 834 days + corr
%   amo lead cable by 364 days + corr
%   ao  lags cable by 426 and 713 days - corr
%   atltri leads cable by 753 days + corr
%   censo leads cable by 632 days - corr
%   espi leads cable by 618 days - corr
%   gmsst leads cable by 280 days + corr
%   hurr leads cable by 791 days + corr
%   mei leads cable by 609 days - corr
%   nao lags cable by 294 days - corr
%     and lags 865 days = corr
%   nina1 leads cable by 436 days - corr
%   nina3 leads cable by 471 days - corr
%   nina34 leads cable by 505 days - corr
%   nina4 lags cable by 145 days - corr
%   noi leads cable by 407 days + corr
%     and lags cable by 826 days - corr
%   np leads cable by 19 days + corr
%   pdo leads cable by 481 and 843 days - corr
%   qbo lags cable by 374 days - corr
%   sahelrain lags cable by 31 days + corr
%   soi leads cable 581-631 days + corr
%   swmonsoon leads cable by 278 days - corr
%   tna lags bu about 660 days and leads by 887 days + corr
%   tni lags cable by 550 days + corr
%   tsa leads cable by 259 days + corr

