load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/SST/ncfile/ENSO_Month_ECMWF_1979_2014.mat
load ~/Aerosol_Variaiton/IRUN/CIR/ncfile/CIR_monthly_ECMWF.mat
lat=-89.5:2.5:89.5;
lon=0:2.5:357.5;
lev=[0.2,0.3843,0.6365,0.9564,1.3448,1.8058,2.3478,2.985,3.7397,4.6462,5.7565,7.1322,8.8366,10.9483,13.5647,16.8064,20.8227,25.7989,31.9642,39.6029,49.0671,60.1802,73.0663,87.7274,104.2288,122.6137,142.9017,165.0886,189.1466,215.0251,242.6523,272.0593,303.2174,336.0439,370.4072,406.1328,443.0086,480.7907,519.2093,557.9734,596.7774,635.306,673.2403,710.2627,746.0635,780.3455,812.8303,843.2634,871.4203,897.1118,920.1893,940.5511,958.1477,972.9868,985.1399,994.7472,1002.0236,1007.2639,1010.8487,1013.25];
year=1:36;
month=1:432;


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

UWND_EN_month=zeros(length(lon),length(lev),a);
UWND_LL_month=zeros(length(lon),length(lev),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(length(lon),length(lev),a);
OMEGA_LL_month=zeros(length(lon),length(lev),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_ECMWF.mat','UWND_EN','UWND_LL','UWND_ENSO','OMEGA_EN','OMEGA_LL','OMEGA_ENSO')

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