year=2001:2014;
lat=-89.5:1:89.5;
lon=-179.5:1:179.5;

WIND=ncread('/Users/yangyang/Aerosol_Variaiton/MODIS/ncfile/WIND_ECMWF.nc','VWND_DJF');
AOD=ncread('/Users/yangyang/Aerosol_Variaiton/MODIS/ncfile/AOD_MODIS.nc','AOD_DJF');



corr=zeros(length(lon),length(lat));

for i=1:length(lon)
    for j=1:length(lat)
        r=corrcoef(WIND(i,j,:),AOD(i,j,:));
        corr(i,j)=r(1,2);
        if sum(AOD(i,j,:))<0
            corr(i,j)=-999;
        end
    end
end


corr(isnan(corr))=-999;

save('corr_AOD_VWND.mat','corr')

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