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

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

VWND_EN_month=zeros(144,96,a);
VWND_LL_month=zeros(144,96,b);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        VWND_EN_month(:,:,n)=VWND_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        VWND_LL_month(:,:,m)=VWND_MONTH(:,:,monthID);
    end
end

VWND_EN=mean(VWND_EN_month,3);
VWND_LL=mean(VWND_LL_month,3);

VWND_ENSO=VWND_EN-VWND_LL;


save('VWND_ENSO_composite_monthly.mat','VWND_EN','VWND_LL','VWND_ENSO')

nccreate('VWND_ENSO_composite_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('VWND_ENSO_composite_monthly.nc','lat', lat)
ncwriteatt('VWND_ENSO_composite_monthly.nc','lat','units','degrees_north')
ncwriteatt('VWND_ENSO_composite_monthly.nc','lat','long_name','Latitude')
nccreate('VWND_ENSO_composite_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('VWND_ENSO_composite_monthly.nc','lon', lon)
ncwriteatt('VWND_ENSO_composite_monthly.nc','lon','units','degrees_east')
ncwriteatt('VWND_ENSO_composite_monthly.nc','lon','long_name','Longitude')
nccreate('VWND_ENSO_composite_monthly.nc','VWND_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('VWND_ENSO_composite_monthly.nc','VWND_EN', VWND_EN)
nccreate('VWND_ENSO_composite_monthly.nc','VWND_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('VWND_ENSO_composite_monthly.nc','VWND_LL', VWND_LL)
nccreate('VWND_ENSO_composite_monthly.nc','VWND_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('VWND_ENSO_composite_monthly.nc','VWND_ENSO', VWND_ENSO)
ncdisp('VWND_ENSO_composite_monthly.nc')
