year=1978:1992;

lon=ncread('/Users/yangyang/Aerosol_Variaiton/TOMS/dat/TOMS_Aerosol_Index_12_1978_1992.nc','lon');
lat=ncread('/Users/yangyang/Aerosol_Variaiton/TOMS/dat/TOMS_Aerosol_Index_12_1978_1992.nc','lat');
AI=ncread('/Users/yangyang/Aerosol_Variaiton/TOMS/ncfile/AI.nc','AI_DJF');
AI(AI<0)=nan;

WIND=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/WIND/ncfile/WIND_NCEP_1978_1992.nc','WIND_DJF');
WIND_ECHINA=zeros(length(year),1);
WIND_ECHINA(:)=mean(mean(WIND(45:50,19:29,:),2),1);


corr=zeros(length(lon),length(lat));
temp=zeros(length(year),1);
for i=1:length(lon)
    for j=1:length(lat)
        temp(:)=AI(i,j,:);
        temp2=corrcoef(temp,WIND_ECHINA);
        corr(i,j)=temp2(1,2);
    end
end

corr(isnan(corr))=-999;



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

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