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

SSLT_MONTH=SSLT_MONTH*1e6;

regressor=zeros(144,96);
sig=zeros(144,96);
for i=1:144
    for j=1:96
        y=zeros(1800,1);
        y(:)=CCN_MONTH(i,j,:);
        x=zeros(1800,1);
        x(:)=SSLT_MONTH(i,j,:);
        X=[ones(1800,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_monthly.mat','regressor','sig')

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