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

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

SSLTSF2_EN_month=zeros(144,96,a);
SSLTSF2_LL_month=zeros(144,96,b);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        SSLTSF2_EN_month(:,:,n)=SSLTSF2_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        SSLTSF2_LL_month(:,:,m)=SSLTSF2_MONTH(:,:,monthID);
    end
end

SSLTSF2_EN=mean(SSLTSF2_EN_month,3);
SSLTSF2_LL=mean(SSLTSF2_LL_month,3);

SSLTSF2_ENSO=SSLTSF2_EN-SSLTSF2_LL;

SSLTSF2_ENSO(SSLTSF2_ENSO==0)=-999;


save('SSLTSF2_ENSO_composite_monthly.mat','SSLTSF2_EN','SSLTSF2_LL','SSLTSF2_ENSO')

nccreate('SSLTSF2_ENSO_composite_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('SSLTSF2_ENSO_composite_monthly.nc','lat', lat)
ncwriteatt('SSLTSF2_ENSO_composite_monthly.nc','lat','units','degrees_north')
ncwriteatt('SSLTSF2_ENSO_composite_monthly.nc','lat','long_name','Latitude')
nccreate('SSLTSF2_ENSO_composite_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('SSLTSF2_ENSO_composite_monthly.nc','lon', lon)
ncwriteatt('SSLTSF2_ENSO_composite_monthly.nc','lon','units','degrees_east')
ncwriteatt('SSLTSF2_ENSO_composite_monthly.nc','lon','long_name','Longitude')
nccreate('SSLTSF2_ENSO_composite_monthly.nc','SSLTSF2_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF2_ENSO_composite_monthly.nc','SSLTSF2_EN', SSLTSF2_EN)
nccreate('SSLTSF2_ENSO_composite_monthly.nc','SSLTSF2_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF2_ENSO_composite_monthly.nc','SSLTSF2_LL', SSLTSF2_LL)
nccreate('SSLTSF2_ENSO_composite_monthly.nc','SSLTSF2_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF2_ENSO_composite_monthly.nc','SSLTSF2_ENSO', SSLTSF2_ENSO)
ncdisp('SSLTSF2_ENSO_composite_monthly.nc')
