load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/SST/ncfile/ENSO_Season.mat
load ~/Aerosol_Variaiton/IRUN/U10/ncfile/U10.mat
year=1:150;

a=sum(EN_SON);
b=sum(LL_SON);

U10_EN_SON=zeros(144,96,a);
U10_LL_SON=zeros(144,96,b);

n=0;
m=0;
for yearID=1:length(year)
    if EN_SON(yearID)==1
        n=n+1;
        U10_EN_SON(:,:,n)=U10_SON(:,:,yearID);
    end
    if LL_SON(yearID)==1
        m=m+1;
        U10_LL_SON(:,:,m)=U10_SON(:,:,yearID);
    end
end

U10_EN=mean(U10_EN_SON,3);
U10_LL=mean(U10_LL_SON,3);

U10_ENSO=U10_EN-U10_LL;

save('U10_ENSO_composite_monthly_SON.mat','U10_EN','U10_LL','U10_ENSO')

nccreate('U10_ENSO_composite_monthly_SON.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('U10_ENSO_composite_monthly_SON.nc','lat', lat)
ncwriteatt('U10_ENSO_composite_monthly_SON.nc','lat','units','degrees_north')
ncwriteatt('U10_ENSO_composite_monthly_SON.nc','lat','long_name','Latitude')
nccreate('U10_ENSO_composite_monthly_SON.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('U10_ENSO_composite_monthly_SON.nc','lon', lon)
ncwriteatt('U10_ENSO_composite_monthly_SON.nc','lon','units','degrees_east')
ncwriteatt('U10_ENSO_composite_monthly_SON.nc','lon','long_name','Longitude')
nccreate('U10_ENSO_composite_monthly_SON.nc','U10_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('U10_ENSO_composite_monthly_SON.nc','U10_EN', U10_EN)
nccreate('U10_ENSO_composite_monthly_SON.nc','U10_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('U10_ENSO_composite_monthly_SON.nc','U10_LL', U10_LL)
nccreate('U10_ENSO_composite_monthly_SON.nc','U10_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('U10_ENSO_composite_monthly_SON.nc','U10_ENSO', U10_ENSO)
ncdisp('U10_ENSO_composite_monthly_SON.nc')
