function plot_data_1(handles)
% PLOT_DATA_1 - plots flow and density (or speed) data in the main screen
% of ctmGUI. Cannot be called from outside of ctmGUI.
%
% Last modified: 02/24/2008.
%
% Alex Kurzhanskiy <akurzhan@eecs.berkeley.edu>
%
global g_ctmGUI;
N = size(g_ctmGUI.cellData, 2); % number of cells
densities = g_ctmGUI.densityData(1:N, end);
flows = g_ctmGUI.flowData(1:N, end);
speeds = g_ctmGUI.speedData(1:N, end);
onerow = ones(1, N);
tm = max([eps (g_ctmGUI.timeStep * g_ctmGUI.TS * 60)]);
% get Y axis limits
ymin = g_ctmGUI.timeMinutes(1);
ymax = ymin + (g_ctmGUI.TS * 60 * g_ctmGUI.taxislim * g_ctmGUI.plotPeriod);
ylim = [ymin ymax];
% assign colors to cells
clrs = get_color_grade(densities, flows, g_ctmGUI.cellData, g_ctmGUI.yoColorRatio);
axes(handles.freeway);
plotbar(g_ctmGUI.pmData, 0.5*onerow, clrs);
hold on;
idx = get(handles.onrampList, 'Value') - 1;
if (idx > 0) & (idx <= N)
plot(g_ctmGUI.pmData(idx), 0.75, 'bv', 'MarkerFaceColor', 'b');
end
idx = get(handles.offrampList, 'Value');
plot(g_ctmGUI.pmData(idx+1), 0.75, 'c^', 'MarkerFaceColor', 'c');
axis([g_ctmGUI.xLims 0 1]);
set(handles.freeway, 'YTick', []);
hold off;
% show densities or speeds?
spd = strcmp(get(handles.menuSpeedOn, 'Checked'), 'on');
% plot data (densities and flows)
if strcmp(get(handles.menuContoursOn, 'Checked'), 'on') % plot time contours
XX = [0 1];
if spd > 0
mnd = min(min(g_ctmGUI.speedData));
mxd = max(max(g_ctmGUI.speedData));
else
mnd = min(min(g_ctmGUI.densityData));
mxd = max(max(g_ctmGUI.densityData));
end
mnf = min(min(g_ctmGUI.flowData));
mxf = max(max(g_ctmGUI.flowData));
myeps = 1e-7;
mxd = mxd + myeps; % these 2 lines are here to prevent
mnf = mnf - myeps; % overlaps of color maps...
uld = 2*mxd - mnd;
llf = 2*mnf - mxf;
axes(handles.densityPlot);
if spd > 0
pcolor(g_ctmGUI.pmData, ...
[g_ctmGUI.timeMinutes tm], ...
[(g_ctmGUI.speedData)'; (uld * [onerow 1])]);
else
pcolor(g_ctmGUI.pmData, ...
[g_ctmGUI.timeMinutes tm], ...
[(g_ctmGUI.densityData)'; (uld * [onerow 1])]);
end
shading flat;
if size(g_ctmGUI.timeMinutes, 2) < g_ctmGUI.taxislim
axis([g_ctmGUI.xLims ylim]);
else
ylim = axis;
ylim = ylim(3:4);
axis([g_ctmGUI.xLims ylim]);
end
xlabel('Post mile');
ylabel('Time (min)');
axes(handles.densityCM);
YY = linspace(mnd, mxd, g_ctmGUI.numColors);
pcolor(XX, YY, [YY' (uld * ones(g_ctmGUI.numColors, 1))]);
if spd > 0
ylabel('Speed (mph)');
else
ylabel('Density (vpm)');
end
shading flat;
axis([0 1 mnd mxd]);
set(handles.densityCM, 'XTick', []);
axes(handles.flowPlot);
pcolor(g_ctmGUI.pmData, ...
[g_ctmGUI.timeMinutes tm], ...
[(g_ctmGUI.flowData)'; (llf * [onerow 1])]);
shading flat;
if size(g_ctmGUI.timeMinutes, 2) < g_ctmGUI.taxislim
axis([g_ctmGUI.xLims ylim]);
else
ylim = axis;
ylim = ylim(3:4);
axis([g_ctmGUI.xLims ylim]);
end
%xlabel('Post mile');
ylabel('Time (min)');
axes(handles.flowCM);
YY = linspace(mnf, mxf, g_ctmGUI.numColors);
pcolor(XX, YY, [YY' (llf * ones(g_ctmGUI.numColors, 1))]);
shading flat;
axis([0 1 mnf mxf]);
ylabel('Flow (vph)');
set(handles.flowCM, 'XTick', []);
else % plot 2D data
fl = get_rbflow(densities(end, 1), ...
g_ctmGUI.cellData(end).ORflow, ...
flows(end, 1), ...
g_ctmGUI.cellData(end), ...
g_ctmGUI.outflow, ...
g_ctmGUI.TS);
axes(handles.densityPlot);
if spd > 0
ffv = get_ff_speeds(g_ctmGUI.cellData);
plot(g_ctmGUI.pmData, [ffv' ffv(end, 1)], 'r');
hold on;
plot(g_ctmGUI.pmData, [speeds' (fl/densities(end, 1))], '-bd');
hold off;
else
plot(g_ctmGUI.pmData, [densities' densities(end, 1)], '-bd');
cdv = get_critical_densities(g_ctmGUI.cellData)';
if min(cdv - densities') < 10
hold on;
plot(g_ctmGUI.pmData, [cdv cdv(end)], 'r');
hold off;
end
end
ylim = axis;
ylim = ylim(3:4);
axis([g_ctmGUI.xLims ylim]);
xlabel('Post mile');
if spd > 0
ylabel('Speed (mph)');
else
ylabel('Density (vpm)');
end
axes(handles.flowPlot);
plot(g_ctmGUI.pmData, [flows' fl], '-kd');
mfv = get_max_flows(g_ctmGUI.cellData);
if min(mfv' - flows') < 2000
hold on;
plot(g_ctmGUI.pmData, [mfv' mfv(end, 1)], 'r');
hold off;
end
ylim = axis;
ylim = ylim(3:4);
axis([g_ctmGUI.xLims ylim]);
%xlabel('Post mile');
ylabel('Flow (vph)');
end
return;