load ~/NC/grid.mat
load ~/Aerosol_Variaiton/ERUN/SST/ncfile/ENSO_Month_10th.mat
load ~/Aerosol_Variaiton/ERUN/AOD/ncfile/AOD_monthly.mat
month=1:1800;

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

AOD_EN_month=zeros(144,96,a);
AOD_LL_month=zeros(144,96,b);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        AOD_EN_month(:,:,n)=AOD_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        AOD_LL_month(:,:,m)=AOD_MONTH(:,:,monthID);
    end
end

AOD_EN=mean(AOD_EN_month,3);
AOD_LL=mean(AOD_LL_month,3);

H=zeros(length(lon),length(lat));
for i=1:length(lon)
    for j=1:length(lat)
        H(i,j)=ttest2(AOD_EN_month(i,j,:),AOD_LL_month(i,j,:),0.05);
    end
end

AOD_ENSO=AOD_EN-AOD_LL;

save('AOD_ENSO_composite_monthly_10th.mat','AOD_EN','AOD_LL','AOD_ENSO')

nccreate('AOD_ENSO_composite_monthly_10th.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('AOD_ENSO_composite_monthly_10th.nc','lat', lat)
ncwriteatt('AOD_ENSO_composite_monthly_10th.nc','lat','units','degrees_north')
ncwriteatt('AOD_ENSO_composite_monthly_10th.nc','lat','long_name','Latitude')
nccreate('AOD_ENSO_composite_monthly_10th.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('AOD_ENSO_composite_monthly_10th.nc','lon', lon)
ncwriteatt('AOD_ENSO_composite_monthly_10th.nc','lon','units','degrees_east')
ncwriteatt('AOD_ENSO_composite_monthly_10th.nc','lon','long_name','Longitude')
nccreate('AOD_ENSO_composite_monthly_10th.nc','AOD_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('AOD_ENSO_composite_monthly_10th.nc','AOD_EN', AOD_EN)
nccreate('AOD_ENSO_composite_monthly_10th.nc','AOD_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('AOD_ENSO_composite_monthly_10th.nc','AOD_LL', AOD_LL)
nccreate('AOD_ENSO_composite_monthly_10th.nc','AOD_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('AOD_ENSO_composite_monthly_10th.nc','AOD_ENSO', AOD_ENSO)
nccreate('AOD_ENSO_composite_monthly_10th.nc','H','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('AOD_ENSO_composite_monthly_10th.nc','H', H)
ncdisp('AOD_ENSO_composite_monthly_10th.nc')
