function a = ComputeBinDataR(bandData, invStokesM, countObs, numberBins)

binOkay = 1;
for i=1:numberBins
	if countObs(i) > 0
	
			% Determine the average reflectance for the 3 angles.
	
		for j=1:3
			bandData(i,j) = bandData(i,j)/countObs(i);
			end;	% for j=1:3
	
			% Determine the average I, Q and U
			
		stokesV = invStokesM * ...
			[bandData(i,1); bandData(i,2); bandData(i,3)];
			
		bandData(i,1:3) = stokesV';

			% Now compute the polarization percent,
			% the angle chi of the plane of polarization,
			% and the polarization reflectance factor.
	
		bandData(i,4) = 100 * sqrt( (bandData(i,2)^2 + bandData(i,3)^2) )/bandData(i,1);
		bandData(i,5) = (atan2( bandData(i,3),bandData(i,2) )/2) * 180/pi;
		bandData(i,6) = bandData(i,4) * bandData(i,1) / 100;

	else	% countObs(i) <= 0
		binOkay = 0;
			
	end;	% if countObs(i) > 0, else...
		
	end;	% for i=1:numberBins

	% Now fill the empty bins where possible with the portion of those
	% on either side of it.

if binOkay == 0			
	for i=1:numberBins
		if countObs(i) <= 0
		
			il = 0;
			iu = 0;
			for j=i-1:-1:1
				if countObs(j) > 0
					il = j;
					break;
					end;	% if countObs(j) > 0
					
				end;	% for j=i-1:-1:1
				
			for j=i+1:numberBins
				if countObs(j) > 0
					iu = j;
					break;
					end;	% if numberBins(j) > 0
					
				end;	% for j=i-1:-1:1
				
			if il > 0 & iu > 0
				iuFactor = (i-il)/(iu-il);
				ilFactor = 1 - iuFactor;
				bandData(i,1:6) = ilFactor*bandData(il,1:6) +...
											iuFactor*bandData(iu,1:6);
%				for j=1:6
%					bandData(i,j) = ilFactor*bandData(il,j) +...
%											iuFactor*bandData(iu,j);
%					end;	% for j=1:6
				
			else	% il <= 0 | iu <= 0
				bandData(i,1:6) = [nan nan nan nan nan nan];
			
			end;	% if il > 0 & iu > 0, else...
			
			end;	% if countObs(i) <= 0
			
		end;	% for i=1:numberBins
		
	end;	% if binOkay == 0

a = bandData;
