function out = cal_vr_shape(outin)

% CAL_VR_SHAPE calculate variance reduction between reference distribution
%              and given distribution in back azimuth axis.


mm = size(outin);
mm1 = (mm(2)+1)/2;
xtemp = 1:mm(2);
refdist = exp(-((mm1-xtemp)./2).^2)+0.03;

[maxamp,imaxamp]=max(outin');
temp2 = sum(refdist.^2);

for i = 1 : mm(1)
    if (imaxamp(i) <= mm1)
        ishift = mm1-imaxamp(i);
        finout1(i,ishift+1:mm(2))=outin(i,1:mm(2)-ishift)/maxamp(i);
        finout1(i,1:ishift)=outin(i,mm(2)-ishift+1:mm(2))/maxamp(i);
    else
       ishift = imaxamp(i) - mm1;
       finout1(i,1:mm(2)-ishift)=outin(i,ishift+1:mm(2))/maxamp(i);
       finout1(i,mm(2)-ishift+1:mm(2))=outin(i,1:ishift)/maxamp(i);
    end
    temp1 = sum((finout1(i,:)'-refdist').^2);
    out(i) = sqrt(temp1/temp2);
end

temp2 = sum(refdist.^2);
for j = 1 : mm(1)
   temp1 = sum((finout1(j,:)'-refdist').^2); 
   out(j) = sqrt(temp1/temp2);
end
