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

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

SSLTSF3_EN_month=zeros(144,96,a);
SSLTSF3_LL_month=zeros(144,96,b);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        SSLTSF3_EN_month(:,:,n)=SSLTSF3_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        SSLTSF3_LL_month(:,:,m)=SSLTSF3_MONTH(:,:,monthID);
    end
end

SSLTSF3_EN=mean(SSLTSF3_EN_month,3);
SSLTSF3_LL=mean(SSLTSF3_LL_month,3);

SSLTSF3_ENSO=SSLTSF3_EN-SSLTSF3_LL;

SSLTSF3_ENSO(SSLTSF3_ENSO==0)=-999;


save('SSLTSF3_ENSO_composite_monthly.mat','SSLTSF3_EN','SSLTSF3_LL','SSLTSF3_ENSO')

nccreate('SSLTSF3_ENSO_composite_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('SSLTSF3_ENSO_composite_monthly.nc','lat', lat)
ncwriteatt('SSLTSF3_ENSO_composite_monthly.nc','lat','units','degrees_north')
ncwriteatt('SSLTSF3_ENSO_composite_monthly.nc','lat','long_name','Latitude')
nccreate('SSLTSF3_ENSO_composite_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('SSLTSF3_ENSO_composite_monthly.nc','lon', lon)
ncwriteatt('SSLTSF3_ENSO_composite_monthly.nc','lon','units','degrees_east')
ncwriteatt('SSLTSF3_ENSO_composite_monthly.nc','lon','long_name','Longitude')
nccreate('SSLTSF3_ENSO_composite_monthly.nc','SSLTSF3_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF3_ENSO_composite_monthly.nc','SSLTSF3_EN', SSLTSF3_EN)
nccreate('SSLTSF3_ENSO_composite_monthly.nc','SSLTSF3_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF3_ENSO_composite_monthly.nc','SSLTSF3_LL', SSLTSF3_LL)
nccreate('SSLTSF3_ENSO_composite_monthly.nc','SSLTSF3_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF3_ENSO_composite_monthly.nc','SSLTSF3_ENSO', SSLTSF3_ENSO)
ncdisp('SSLTSF3_ENSO_composite_monthly.nc')
