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');
FSNS=ncread('/Users/yangyang/Aerosol_Variaiton/CERES/ncfile/FNS_2001_2016_12.nc','FSNS_DJF');


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

n=0;
for yearID=1:length(year)
    if WIND_year(yearID)==1
        n=n+1;
        FSNS_weak_temp(:,:,n)=FSNS(:,:,yearID);
    end
end
FSNS_weak=mean(FSNS_weak_temp,3);

FSNS_aveg=mean(FSNS,3);
FSNS_diff=FSNS_weak-FSNS_aveg;


for i=1:length(lon)
    for j=1:length(lat)
        if FSNS_weak(i,j)<0
            FSNS_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(:)=FSNS_weak_temp(i,j,:);
        temp2(:)=FSNS(i,j,:);
        temp1(temp1<0)=nan;
        temp2(temp2<0)=nan;
        h(i,j)=ttest2(temp1,temp2);
    end
end

h(isnan(h))=-999;


save('FSNS_10th_12.mat','FSNS_weak','FSNS_aveg','FSNS_diff','h')

nccreate('FSNS_10th_12.nc','lat','Dimensions',{'lat',length(lat)},'Format','classic')
ncwrite('FSNS_10th_12.nc','lat', lat)
ncwriteatt('FSNS_10th_12.nc','lat','units','degrees_north')
ncwriteatt('FSNS_10th_12.nc','lat','long_name','Latitude')
nccreate('FSNS_10th_12.nc','lon','Dimensions',{'lon',length(lon)},'Format','classic')
ncwrite('FSNS_10th_12.nc','lon', lon)
ncwriteatt('FSNS_10th_12.nc','lon','units','degrees_east')
ncwriteatt('FSNS_10th_12.nc','lon','long_name','Longitude')
nccreate('FSNS_10th_12.nc','FSNS_weak','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FSNS_10th_12.nc','FSNS_weak', FSNS_weak)
nccreate('FSNS_10th_12.nc','FSNS_aveg','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FSNS_10th_12.nc','FSNS_aveg', FSNS_aveg)
nccreate('FSNS_10th_12.nc','FSNS_diff','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FSNS_10th_12.nc','FSNS_diff', FSNS_diff)
nccreate('FSNS_10th_12.nc','h','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FSNS_10th_12.nc','h', h)
ncdisp('FSNS_10th_12.nc')