load ~/NC/grid.mat
load ~/Aerosol_Variaiton/ERUN/SST/ncfile/ENSO_Month.mat
load ~/Aerosol_Variaiton/ERUN/CIR/ncfile/CIR_monthly.mat
month=1:1800;

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

UWND_EN_month=zeros(144,30,a);
UWND_LL_month=zeros(144,30,b);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        UWND_EN_month(:,:,n)=UWND_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        UWND_LL_month(:,:,m)=UWND_MONTH(:,:,monthID);
    end
end

UWND_EN=mean(UWND_EN_month,3);
UWND_LL=mean(UWND_LL_month,3);

UWND_ENSO=UWND_EN-UWND_LL;


OMEGA_EN_month=zeros(144,30,a);
OMEGA_LL_month=zeros(144,30,b);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        OMEGA_EN_month(:,:,n)=OMEGA_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        OMEGA_LL_month(:,:,m)=OMEGA_MONTH(:,:,monthID);
    end
end

OMEGA_EN=mean(OMEGA_EN_month,3);
OMEGA_LL=mean(OMEGA_LL_month,3);

OMEGA_ENSO=OMEGA_EN-OMEGA_LL;


save('CIR_ENSO_composite_monthly.mat','UWND_EN','UWND_LL','UWND_ENSO','OMEGA_EN','OMEGA_LL','OMEGA_ENSO')

nccreate('CIR_ENSO_composite_monthly.nc','lev','Dimensions',{'lev',30},'Format','classic')
ncwrite('CIR_ENSO_composite_monthly.nc','lev', lev)
nccreate('CIR_ENSO_composite_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('CIR_ENSO_composite_monthly.nc','lat', lat)
ncwriteatt('CIR_ENSO_composite_monthly.nc','lat','units','degrees_north')
ncwriteatt('CIR_ENSO_composite_monthly.nc','lat','long_name','Latitude')
nccreate('CIR_ENSO_composite_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('CIR_ENSO_composite_monthly.nc','lon', lon)
ncwriteatt('CIR_ENSO_composite_monthly.nc','lon','units','degrees_east')
ncwriteatt('CIR_ENSO_composite_monthly.nc','lon','long_name','Longitude')
nccreate('CIR_ENSO_composite_monthly.nc','UWND_EN','Dimensions',{'lon',144,'lev',30},'Format','classic')
ncwrite('CIR_ENSO_composite_monthly.nc','UWND_EN', UWND_EN)
nccreate('CIR_ENSO_composite_monthly.nc','UWND_LL','Dimensions',{'lon',144,'lev',30},'Format','classic')
ncwrite('CIR_ENSO_composite_monthly.nc','UWND_LL', UWND_LL)
nccreate('CIR_ENSO_composite_monthly.nc','UWND_ENSO','Dimensions',{'lon',144,'lev',30},'Format','classic')
ncwrite('CIR_ENSO_composite_monthly.nc','UWND_ENSO', UWND_ENSO)
nccreate('CIR_ENSO_composite_monthly.nc','OMEGA_EN','Dimensions',{'lon',144,'lev',30},'Format','classic')
ncwrite('CIR_ENSO_composite_monthly.nc','OMEGA_EN', OMEGA_EN)
nccreate('CIR_ENSO_composite_monthly.nc','OMEGA_LL','Dimensions',{'lon',144,'lev',30},'Format','classic')
ncwrite('CIR_ENSO_composite_monthly.nc','OMEGA_LL', OMEGA_LL)
nccreate('CIR_ENSO_composite_monthly.nc','OMEGA_ENSO','Dimensions',{'lon',144,'lev',30},'Format','classic')
ncwrite('CIR_ENSO_composite_monthly.nc','OMEGA_ENSO', OMEGA_ENSO)
ncdisp('CIR_ENSO_composite_monthly.nc')
