load ~/NC/grid
load ~/Aerosol_Variaiton/IRUN/SSLT/ncfile/SSLT.mat
load ~/Aerosol_Variaiton/IRUN/CCN_TOT/ncfile/CCN.mat

SSLT_ANN=SSLT_ANN*1e6;

regressor=zeros(144,96);
sig=zeros(144,96);
for i=1:144
    for j=1:96
        y=zeros(150,1);
        y(:)=CCN_ANN(i,j,:);
        x=zeros(150,1);
        x(:)=SSLT_ANN(i,j,:);
        X=[ones(150,1),x];
        [b,bint,r,rint,stats]=regress(y,X);
        regressor(i,j)=b(2);
        sig(i,j)=double(stats(3)<0.05);        
    end
end

save('SSLT_CCN_Regression_ANN.mat','regressor','sig')

nccreate('SSLT_CCN_Regression_ANN.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('SSLT_CCN_Regression_ANN.nc','lat', lat)
ncwriteatt('SSLT_CCN_Regression_ANN.nc','lat','units','degrees_north')
ncwriteatt('SSLT_CCN_Regression_ANN.nc','lat','long_name','Latitude')
nccreate('SSLT_CCN_Regression_ANN.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('SSLT_CCN_Regression_ANN.nc','lon', lon)
ncwriteatt('SSLT_CCN_Regression_ANN.nc','lon','units','degrees_east')
ncwriteatt('SSLT_CCN_Regression_ANN.nc','lon','long_name','Longitude')
nccreate('SSLT_CCN_Regression_ANN.nc','regressor','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLT_CCN_Regression_ANN.nc','regressor', regressor)
nccreate('SSLT_CCN_Regression_ANN.nc','sig','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('SSLT_CCN_Regression_ANN.nc','sig', sig)
ncdisp('SSLT_CCN_Regression_ANN.nc')