
%
% make mat files for all the cpc/esrl indeces
%

d=dir('*.data')

for II = 1: length(d)
    L = findstr(d(II).name, '.data')
    L0 = find(d(II).name == '.')
    L1 = find(d(II).name == '_')
    if isempty(L1)
        L1 = L0
    end
    index_name = d(II).name(1:L(1)-1)
    index_name = strrep(index_name,'.','_')
    shortname = d(II).name(1:L0(1)-1)
    old_filename = d(II).name
    new_filename = [index_name '.data.txt']
    eval(['!awk ''{if (NF == 13) {print $0} else {print "%" $0}}'' ' old_filename ' > ' new_filename])
    read_esrl_index2 (index_name)

    eval(['load ' index_name])
    % make smooth version of each
    eval( ['II = find(isnan(' index_name '));'] )
    eval( [index_name '(II) = [];'] )
    eval( [index_name '_date(II) = [];'] )
    eval( [shortname '_date = ' index_name '_date;'])
    eval( [index_name '_smooth_date = ' index_name '_date;'])
    eval( ['[' index_name '_butter_ann, ' index_name '_butter_bia, ' index_name '_butter_mos, ' index_name '_lp_ann, ' index_name '_lp_mos, ' index_name '_prolate_ann, ' index_name '_prolate_bia, ' index_name '_prolate_mos, ' index_name '_rmn_ann, ' index_name '_rmn_bia, ' index_name '_rmn_mos] = make_filtered_monthly_series (' index_name ''', ' index_name '_date'');'] )
    %eval( ['[' index_name '_smooth_butter_ann, ' index_name '_smooth_butter_bia, ' index_name '_smooth_butter_mos, ' index_name '_smooth_lp_ann, ' index_name '_smooth_lp_mos, ' index_name '_smooth_prolate_ann, ' index_name '_smooth_prolate_bia, ' index_name '_smooth_prolate_mos, ' index_name '_smooth_rmn_ann, ' index_name '_smooth_rmn_bia, ' index_name '_smooth_rmn_mos] = make_filtered_monthly_series (' index_name '_smooth'', ' index_name '_smooth_date'');'] )
    eval( ['save ' index_name '_smooth_filtered.mat ' index_name '_date ' index_name '* ' shortname '_date'] )
    eval( ['clear ' index_name '* ' shortname '* ' ' L old_filename new_filename II'] )
    close all
end


