load ~/NC/grid.mat
load /Users/yangyang/Aerosol_Variaiton/IRUN/AIE_efficiency_CDNC/ncfile/Regions.mat
month=1:1800;

RH=ncread('/Users/yangyang/Aerosol_Variaiton/IRUN/RH/ncfile/RH_monthly.nc','RH_MONTH');

RH_ASI=zeros(length(month),1);
for monthID=1:length(month)
    RH_ASI(monthID)=sum(sum(RH(:,:,monthID).*ASI,2),1)/sum(ASI(:));
end
nccreate('RH_region_monthly.nc','RH_ASI','Dimensions',{'Year',length(month)},'Format','classic')
ncwrite('RH_region_monthly.nc','RH_ASI', RH_ASI)

RH_SPO=zeros(length(month),1);
for monthID=1:length(month)
    RH_SPO(monthID)=sum(sum(RH(:,:,monthID).*SPO,2),1)/sum(SPO(:));
end
nccreate('RH_region_monthly.nc','RH_SPO','Dimensions',{'Year',length(month)},'Format','classic')
ncwrite('RH_region_monthly.nc','RH_SPO', RH_SPO)

RH_SAO=zeros(length(month),1);
for monthID=1:length(month)
    RH_SAO(monthID)=sum(sum(RH(:,:,monthID).*SAO,2),1)/sum(SAO(:));
end
nccreate('RH_region_monthly.nc','RH_SAO','Dimensions',{'Year',length(month)},'Format','classic')
ncwrite('RH_region_monthly.nc','RH_SAO', RH_SAO)

RH_SIO=zeros(length(month),1);
for monthID=1:length(month)
    RH_SIO(monthID)=sum(sum(RH(:,:,monthID).*SIO,2),1)/sum(SIO(:));
end
nccreate('RH_region_monthly.nc','RH_SIO','Dimensions',{'Year',length(month)},'Format','classic')
ncwrite('RH_region_monthly.nc','RH_SIO', RH_SIO)

RH_TPO=zeros(length(month),1);
for monthID=1:length(month)
    RH_TPO(monthID)=sum(sum(RH(:,:,monthID).*TPO,2),1)/sum(TPO(:));
end
nccreate('RH_region_monthly.nc','RH_TPO','Dimensions',{'Year',length(month)},'Format','classic')
ncwrite('RH_region_monthly.nc','RH_TPO', RH_TPO)

RH_TAO=zeros(length(month),1);
for monthID=1:length(month)
    RH_TAO(monthID)=sum(sum(RH(:,:,monthID).*TAO,2),1)/sum(TAO(:));
end
nccreate('RH_region_monthly.nc','RH_TAO','Dimensions',{'Year',length(month)},'Format','classic')
ncwrite('RH_region_monthly.nc','RH_TAO', RH_TAO)

RH_TIO=zeros(length(month),1);
for monthID=1:length(month)
    RH_TIO(monthID)=sum(sum(RH(:,:,monthID).*TIO,2),1)/sum(TIO(:));
end
nccreate('RH_region_monthly.nc','RH_TIO','Dimensions',{'Year',length(month)},'Format','classic')
ncwrite('RH_region_monthly.nc','RH_TIO', RH_TIO)

RH_NPO=zeros(length(month),1);
for monthID=1:length(month)
    RH_NPO(monthID)=sum(sum(RH(:,:,monthID).*NPO,2),1)/sum(NPO(:));
end
nccreate('RH_region_monthly.nc','RH_NPO','Dimensions',{'Year',length(month)},'Format','classic')
ncwrite('RH_region_monthly.nc','RH_NPO', RH_NPO)

RH_NAO=zeros(length(month),1);
for monthID=1:length(month)
    RH_NAO(monthID)=sum(sum(RH(:,:,monthID).*NAO,2),1)/sum(NAO(:));
end
nccreate('RH_region_monthly.nc','RH_NAO','Dimensions',{'Year',length(month)},'Format','classic')
ncwrite('RH_region_monthly.nc','RH_NAO', RH_NAO)

RH_SAM=zeros(length(month),1);
for monthID=1:length(month)
    RH_SAM(monthID)=sum(sum(RH(:,:,monthID).*SAM,2),1)/sum(SAM(:));
end
nccreate('RH_region_monthly.nc','RH_SAM','Dimensions',{'Year',length(month)},'Format','classic')
ncwrite('RH_region_monthly.nc','RH_SAM', RH_SAM)

RH_AFR=zeros(length(month),1);
for monthID=1:length(month)
    RH_AFR(monthID)=sum(sum(RH(:,:,monthID).*AFR,2),1)/sum(AFR(:));
end
nccreate('RH_region_monthly.nc','RH_AFR','Dimensions',{'Year',length(month)},'Format','classic')
ncwrite('RH_region_monthly.nc','RH_AFR', RH_AFR)

RH_OCE=zeros(length(month),1);
for monthID=1:length(month)
    RH_OCE(monthID)=sum(sum(RH(:,:,monthID).*OCE,2),1)/sum(OCE(:));
end
nccreate('RH_region_monthly.nc','RH_OCE','Dimensions',{'Year',length(month)},'Format','classic')
ncwrite('RH_region_monthly.nc','RH_OCE', RH_OCE)

RH_NAM=zeros(length(month),1);
for monthID=1:length(month)
    RH_NAM(monthID)=sum(sum(RH(:,:,monthID).*NAM,2),1)/sum(NAM(:));
end
nccreate('RH_region_monthly.nc','RH_NAM','Dimensions',{'Year',length(month)},'Format','classic')
ncwrite('RH_region_monthly.nc','RH_NAM', RH_NAM)

RH_EUR=zeros(length(month),1);
for monthID=1:length(month)
    RH_EUR(monthID)=sum(sum(RH(:,:,monthID).*EUR,2),1)/sum(EUR(:));
end
nccreate('RH_region_monthly.nc','RH_EUR','Dimensions',{'Year',length(month)},'Format','classic')
ncwrite('RH_region_monthly.nc','RH_EUR', RH_EUR)

save('RH_region_monthly.mat','RH_ASI','RH_SPO','RH_SAO','RH_SIO','RH_TPO','RH_TAO','RH_TIO','RH_NPO','RH_NAO','RH_SAM','RH_AFR','RH_OCE','RH_NAM','RH_EUR')
                      
