function plotsim(fname, qntity, cells, clr)
% PLOTSIM - plot specified simulation results coming from CTMSIM.
%
% Call: plotsim(fname, qntity, cells, clr)
%
% Parameters:
% fname - name of the file with simulation stored by CTMSIM;
% qntity - quantity that needs to be plotted:
% 'density' - mainline density,
% 'flow' - mainline flow,
% 'speed' - mainline speed,
% 'ttime' - mainline travel time,
% 'demand' - on-ramp demand,
% 'orflow' - on-ramp flow,
% 'queue' - on-ramp queue,
% 'frflow' - off-ramp flow,
% 'beta' - off-ramp split ratio,
% 'vht' - Vehicle Hours Traveled,
% 'vmt' - Vehicle Miles Traveled,
% 'delay' - travel delay,
% 'ploss' - productivity loss;
% cells - array of cell numbers, for which data has to be plotted;
% clr - line color.
%
% Returns: none.
%
% See also: PLOTSIM3, CTMSIM, FWCONFIG.
%
% Last modified: 03/25/2007.
%
% Alex Kurzhanskiy <akurzhan@eecs.berkeley.edu>
%
load(fname);
if ~isstruct(ctmGUI_data)
error('PLOTSIM: no simulation data found in the specified file.')
end
if ~exist('clr', 'var') | isempty(clr)
clr = 'b';
end
s = ctmGUI_data; % just to make the name shorter
if strcmp(lower(qntity), 'ttime') % special case: no per cell data available
plot(s.timeMinutes, s.traveltimeData, 'LineWidth', 2, 'Color', clr);
xlabel('Time (min)');
ylabel('Travel Time (min)');
title(s.freeway);
hold on;
return;
end
str = sprintf('per %.2f minutes', (60 * s.plotPeriod * s.TS));
if ~exist('cells', 'var') | isempty(cells) % no cells specified
% time series contours or aggregates
switch lower(qntity)
case 'density'
subplot('position', [0.1 0.1 0.7 0.8]);
pcolor(s.pmData, s.timeMinutes, s.densityData');
colormap(s.densityCMF);
shading flat;
xlabel('Post Mile');
ylabel('Time (min)');
title('Density Time Contour');
subplot('position', [0.93 0.1 0.05 0.8]);
mn = min(min(s.densityData));
mx = max(max(s.densityData));
yy = linspace(mn, mx, size(s.densityCMF, 1));
pcolor([0 1], yy, [yy' yy']);
colormap(s.densityCMF);
shading flat;
ylabel('Density (vpm)');
h = gca;
set(h, 'XTick', []);
return;
case 'flow'
subplot('position', [0.1 0.1 0.7 0.8]);
pcolor(s.pmData, s.timeMinutes, s.flowData');
colormap(s.flowCMF);
shading flat;
xlabel('Post Mile');
ylabel('Time (min)');
title('Flow Time Contour');
subplot('position', [0.93 0.1 0.05 0.8]);
mn = min(min(s.flowData));
mx = max(max(s.flowData));
yy = linspace(mn, mx, size(s.flowCMF, 1));
pcolor([0 1], yy, [yy' yy']);
colormap(s.flowCMF);
shading flat;
ylabel('Flow (vph)');
h = gca;
set(h, 'XTick', []);
return;
case 'speed'
subplot('position', [0.1 0.1 0.7 0.8]);
pcolor(s.pmData, s.timeMinutes, s.speedData');
colormap(s.speedCMF);
shading flat;
xlabel('Post Mile');
ylabel('Time (min)');
title('Speed Time Contour');
subplot('position', [0.93 0.1 0.05 0.8]);
mn = min(min(s.speedData));
mx = max(max(s.speedData));
yy = linspace(mn, mx, size(s.speedCMF, 1));
pcolor([0 1], yy, [yy' yy']);
colormap(s.speedCMF);
shading flat;
ylabel('Speed (mph)');
h = gca;
set(h, 'XTick', []);
return;
case 'demand'
subplot('position', [0.1 0.1 0.7 0.8]);
pcolor(s.pmData, s.timeMinutes, s.demandData');
colormap(s.orflowCMF);
shading flat;
xlabel('Post Mile');
ylabel('Time (min)');
title('On-Ramp Demand Time Contour');
subplot('position', [0.93 0.1 0.05 0.8]);
mn = min(min(s.orflowData));
mx = max(max(s.orflowData));
yy = linspace(mn, mx, size(s.orflowCMF, 1));
pcolor([0 1], yy, [yy' yy']);
colormap(s.orflowCMF);
shading flat;
ylabel('On-Ramp Demand (vph)');
h = gca;
set(h, 'XTick', []);
return;
case 'orflow'
subplot('position', [0.1 0.1 0.7 0.8]);
pcolor(s.pmData, s.timeMinutes, s.orflowData');
colormap(s.orflowCMF);
shading flat;
xlabel('Post Mile');
ylabel('Time (min)');
title('On-Ramp Flow Time Contour');
subplot('position', [0.93 0.1 0.05 0.8]);
mn = min(min(s.orflowData));
mx = max(max(s.orflowData));
yy = linspace(mn, mx, size(s.orflowCMF, 1));
pcolor([0 1], yy, [yy' yy']);
colormap(s.orflowCMF);
shading flat;
ylabel('On-Ramp Flow (vph)');
h = gca;
set(h, 'XTick', []);
return;
case 'queue'
subplot('position', [0.1 0.1 0.7 0.8]);
pcolor(s.pmData, s.timeMinutes, s.orqueueData');
colormap(s.orqueueCMF);
shading flat;
xlabel('Post Mile');
ylabel('Time (min)');
title('On-Ramp Queue Time Contour');
subplot('position', [0.93 0.1 0.05 0.8]);
mn = min(min(s.orqueueData));
mx = max(max(s.orqueueData));
yy = linspace(mn, mx, size(s.orqueueCMF, 1));
pcolor([0 1], yy, [yy' yy']);
colormap(s.orqueueCMF);
shading flat;
ylabel('Queue Size');
h = gca;
set(h, 'XTick', []);
return;
case 'frflow'
subplot('position', [0.1 0.1 0.7 0.8]);
pcolor(s.pmData, s.timeMinutes, s.frflowData');
colormap(s.frflowCMF);
shading flat;
xlabel('Post Mile');
ylabel('Time (min)');
title('Off-Ramp Flow Time Contour');
subplot('position', [0.93 0.1 0.05 0.8]);
mn = min(min(s.frflowData));
mx = max(max(s.frflowData));
yy = linspace(mn, mx, size(s.frflowCMF, 1));
pcolor([0 1], yy, [yy' yy']);
colormap(s.frflowCMF);
shading flat;
ylabel('Off-Ramp Flow (vph)');
h = gca;
set(h, 'XTick', []);
return;
case 'beta'
subplot('position', [0.1 0.1 0.7 0.8]);
pcolor(s.pmData, s.timeMinutes, s.frbetaData');
colormap(s.frbetaCMF);
shading flat;
xlabel('Post Mile');
ylabel('Time (min)');
title('Off-Ramp Split Ratio Time Contour');
subplot('position', [0.93 0.1 0.05 0.8]);
mn = min(min(s.frbetaData));
mx = max(max(s.frbetaData));
yy = linspace(mn, mx, size(s.frbetaCMF, 1));
pcolor([0 1], yy, [yy' yy']);
colormap(s.frbetaCMF);
shading flat;
ylabel('Off-Ramp Split Ratio');
h = gca;
set(h, 'XTick', []);
return;
case 'vht'
plot(s.timeMinutes, s.tvhData, 'LineWidth', 2, 'Color', clr);
xlabel('Time (min)');
ylabel(sprintf('VHT %s', str));
title(s.freeway);
hold on;
return;
case 'vmt'
plot(s.timeMinutes, s.tvmData, 'LineWidth', 2, 'Color', clr);
xlabel('Time (min)');
ylabel(sprintf('VMT %s', str));
title(s.freeway);
hold on;
return;
case 'delay'
plot(s.timeMinutes, s.cdelayData, 'LineWidth', 2, 'Color', clr);
xlabel('Time (min)');
ylabel(sprintf('Delay (vh) %s', str));
title(s.freeway);
hold on;
return;
case 'ploss'
plot(s.timeMinutes, s.cplossData, 'LineWidth', 2, 'Color', clr);
xlabel('Time (min)');
ylabel(sprintf('Productivity Loss (lmh) %s', str));
title(s.freeway);
hold on;
return;
otherwise
error('PLOTSIM: invalid quantity.');
end
else
% 2D plots: data per cell
switch lower(qntity)
case 'density'
data = s.densityData;
ylbl = 'Density (vpm)';
case 'flow'
data = s.flowData;
ylbl = 'Flow (vph)';
case 'speed'
data = s.speedData;
ylbl = 'Speed (mph)';
case 'demand'
data = s.demandData;
ylbl = 'On-Ramp Demand (vph)';
case 'orflow'
data = s.orflowData;
ylbl = 'On-Ramp Flow (vph)';
case 'queue'
data = s.orqueueData;
ylbl = 'Queue Size';
case 'frflow'
data = s.frflowData;
ylbl = 'Off-Ramp Flow (vph)';
case 'beta'
data = s.frbetaData;
ylbl = 'Off-Ramp Split Ratio';
case 'vht'
data = s.vhtData;
ylbl = sprintf('VHT %s', str);
case 'vmt'
data = s.vmtData;
ylbl = sprintf('VMT %s', str);
case 'delay'
data = s.delayData;
ylbl = sprintf('Delay (vh) %s', str);
case 'ploss'
data = s.plossData;
ylbl = sprintf('Productivity Loss (lmh) %s', str);
otherwise
error('PLOTSIM: invalid quantity.');
end
N = size(s.cellData, 2); % total number of cells
M = size(cells, 2); % number of cells specified
for i = 1:M
cn = cells(i);
if (cn < 1) | (cn > N)
fprintf('PLOTSIM: Warning! Invalid cell number %d...\n\n', cn);
continue;
end
figure(cn);
plot(s.timeMinutes, data(cn, :), 'LineWidth', 2, 'Color', clr);
xlabel('Time (min)');
ylabel(ylbl);
title(sprintf('Cell %d', cn));
hold on;
end
end
return;