year=1981:2015;

load /Users/yang146/Aerosol_Variaiton/OBS/ncfile/Dust_1981_2007.mat
dust_1981_2007=dust;
load /Users/yang146/Aerosol_Variaiton/OBS/ncfile/Dust_2008_2015.mat
dust_2008_2015=dust;

load /Users/yang146/Aerosol_Variaiton/OBS/ncfile/sites.mat
temp=importdata('/Users/yangyang/Aerosol_Variaiton/OBS/dat/2007-2015DJF_DustStorms/stationID.txt');
stationID=temp(:,1);

dust_2008_2015_new=zeros(length(siteID),8);
for j=1:length(siteID)
    for i=1:length(stationID)
        if stationID(i)==siteID(j)
            dust_2008_2015_new(j,:)=dust_2008_2015(i,:);
        end
    end
end


dust=zeros(length(siteID),length(year));
dust(:,1:27)=dust_1981_2007;
dust(:,28:35)=dust_2008_2015_new;



WIND_year=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/WIND/ncfile/WIND_NCEP_10th_1981_2015.nc','WIND_year');

dust_weak_temp=zeros(length(lon_site),1);

n=0;
for yearID=1:length(year)
    if WIND_year(yearID)==1
        n=n+1;
        dust_weak_temp(:,n)=dust(:,yearID);
    end
end
dust_weak=mean(dust_weak_temp,2);
dust_aveg=mean(dust,2);
dust_diff=dust_weak-dust_aveg;

dust_diff(dust_diff==0)=-999;


save('Dust_10th_1981_2015','dust_weak','dust_aveg','dust_diff','lon_site','lat_site')



nccreate('Dust_10th_1981_2015.nc','lat','Dimensions',{'site',length(lat_site)},'Format','classic')
ncwrite('Dust_10th_1981_2015.nc','lat', lat_site)
ncwriteatt('Dust_10th_1981_2015.nc','lat','units','degrees_north')
ncwriteatt('Dust_10th_1981_2015.nc','lat','long_name','Latitude')
nccreate('Dust_10th_1981_2015.nc','lon','Dimensions',{'site',length(lat_site)},'Format','classic')
ncwrite('Dust_10th_1981_2015.nc','lon', lon_site)
ncwriteatt('Dust_10th_1981_2015.nc','lon','units','degrees_east')
ncwriteatt('Dust_10th_1981_2015.nc','lon','long_name','Longitude')
nccreate('Dust_10th_1981_2015.nc','dust_weak','Dimensions',{'site',length(lat_site)},'Format','classic')
ncwrite('Dust_10th_1981_2015.nc','dust_weak', dust_weak)
nccreate('Dust_10th_1981_2015.nc','dust_aveg','Dimensions',{'site',length(lat_site)},'Format','classic')
ncwrite('Dust_10th_1981_2015.nc','dust_aveg', dust_aveg)
nccreate('Dust_10th_1981_2015.nc','dust_diff','Dimensions',{'site',length(lat_site)},'Format','classic')
ncwrite('Dust_10th_1981_2015.nc','dust_diff', dust_diff)






                
    