load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/SST/ncfile/ENSO_Month.mat
load ~/Aerosol_Variaiton/IRUN/TS/ncfile/TS_monthly.mat
month=1:1800;

TS_EN_month=zeros(144,96,180);
TS_LL_month=zeros(144,96,180);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        TS_EN_month(:,:,n)=TS_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        TS_LL_month(:,:,m)=TS_MONTH(:,:,monthID);
    end
end

TS_EN=mean(TS_EN_month,3);
TS_LL=mean(TS_LL_month,3);

H=zeros(144,96);
for i=1:144
    for j=1:96
        H(i,j)=ttest2(TS_EN_month(i,j,:),TS_LL_month(i,j,:),0.05);
    end
end

TS_ENSO=TS_EN-TS_LL;

save('TS_ENSO_composite_monthly.mat','TS_EN','TS_LL','TS_ENSO')

nccreate('TS_ENSO_composite_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('TS_ENSO_composite_monthly.nc','lat', lat)
ncwriteatt('TS_ENSO_composite_monthly.nc','lat','units','degrees_north')
ncwriteatt('TS_ENSO_composite_monthly.nc','lat','long_name','Latitude')
nccreate('TS_ENSO_composite_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('TS_ENSO_composite_monthly.nc','lon', lon)
ncwriteatt('TS_ENSO_composite_monthly.nc','lon','units','degrees_east')
ncwriteatt('TS_ENSO_composite_monthly.nc','lon','long_name','Longitude')
nccreate('TS_ENSO_composite_monthly.nc','TS_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('TS_ENSO_composite_monthly.nc','TS_EN', TS_EN)
nccreate('TS_ENSO_composite_monthly.nc','TS_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('TS_ENSO_composite_monthly.nc','TS_LL', TS_LL)
nccreate('TS_ENSO_composite_monthly.nc','TS_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('TS_ENSO_composite_monthly.nc','TS_ENSO', TS_ENSO)
nccreate('TS_ENSO_composite_monthly.nc','H','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('TS_ENSO_composite_monthly.nc','H', H)
ncdisp('TS_ENSO_composite_monthly.nc')
