%
% RTD Simulator - Tracer injection simulation
%
% Bob Newell, January 1996
%
function ok = rtdmbal( objects )
[nobjects, n] = size( objects );
%
% want to check out the mass balance which
% the user has to set up properly
%
disp( 'Mass balance check ...' );
ok = 1;
for n = 1:nobjects,
  if objects(n,1) > 1 & objects(n,1) < 5,
    inflow = 0;
    outflow = 0;
%
% calculate inlet flows (total)
%  
    for i = 1:nobjects,
      for j = 2:5,
        k = objects(i,2*j);
        if k == n,
          inflow = inflow + objects(i,2*j+1);
        end;
      end;
    end;
%
% calculate outlet flows
%
    for j = 2:5,
      k = objects(n,2*j);
      if k > 0,
        outflow = outflow + objects(n,2*j+1);
      end;
    end;
%
% now for the check
%
    if abs( inflow - outflow ) > 0.00001,
      disp( [ 'Object ' num2str(n) ' has a mass imbalance' ] );
      disp( [ '  Inflow = ' num2str( inflow ) ...
	               '  Outflow = ' num2str( outflow ) ] );
      ok = 0;
    end;
%
  end;
end;
%
if ok == 0,
  input( 'Press ENTER to continue ..' );
end;
return;
