year=2003:2016;

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

WIND_year_temp=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/WIND/ncfile/WIND_NCEP_10th_2001_2016.nc','WIND_year');
WIND_year=WIND_year_temp(3:16);
AOD=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/AOD/ncfile/AOD_MODIS_Aqua_2003_2016.nc','AOD_coarse_DJF');

AOD_weak_temp=zeros(length(lon),length(lat));
n=0;
for yearID=1:length(year)
    if WIND_year(yearID)==1
        n=n+1;
        AOD_weak_temp(:,:,n)=AOD(:,:,yearID);
    end
end
AOD_weak=mean(AOD_weak_temp,3);

AOD_aveg=mean(AOD,3);
AOD_diff=AOD_weak-AOD_aveg;

for i=1:length(lon)
    for j=1:length(lat)
        if AOD_weak(i,j)<0
            AOD_diff(i,j)=-999;
        end
    end
end


save('AOD_MODIS_Aqua_10th.mat','AOD_weak','AOD_aveg','AOD_diff')

nccreate('AOD_MODIS_Aqua_10th.nc','lat','Dimensions',{'lat',length(lat)},'Format','classic')
ncwrite('AOD_MODIS_Aqua_10th.nc','lat', lat)
ncwriteatt('AOD_MODIS_Aqua_10th.nc','lat','units','degrees_north')
ncwriteatt('AOD_MODIS_Aqua_10th.nc','lat','long_name','Latitude')
nccreate('AOD_MODIS_Aqua_10th.nc','lon','Dimensions',{'lon',length(lon)},'Format','classic')
ncwrite('AOD_MODIS_Aqua_10th.nc','lon', lon)
ncwriteatt('AOD_MODIS_Aqua_10th.nc','lon','units','degrees_east')
ncwriteatt('AOD_MODIS_Aqua_10th.nc','lon','long_name','Longitude')
nccreate('AOD_MODIS_Aqua_10th.nc','AOD_weak','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('AOD_MODIS_Aqua_10th.nc','AOD_weak', AOD_weak)
nccreate('AOD_MODIS_Aqua_10th.nc','AOD_aveg','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('AOD_MODIS_Aqua_10th.nc','AOD_aveg', AOD_aveg)
nccreate('AOD_MODIS_Aqua_10th.nc','AOD_diff','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('AOD_MODIS_Aqua_10th.nc','AOD_diff', AOD_diff)
ncdisp('AOD_MODIS_Aqua_10th.nc')