year=2001:2016;

lat=-89.5:1:89.5;
lon=-179.5:1:179.5;

WIND_year=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/WIND/ncfile/WIND_NCEP_10th_2001_2016.nc','WIND_year');
AODBD=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/AODBD/ncfile/AODBD_MODIS_2001_2016.nc','AODBD_DJF');

AODBD_weak_temp=zeros(length(lon),length(lat));
n=0;
for yearID=1:length(year)
    if WIND_year(yearID)==1
        n=n+1;
        AODBD_weak_temp(:,:,n)=AODBD(:,:,yearID);
    end
end
AODBD_weak=mean(AODBD_weak_temp,3);

AODBD_aveg=mean(AODBD,3);
AODBD_diff=AODBD_weak-AODBD_aveg;

for i=1:length(lon)
    for j=1:length(lat)
        if AODBD_weak(i,j)<0
            AODBD_diff(i,j)=-999;
        end
        if AODBD_aveg(i,j)<0
            AODBD_diff(i,j)=-999;
        end
    end
end


save('AODBD_MODIS_10th.mat','AODBD_weak','AODBD_aveg','AODBD_diff')

nccreate('AODBD_MODIS_10th.nc','lat','Dimensions',{'lat',length(lat)},'Format','classic')
ncwrite('AODBD_MODIS_10th.nc','lat', lat)
ncwriteatt('AODBD_MODIS_10th.nc','lat','units','degrees_north')
ncwriteatt('AODBD_MODIS_10th.nc','lat','long_name','Latitude')
nccreate('AODBD_MODIS_10th.nc','lon','Dimensions',{'lon',length(lon)},'Format','classic')
ncwrite('AODBD_MODIS_10th.nc','lon', lon)
ncwriteatt('AODBD_MODIS_10th.nc','lon','units','degrees_east')
ncwriteatt('AODBD_MODIS_10th.nc','lon','long_name','Longitude')
nccreate('AODBD_MODIS_10th.nc','AODBD_weak','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('AODBD_MODIS_10th.nc','AODBD_weak', AODBD_weak)
nccreate('AODBD_MODIS_10th.nc','AODBD_aveg','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('AODBD_MODIS_10th.nc','AODBD_aveg', AODBD_aveg)
nccreate('AODBD_MODIS_10th.nc','AODBD_diff','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('AODBD_MODIS_10th.nc','AODBD_diff', AODBD_diff)
ncdisp('AODBD_MODIS_10th.nc')