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

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

SSLTSF1_EN_month=zeros(144,96,a);
SSLTSF1_LL_month=zeros(144,96,b);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        SSLTSF1_EN_month(:,:,n)=SSLTSF1_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        SSLTSF1_LL_month(:,:,m)=SSLTSF1_MONTH(:,:,monthID);
    end
end

SSLTSF1_EN=mean(SSLTSF1_EN_month,3);
SSLTSF1_LL=mean(SSLTSF1_LL_month,3);

SSLTSF1_ENSO=SSLTSF1_EN-SSLTSF1_LL;

SSLTSF1_ENSO(SSLTSF1_ENSO==0)=-999;


save('SSLTSF1_ENSO_composite_monthly.mat','SSLTSF1_EN','SSLTSF1_LL','SSLTSF1_ENSO')

nccreate('SSLTSF1_ENSO_composite_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('SSLTSF1_ENSO_composite_monthly.nc','lat', lat)
ncwriteatt('SSLTSF1_ENSO_composite_monthly.nc','lat','units','degrees_north')
ncwriteatt('SSLTSF1_ENSO_composite_monthly.nc','lat','long_name','Latitude')
nccreate('SSLTSF1_ENSO_composite_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('SSLTSF1_ENSO_composite_monthly.nc','lon', lon)
ncwriteatt('SSLTSF1_ENSO_composite_monthly.nc','lon','units','degrees_east')
ncwriteatt('SSLTSF1_ENSO_composite_monthly.nc','lon','long_name','Longitude')
nccreate('SSLTSF1_ENSO_composite_monthly.nc','SSLTSF1_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF1_ENSO_composite_monthly.nc','SSLTSF1_EN', SSLTSF1_EN)
nccreate('SSLTSF1_ENSO_composite_monthly.nc','SSLTSF1_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF1_ENSO_composite_monthly.nc','SSLTSF1_LL', SSLTSF1_LL)
nccreate('SSLTSF1_ENSO_composite_monthly.nc','SSLTSF1_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLTSF1_ENSO_composite_monthly.nc','SSLTSF1_ENSO', SSLTSF1_ENSO)
ncdisp('SSLTSF1_ENSO_composite_monthly.nc')
