load ~/NC/grid.mat
load ~/Aerosol_Variaiton/ERUN/SST/ncfile/NINO34.mat
load ~/Aerosol_Variaiton/ERUN/PRECT/ncfile/PRECT.mat
year=1:150;

corr_DJF=zeros(144,96);
corr_JJA=zeros(144,96);

for i=1:144
    for j=1:96
        r=corrcoef(PRECT_DJF(i,j,:),NINO34_DJF(:));
        corr_DJF(i,j)=r(1,2);
        r=corrcoef(PRECT_JJA(i,j,:),NINO34_JJA(:));
        corr_JJA(i,j)=r(1,2);
    end
end

corr_DJF(isnan(corr_DJF))=-999;
corr_JJA(isnan(corr_JJA))=-999;

save('corr_PRECT_NINO34.mat','corr_DJF','corr_DJF')

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