load ~/NC/grid.mat
load ~/Aerosol_Variaiton/IRUN/SST/ncfile/ENSO_Month.mat
load ~/Aerosol_Variaiton/IRUN/RH/ncfile/RH_monthly.mat
month=1:1800;

a=sum(EN_Month);
b=sum(LL_Month);

RH_EN_month=zeros(144,96,a);
RH_LL_month=zeros(144,96,b);

n=0;
m=0;
for monthID=1:length(month)
    if EN_Month(monthID)==1
        n=n+1;
        RH_EN_month(:,:,n)=RH_MONTH(:,:,monthID);
    end
    if LL_Month(monthID)==1
        m=m+1;
        RH_LL_month(:,:,m)=RH_MONTH(:,:,monthID);
    end
end

RH_EN=mean(RH_EN_month,3);
RH_LL=mean(RH_LL_month,3);

RH_ENSO=RH_EN-RH_LL;


save('RH_ENSO_composite_monthly.mat','RH_EN','RH_LL','RH_ENSO')

nccreate('RH_ENSO_composite_monthly.nc','lat','Dimensions',{'lat',96},'Format','classic')
ncwrite('RH_ENSO_composite_monthly.nc','lat', lat)
ncwriteatt('RH_ENSO_composite_monthly.nc','lat','units','degrees_north')
ncwriteatt('RH_ENSO_composite_monthly.nc','lat','long_name','Latitude')
nccreate('RH_ENSO_composite_monthly.nc','lon','Dimensions',{'lon',144},'Format','classic')
ncwrite('RH_ENSO_composite_monthly.nc','lon', lon)
ncwriteatt('RH_ENSO_composite_monthly.nc','lon','units','degrees_east')
ncwriteatt('RH_ENSO_composite_monthly.nc','lon','long_name','Longitude')
nccreate('RH_ENSO_composite_monthly.nc','RH_EN','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('RH_ENSO_composite_monthly.nc','RH_EN', RH_EN)
nccreate('RH_ENSO_composite_monthly.nc','RH_LL','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('RH_ENSO_composite_monthly.nc','RH_LL', RH_LL)
nccreate('RH_ENSO_composite_monthly.nc','RH_ENSO','Dimensions',{'lon',144,'lat',96},'Format','classic')
ncwrite('RH_ENSO_composite_monthly.nc','RH_ENSO', RH_ENSO)
ncdisp('RH_ENSO_composite_monthly.nc')
