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');
FNSC=ncread('/Users/yangyang/Aerosol_Variaiton/CERES/ncfile/FNSC_2001_2016_DJF.nc','FNSC_DJF');


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

n=0;
for yearID=1:length(year)
    if WIND_year(yearID)==1
        n=n+1;
        FNSC_weak_temp(:,:,n)=FNSC(:,:,yearID);
    end
end
FNSC_weak=mean(FNSC_weak_temp,3);

FNSC_aveg=mean(FNSC,3);
FNSC_diff=FNSC_weak-FNSC_aveg;


%for i=1:length(lon)
%    for j=1:length(lat)
%        if FNSC_weak(i,j)<0
%            FNSC_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(:)=FNSC_weak_temp(i,j,:);
        temp2(:)=FNSC(i,j,:);
%        temp1(temp1<0)=nan;
%        temp2(temp2<0)=nan;
        h(i,j)=ttest2(temp1,temp2);
    end
end

h(isnan(h))=-999;


save('FNSC_10th.mat','FNSC_weak','FNSC_aveg','FNSC_diff','h')

nccreate('FNSC_10th.nc','lat','Dimensions',{'lat',length(lat)},'Format','classic')
ncwrite('FNSC_10th.nc','lat', lat)
ncwriteatt('FNSC_10th.nc','lat','units','degrees_north')
ncwriteatt('FNSC_10th.nc','lat','long_name','Latitude')
nccreate('FNSC_10th.nc','lon','Dimensions',{'lon',length(lon)},'Format','classic')
ncwrite('FNSC_10th.nc','lon', lon)
ncwriteatt('FNSC_10th.nc','lon','units','degrees_east')
ncwriteatt('FNSC_10th.nc','lon','long_name','Longitude')
nccreate('FNSC_10th.nc','FNSC_weak','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FNSC_10th.nc','FNSC_weak', FNSC_weak)
nccreate('FNSC_10th.nc','FNSC_aveg','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FNSC_10th.nc','FNSC_aveg', FNSC_aveg)
nccreate('FNSC_10th.nc','FNSC_diff','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FNSC_10th.nc','FNSC_diff', FNSC_diff)
nccreate('FNSC_10th.nc','h','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FNSC_10th.nc','h', h)
ncdisp('FNSC_10th.nc')