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

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

AODSS_EN_month=zeros(144,96,a);
AODSS_LL_month=zeros(144,96,b);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        AODSS_EN_month(:,:,n)=AODSS_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        AODSS_LL_month(:,:,m)=AODSS_MONTH(:,:,monthID);
    end
end

AODSS_EN=mean(AODSS_EN_month,3);
AODSS_LL=mean(AODSS_LL_month,3);

AODSS_ENSO=AODSS_EN-AODSS_LL;

save('AODSS_ENSO_composite_monthly.mat','AODSS_EN','AODSS_LL','AODSS_ENSO')

nccreate('AODSS_ENSO_composite_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('AODSS_ENSO_composite_monthly.nc','lat', lat)
ncwriteatt('AODSS_ENSO_composite_monthly.nc','lat','units','degrees_north')
ncwriteatt('AODSS_ENSO_composite_monthly.nc','lat','long_name','Latitude')
nccreate('AODSS_ENSO_composite_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('AODSS_ENSO_composite_monthly.nc','lon', lon)
ncwriteatt('AODSS_ENSO_composite_monthly.nc','lon','units','degrees_east')
ncwriteatt('AODSS_ENSO_composite_monthly.nc','lon','long_name','Longitude')
nccreate('AODSS_ENSO_composite_monthly.nc','AODSS_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('AODSS_ENSO_composite_monthly.nc','AODSS_EN', AODSS_EN)
nccreate('AODSS_ENSO_composite_monthly.nc','AODSS_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('AODSS_ENSO_composite_monthly.nc','AODSS_LL', AODSS_LL)
nccreate('AODSS_ENSO_composite_monthly.nc','AODSS_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('AODSS_ENSO_composite_monthly.nc','AODSS_ENSO', AODSS_ENSO)
ncdisp('AODSS_ENSO_composite_monthly.nc')
