year=2001:2016;
lat=ncread('/Users/yang146/Aerosol_Variaiton/CERES/dat/CERES_EBAF-Surface_Ed2.8_Subset_200003-201602.nc','lat');
lon=ncread('/Users/yang146/Aerosol_Variaiton/CERES/dat/CERES_EBAF-Surface_Ed2.8_Subset_200003-201602.nc','lon');

WIND_year=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/WIND/ncfile/WIND_NCEP_10th_2001_2016.nc','WIND_year');
FNS=ncread('/Users/yangyang/Aerosol_Variaiton/CERES/ncfile/FNS_2001_2016_DJF.nc','FNS_DJF');


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

n=0;
for yearID=1:length(year)
    if WIND_year(yearID)==1
        n=n+1;
        FNS_weak_temp(:,:,n)=FNS(:,:,yearID);
    end
end
FNS_weak=mean(FNS_weak_temp,3);

FNS_aveg=mean(FNS,3);
FNS_diff=FNS_weak-FNS_aveg;


%for i=1:length(lon)
%    for j=1:length(lat)
%        if FNS_weak(i,j)<0
%            FNS_diff(i,j)=-999;
%        end
%    end
%end



h=zeros(length(lon),length(lat));
temp1=zeros(sum(WIND_year),1);
temp2=zeros(length(year),1);
for i=1:length(lon)
    for j=1:length(lat)
        temp1(:)=FNS_weak_temp(i,j,:);
        temp2(:)=FNS(i,j,:);
%        temp1(temp1<0)=nan;
%        temp2(temp2<0)=nan;
        h(i,j)=ttest2(temp1,temp2);
    end
end

h(isnan(h))=-999;


save('FNS_10th.mat','FNS_weak','FNS_aveg','FNS_diff','h')

nccreate('FNS_10th.nc','lat','Dimensions',{'lat',length(lat)},'Format','classic')
ncwrite('FNS_10th.nc','lat', lat)
ncwriteatt('FNS_10th.nc','lat','units','degrees_north')
ncwriteatt('FNS_10th.nc','lat','long_name','Latitude')
nccreate('FNS_10th.nc','lon','Dimensions',{'lon',length(lon)},'Format','classic')
ncwrite('FNS_10th.nc','lon', lon)
ncwriteatt('FNS_10th.nc','lon','units','degrees_east')
ncwriteatt('FNS_10th.nc','lon','long_name','Longitude')
nccreate('FNS_10th.nc','FNS_weak','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FNS_10th.nc','FNS_weak', FNS_weak)
nccreate('FNS_10th.nc','FNS_aveg','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FNS_10th.nc','FNS_aveg', FNS_aveg)
nccreate('FNS_10th.nc','FNS_diff','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FNS_10th.nc','FNS_diff', FNS_diff)
nccreate('FNS_10th.nc','h','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FNS_10th.nc','h', h)
ncdisp('FNS_10th.nc')