% EXTERNAL DATA FILE FORMAT
%
% External data can be compared to simulated tracer
% responses using the compare function.
%
% The external data file is expected to contain a
% full matrix with N+1 columns of M rows where
% column one is the time in days (between 1 and 3)
% followed by columns for N concentration curves.
% M is the number of time points.
%
% The points are plotted as asterisks (*) and if
% M is greater than about 30 the plot is not
% visually pleasing. 
%
% The file should be in ASCII format with a ".dat"
% extension which will be automatically added to
% the user specified name.

%----------------- above is help info ------------------
%
% RTD Simulator - Compare tracer curves
%
% Bob Newell, January 1996
%
function rtdcomp( fname, results, objects )
[npts, n] = size( results );
nobjects = n - 1;
%
% extract data to plot
%
time = results(:,1);
%
% plot according to current scale factors 
%
data = [];
leg = [];
for i = 1:nobjects,
  if objects(i,12) > 0,
    data = [ data objects(i,12) * results(:,i+1) ];
	leg = [ leg; [ 'Object ' num2str(i) ] ]; 
  end;
end;
%
% get the external data
%
extname = input( 'Filename for external data in single quotes > ' );
extdata = [];
if length(extname) > 0,
  fid = fopen( [extname '.dat'] );
  if fid >= 0,
    fclose( fid );
    eval( ['load ' extname '.dat'] );
    eval( ['extdata = ' extname ';'] );
  end;
end;
[ne, me] = size( extdata );
%
% now the graphics part
%
h = figure;  
plot( time, data );
xlabel( 'Time in Days' );
ylabel( 'Tracer' );
title( ['RTD Simulation "' fname '"'] );
legend( leg );
if me > 0,
  hold on;
  plot( extdata(:,1), extdata(:,2:me), '*' );
  hold off;
end;
%t = waitforbuttonpress;
%close( h );
%
return;
