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

PRECT_ANN_SD=zeros(144,96);
PRECT_ANN_RSD=zeros(144,96);
PRECT_DJF_SD=zeros(144,96);
PRECT_DJF_RSD=zeros(144,96);
PRECT_MAM_SD=zeros(144,96);
PRECT_MAM_RSD=zeros(144,96);
PRECT_JJA_SD=zeros(144,96);
PRECT_JJA_RSD=zeros(144,96);
PRECT_SON_SD=zeros(144,96);
PRECT_SON_RSD=zeros(144,96);
PRECT_JAN_SD=zeros(144,96);
PRECT_JAN_RSD=zeros(144,96);
PRECT_JUL_SD=zeros(144,96);
PRECT_JUL_RSD=zeros(144,96);

for i=1:144
    for j=1:96
        PRECT_ANN_SD(i,j)=std(PRECT_ANN(i,j,:));
        PRECT_ANN_RSD(i,j)=PRECT_ANN_SD(i,j)./(mean(PRECT_ANN(i,j,:),3));
        PRECT_DJF_SD(i,j)=std(PRECT_DJF(i,j,:));
        PRECT_DJF_RSD(i,j)=PRECT_DJF_SD(i,j)./(mean(PRECT_DJF(i,j,:),3));
        PRECT_MAM_SD(i,j)=std(PRECT_MAM(i,j,:));
        PRECT_MAM_RSD(i,j)=PRECT_MAM_SD(i,j)./(mean(PRECT_MAM(i,j,:),3));
        PRECT_JJA_SD(i,j)=std(PRECT_JJA(i,j,:));
        PRECT_JJA_RSD(i,j)=PRECT_JJA_SD(i,j)./(mean(PRECT_JJA(i,j,:),3));
        PRECT_SON_SD(i,j)=std(PRECT_SON(i,j,:));
        PRECT_SON_RSD(i,j)=PRECT_SON_SD(i,j)./(mean(PRECT_SON(i,j,:),3));
        PRECT_JAN_SD(i,j)=std(PRECT_JAN(i,j,:));
        PRECT_JAN_RSD(i,j)=PRECT_JAN_SD(i,j)./(mean(PRECT_JAN(i,j,:),3));
        PRECT_JUL_SD(i,j)=std(PRECT_JUL(i,j,:));
        PRECT_JUL_RSD(i,j)=PRECT_JUL_SD(i,j)./(mean(PRECT_JUL(i,j,:),3));
    end
end

save('PRECT_SD_RSD.mat','PRECT_ANN_SD','PRECT_ANN_RSD','PRECT_DJF_SD','PRECT_DJF_RSD','PRECT_MAM_SD','PRECT_MAM_RSD','PRECT_JJA_SD','PRECT_JJA_RSD','PRECT_SON_SD','PRECT_SON_RSD','PRECT_JAN_SD','PRECT_JAN_RSD','PRECT_JUL_SD','PRECT_JUL_RSD')

nccreate('PRECT_SD_RSD.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','lat', lat)
ncwriteatt('PRECT_SD_RSD.nc','lat','units','degrees_north')
ncwriteatt('PRECT_SD_RSD.nc','lat','long_name','Latitude')
nccreate('PRECT_SD_RSD.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','lon', lon)
ncwriteatt('PRECT_SD_RSD.nc','lon','units','degrees_east')
ncwriteatt('PRECT_SD_RSD.nc','lon','long_name','Longitude')
nccreate('PRECT_SD_RSD.nc','PRECT_ANN_SD','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','PRECT_ANN_SD', PRECT_ANN_SD)
nccreate('PRECT_SD_RSD.nc','PRECT_ANN_RSD','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','PRECT_ANN_RSD', PRECT_ANN_RSD)
nccreate('PRECT_SD_RSD.nc','PRECT_DJF_SD','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','PRECT_DJF_SD', PRECT_DJF_SD)
nccreate('PRECT_SD_RSD.nc','PRECT_DJF_RSD','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','PRECT_DJF_RSD', PRECT_DJF_RSD)
nccreate('PRECT_SD_RSD.nc','PRECT_MAM_SD','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','PRECT_MAM_SD', PRECT_MAM_SD)
nccreate('PRECT_SD_RSD.nc','PRECT_MAM_RSD','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','PRECT_MAM_RSD', PRECT_MAM_RSD)
nccreate('PRECT_SD_RSD.nc','PRECT_JJA_SD','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','PRECT_JJA_SD', PRECT_JJA_SD)
nccreate('PRECT_SD_RSD.nc','PRECT_JJA_RSD','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','PRECT_JJA_RSD', PRECT_JJA_RSD)
nccreate('PRECT_SD_RSD.nc','PRECT_SON_SD','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','PRECT_SON_SD', PRECT_SON_SD)
nccreate('PRECT_SD_RSD.nc','PRECT_SON_RSD','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','PRECT_SON_RSD', PRECT_SON_RSD)
nccreate('PRECT_SD_RSD.nc','PRECT_JAN_SD','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','PRECT_JAN_SD', PRECT_JAN_SD)
nccreate('PRECT_SD_RSD.nc','PRECT_JAN_RSD','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','PRECT_JAN_RSD', PRECT_JAN_RSD)
nccreate('PRECT_SD_RSD.nc','PRECT_JUL_SD','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','PRECT_JUL_SD', PRECT_JUL_SD)
nccreate('PRECT_SD_RSD.nc','PRECT_JUL_RSD','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('PRECT_SD_RSD.nc','PRECT_JUL_RSD', PRECT_JUL_RSD)
ncdisp('PRECT_SD_RSD.nc')
