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


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

n=0;
for yearID=1:length(year)
    if WIND_year(yearID)==1
        n=n+1;
        FSNSC_weak_temp(:,:,n)=FSNSC(:,:,yearID);
    end
end
FSNSC_weak=mean(FSNSC_weak_temp,3);

FSNSC_aveg=mean(FSNSC,3);
FSNSC_diff=FSNSC_weak-FSNSC_aveg;


for i=1:length(lon)
    for j=1:length(lat)
        if FSNSC_weak(i,j)<0
            FSNSC_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(:)=FSNSC_weak_temp(i,j,:);
        temp2(:)=FSNSC(i,j,:);
        temp1(temp1<0)=nan;
        temp2(temp2<0)=nan;
        h(i,j)=ttest2(temp1,temp2);
    end
end

h(isnan(h))=-999;


save('FSNSC_10th.mat','FSNSC_weak','FSNSC_aveg','FSNSC_diff','h')

nccreate('FSNSC_10th.nc','lat','Dimensions',{'lat',length(lat)},'Format','classic')
ncwrite('FSNSC_10th.nc','lat', lat)
ncwriteatt('FSNSC_10th.nc','lat','units','degrees_north')
ncwriteatt('FSNSC_10th.nc','lat','long_name','Latitude')
nccreate('FSNSC_10th.nc','lon','Dimensions',{'lon',length(lon)},'Format','classic')
ncwrite('FSNSC_10th.nc','lon', lon)
ncwriteatt('FSNSC_10th.nc','lon','units','degrees_east')
ncwriteatt('FSNSC_10th.nc','lon','long_name','Longitude')
nccreate('FSNSC_10th.nc','FSNSC_weak','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FSNSC_10th.nc','FSNSC_weak', FSNSC_weak)
nccreate('FSNSC_10th.nc','FSNSC_aveg','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FSNSC_10th.nc','FSNSC_aveg', FSNSC_aveg)
nccreate('FSNSC_10th.nc','FSNSC_diff','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FSNSC_10th.nc','FSNSC_diff', FSNSC_diff)
nccreate('FSNSC_10th.nc','h','Dimensions',{'lon',length(lon),'lat',length(lat)},'Format','classic')
ncwrite('FSNSC_10th.nc','h', h)
ncdisp('FSNSC_10th.nc')