% %seasonal amplitufe trends
 clear all;close all;
 load('TAS_45_DEC_combined.mat', 'myear', 'syear', 'eyear', 'TAS', 'LAT', 'LON', 'MODELS')

NM = length(LAT);
clat=-87.5:2.5:87.5; CNN = length(clat); 
clon=0:2:360; CN=length(clon);
[CLON CLAT] = meshgrid(clon,clat);

for nm=1:NM;
    lat=LAT{nm};
    lon=LON{nm};
    tas=TAS{nm};
    [Lon Lat] = meshgrid([lon(end)-360 ; lon; lon(1)+360],lat);
    
    
    for mn=1:12;
        nm
        tic
        TAS_2100 = squeeze( tas(end,mn,:,:));
    ETAS_2100 = [TAS_2100(:,end) TAS_2100(:,:) TAS_2100(:,1)];
    CTAS_2100(nm,mn,1:CNN, 1:CN) = interp2(Lon, Lat, ETAS_2100 ,CLON, CLAT);
    
    
    TAS_2000 = squeeze( tas(1,mn,:,:));
    ETAS_2000 = [TAS_2000(:,end) TAS_2000(:,:) TAS_2000(:,1)];
    CTAS_2000(nm,mn,1:CNN, 1:CN) = interp2(Lon, Lat, ETAS_2000 ,CLON, CLAT);
    end
    [coef, phase] = fund2_3d(squeeze(CTAS_2100(nm,:,:,:)));
    SA_2100(nm,1:CNN, 1:CN) = coef;
    
    [coef, phase] = fund2_3d(squeeze(CTAS_2000(nm,:,:,:)));
    SA_2000(nm,1:CNN, 1:CN) = coef;
    
    toc
    
end


