load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/SST/ncfile/ENSO_Month_10th.mat
load ~/Aerosol_Variaiton/IRUN/SST/ncfile/SST_monthly.mat
month=1:1800;

a=sum(EN_Month);
b=sum(LL_Month);

SST_EN_month=zeros(144,96,a);
SST_LL_month=zeros(144,96,b);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        SST_EN_month(:,:,n)=SST_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        SST_LL_month(:,:,m)=SST_MONTH(:,:,monthID);
    end
end

SST_EN=mean(SST_EN_month,3);
SST_LL=mean(SST_LL_month,3);


H=zeros(length(lon),length(lat));
for i=1:length(lon)
    for j=1:length(lat)
        H(i,j)=ttest2(SST_EN_month(i,j,:),SST_LL_month(i,j,:),0.05);
    end
end

SST_ENSO=SST_EN-SST_LL;
SST_ENSO(SST_EN==-999)=-999;
H(SST_EN==-999)=-999;


save('SST_ENSO_composite_monthly_10th.mat','SST_EN','SST_LL','SST_ENSO')

nccreate('SST_ENSO_composite_monthly_10th.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('SST_ENSO_composite_monthly_10th.nc','lat', lat)
ncwriteatt('SST_ENSO_composite_monthly_10th.nc','lat','units','degrees_north')
ncwriteatt('SST_ENSO_composite_monthly_10th.nc','lat','long_name','Latitude')
nccreate('SST_ENSO_composite_monthly_10th.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('SST_ENSO_composite_monthly_10th.nc','lon', lon)
ncwriteatt('SST_ENSO_composite_monthly_10th.nc','lon','units','degrees_east')
ncwriteatt('SST_ENSO_composite_monthly_10th.nc','lon','long_name','Longitude')
nccreate('SST_ENSO_composite_monthly_10th.nc','SST_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SST_ENSO_composite_monthly_10th.nc','SST_EN', SST_EN)
nccreate('SST_ENSO_composite_monthly_10th.nc','SST_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SST_ENSO_composite_monthly_10th.nc','SST_LL', SST_LL)
nccreate('SST_ENSO_composite_monthly_10th.nc','SST_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SST_ENSO_composite_monthly_10th.nc','SST_ENSO', SST_ENSO)
ncdisp('SST_ENSO_composite_monthly_10th.nc')
