function varargout = fdGUI(varargin)
% FDGUI M-file for fdGUI.fig
% FDGUI, by itself, creates a new FDGUI or raises the existing
% singleton*.
%
% H = FDGUI returns the handle to a new FDGUI or the handle to
% the existing singleton*.
%
% FDGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FDGUI.M with the given input arguments.
%
% FDGUI('Property','Value',...) creates a new FDGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before fdGUI_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to fdGUI_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help fdGUI
% Last Modified by GUIDE v2.5 13-Oct-2006 16:31:42
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @fdGUI_OpeningFcn, ...
'gui_OutputFcn', @fdGUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before fdGUI is made visible.
function fdGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to fdGUI (see VARARGIN)
% Choose default command line output for fdGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes fdGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% First, we shall copy all necessary data from the global 'g_ctmGUI' structure
global g_ctmGUI; % MUST (!) exist - the call to 'fdGUI' is initiated from 'ctmGUI'
global g_fdGUI;
g_fdGUI.configFile = g_ctmGUI.configFile;
g_fdGUI.cellData = g_ctmGUI.cellData;
g_fdGUI.pmData = g_ctmGUI.pmData;
g_fdGUI.freeway = g_ctmGUI.freeway;
xmin = g_fdGUI.cellData(1).PMstart;
xmax = g_fdGUI.cellData(end).PMend;
if xmin <= xmax
g_fdGUI.xLims = [xmin xmax];
else
g_fdGUI.xLims = [xmax xmin];
end
g_fdGUI.OK = 0;
set(handles.header, 'String', [g_fdGUI.freeway ' fundamental diagram']);
set(handles.cellList, 'String', get_cell_list(g_fdGUI.cellData));
set(handles.rhocText, 'String', num2str(g_fdGUI.cellData(1).FDrhocrit));
set(handles.rhojText, 'String', num2str(g_fdGUI.cellData(1).FDrhojam));
set(handles.fmaxText, 'String', num2str(g_fdGUI.cellData(1).FDfmax));
vv = g_fdGUI.cellData(1).FDfmax / g_fdGUI.cellData(1).FDrhocrit;
wv = g_fdGUI.cellData(1).FDfmax / (g_fdGUI.cellData(1).FDrhojam - g_fdGUI.cellData(1).FDrhocrit);
set(handles.vTxt, 'String', num2str(vv));
set(handles.wTxt, 'String', num2str(wv));
axes(handles.direction)
if g_fdGUI.pmData(1) <= g_fdGUI.pmData(end)
image(imread('lr.jpg'));
else
image(imread('rl.jpg'));
end
axis off;
axes(handles.rhoCJ);
dc = get_critical_densities(g_fdGUI.cellData);
dc = [dc' dc(end, 1)];
dj = get_jam_densities(g_fdGUI.cellData);
dj = [dj' dj(end, 1)];
plot(g_fdGUI.pmData, dc, '-bd');
hold on;
plot(g_fdGUI.pmData, dj, '-md');
lims = axis;
axis([g_fdGUI.xLims lims(3:4)]);
xlabel('Post mile');
ylabel('Densities (vpm)');
legend('critical', 'jam');
plot(g_fdGUI.pmData(1:2), dc(1:2), 'b', 'LineWidth', 3);
plot(g_fdGUI.pmData(1:2), dj(1:2), 'm', 'LineWidth', 3);
axis([g_fdGUI.xLims lims(3:4)]);
hold off;
axes(handles.flowM);
fm = get_max_flows(g_fdGUI.cellData);
fm = [fm' fm(end, 1)];
plot(g_fdGUI.pmData, fm, '-kd');
hold on;
plot(g_fdGUI.pmData(1:2), fm(1:2), 'k', 'LineWidth', 3);
lims = axis;
axis([g_fdGUI.xLims lims(3:4)]);
xlabel('Post mile');
ylabel('Maximal flows (vph)');
hold off;
axes(handles.FD);
plotfd(g_fdGUI.cellData, 1); % plot FD for the first cell
return;
% --- Outputs from this function are returned to the command line.
function varargout = fdGUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
return;
% --- Executes during object creation, after setting all properties.
function rhocText_CreateFcn(hObject, eventdata, handles)
% hObject handle to rhocText (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
function rhocText_Callback(hObject, eventdata, handles)
% hObject handle to rhocText (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of rhocText as text
% str2double(get(hObject,'String')) returns contents of rhocText as a double
global g_fdGUI;
indx = get(handles.cellList, 'Value');
val = str2double(get(hObject, 'String'));
if (val >= 0) & (val <= g_fdGUI.cellData(indx).FDrhojam)
g_fdGUI.cellData(indx).FDrhocrit = val;
else
set(handles.rhocText, 'String', num2str(g_fdGUI.cellData(indx).FDrhocrit));
end
vv = g_fdGUI.cellData(indx).FDfmax / g_fdGUI.cellData(indx).FDrhocrit;
wv = g_fdGUI.cellData(indx).FDfmax / (g_fdGUI.cellData(indx).FDrhojam - g_fdGUI.cellData(indx).FDrhocrit);
set(handles.vTxt, 'String', num2str(vv));
set(handles.wTxt, 'String', num2str(wv));
axes(handles.rhoCJ);
dc = get_critical_densities(g_fdGUI.cellData);
dc = [dc' dc(end, 1)];
dj = get_jam_densities(g_fdGUI.cellData);
dj = [dj' dj(end, 1)];
plot(g_fdGUI.pmData, dc, '-bd');
hold on;
plot(g_fdGUI.pmData, dj, '-md');
lims = axis;
axis([g_fdGUI.xLims lims(3:4)]);
xlabel('Post mile');
ylabel('Densities (vpm)');
legend('critical', 'jam');
plot(g_fdGUI.pmData(indx:indx+1), dc(indx:indx+1), 'b', 'LineWidth', 3);
plot(g_fdGUI.pmData(indx:indx+1), dj(indx:indx+1), 'm', 'LineWidth', 3);
axis([g_fdGUI.xLims lims(3:4)]);
hold off;
axes(handles.flowM);
fm = get_max_flows(g_fdGUI.cellData);
fm = [fm' fm(end, 1)];
plot(g_fdGUI.pmData, fm, '-kd');
hold on;
plot(g_fdGUI.pmData(indx:indx+1), fm(indx:indx+1), 'k', 'LineWidth', 3);
lims = axis;
axis([g_fdGUI.xLims lims(3:4)]);
xlabel('Post mile');
ylabel('Maximal flows (vph)');
hold off;
axes(handles.FD);
plotfd(g_fdGUI.cellData, indx);
return;
% --- Executes during object creation, after setting all properties.
function rhojText_CreateFcn(hObject, eventdata, handles)
% hObject handle to rhojText (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
function rhojText_Callback(hObject, eventdata, handles)
% hObject handle to rhojText (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of rhojText as text
% str2double(get(hObject,'String')) returns contents of rhojText as a double
global g_fdGUI;
indx = get(handles.cellList, 'Value');
val = str2double(get(hObject, 'String'));
if val >= g_fdGUI.cellData(indx).FDrhocrit
g_fdGUI.cellData(indx).FDrhojam = val;
else
set(handles.rhojText, 'String', num2str(g_fdGUI.cellData(indx).FDrhojam));
end
wv = g_fdGUI.cellData(indx).FDfmax / (g_fdGUI.cellData(indx).FDrhojam - g_fdGUI.cellData(indx).FDrhocrit);
set(handles.wTxt, 'String', num2str(wv));
axes(handles.rhoCJ);
dc = get_critical_densities(g_fdGUI.cellData);
dc = [dc' dc(end, 1)];
dj = get_jam_densities(g_fdGUI.cellData);
dj = [dj' dj(end, 1)];
plot(g_fdGUI.pmData, dc, '-bd');
hold on;
plot(g_fdGUI.pmData, dj, '-md');
lims = axis;
axis([g_fdGUI.xLims lims(3:4)]);
xlabel('Post mile');
ylabel('Densities (vpm)');
legend('critical', 'jam');
plot(g_fdGUI.pmData(indx:indx+1), dc(indx:indx+1), 'b', 'LineWidth', 3);
plot(g_fdGUI.pmData(indx:indx+1), dj(indx:indx+1), 'm', 'LineWidth', 3);
axis([g_fdGUI.xLims lims(3:4)]);
hold off;
axes(handles.flowM);
fm = get_max_flows(g_fdGUI.cellData);
fm = [fm' fm(end, 1)];
plot(g_fdGUI.pmData, fm, '-kd');
hold on;
plot(g_fdGUI.pmData(indx:indx+1), fm(indx:indx+1), 'k', 'LineWidth', 3);
lims = axis;
axis([g_fdGUI.xLims lims(3:4)]);
xlabel('Post mile');
ylabel('Maximal flows (vph)');
hold off;
axes(handles.FD);
plotfd(g_fdGUI.cellData, indx);
return;
% --- Executes during object creation, after setting all properties.
function fmaxText_CreateFcn(hObject, eventdata, handles)
% hObject handle to fmaxText (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
function fmaxText_Callback(hObject, eventdata, handles)
% hObject handle to fmaxText (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of fmaxText as text
% str2double(get(hObject,'String')) returns contents of fmaxText as a double
global g_fdGUI;
indx = get(handles.cellList, 'Value');
val = str2double(get(hObject, 'String'));
if val >= 0
g_fdGUI.cellData(indx).FDfmax = val;
else
set(handles.fmaxText, 'String', num2str(g_fdGUI.cellData(indx).FDfmax));
end
vv = g_fdGUI.cellData(indx).FDfmax / g_fdGUI.cellData(indx).FDrhocrit;
wv = g_fdGUI.cellData(indx).FDfmax / (g_fdGUI.cellData(indx).FDrhojam - g_fdGUI.cellData(indx).FDrhocrit);
set(handles.vTxt, 'String', num2str(vv));
set(handles.wTxt, 'String', num2str(wv));
axes(handles.rhoCJ);
dc = get_critical_densities(g_fdGUI.cellData);
dc = [dc' dc(end, 1)];
dj = get_jam_densities(g_fdGUI.cellData);
dj = [dj' dj(end, 1)];
plot(g_fdGUI.pmData, dc, '-bd');
hold on;
plot(g_fdGUI.pmData, dj, '-md');
lims = axis;
axis([g_fdGUI.xLims lims(3:4)]);
xlabel('Post mile');
ylabel('Densities (vpm)');
legend('critical', 'jam');
plot(g_fdGUI.pmData(indx:indx+1), dc(indx:indx+1), 'b', 'LineWidth', 3);
plot(g_fdGUI.pmData(indx:indx+1), dj(indx:indx+1), 'm', 'LineWidth', 3);
axis([g_fdGUI.xLims lims(3:4)]);
hold off;
axes(handles.flowM);
fm = get_max_flows(g_fdGUI.cellData);
fm = [fm' fm(end, 1)];
plot(g_fdGUI.pmData, fm, '-kd');
hold on;
plot(g_fdGUI.pmData(indx:indx+1), fm(indx:indx+1), 'k', 'LineWidth', 3);
lims = axis;
axis([g_fdGUI.xLims lims(3:4)]);
xlabel('Post mile');
ylabel('Maximal flows (vph)');
hold off;
axes(handles.FD);
plotfd(g_fdGUI.cellData, indx);
return;
% --- Executes during object creation, after setting all properties.
function cellList_CreateFcn(hObject, eventdata, handles)
% hObject handle to cellList (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
% --- Executes on selection change in cellList.
function cellList_Callback(hObject, eventdata, handles)
% hObject handle to cellList (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns cellList contents as cell array
% contents{get(hObject,'Value')} returns selected item from cellList
global g_fdGUI;
indx = get(hObject, 'Value');
set(handles.rhocText, 'String', num2str(g_fdGUI.cellData(indx).FDrhocrit));
set(handles.rhojText, 'String', num2str(g_fdGUI.cellData(indx).FDrhojam));
set(handles.fmaxText, 'String', num2str(g_fdGUI.cellData(indx).FDfmax));
vv = g_fdGUI.cellData(indx).FDfmax / g_fdGUI.cellData(indx).FDrhocrit;
wv = g_fdGUI.cellData(indx).FDfmax / (g_fdGUI.cellData(indx).FDrhojam - g_fdGUI.cellData(indx).FDrhocrit);
set(handles.vTxt, 'String', num2str(vv));
set(handles.wTxt, 'String', num2str(wv));
axes(handles.rhoCJ);
dc = get_critical_densities(g_fdGUI.cellData);
dc = [dc' dc(end, 1)];
dj = get_jam_densities(g_fdGUI.cellData);
dj = [dj' dj(end, 1)];
plot(g_fdGUI.pmData, dc, '-bd');
hold on;
plot(g_fdGUI.pmData, dj, '-md');
lims = axis;
axis([g_fdGUI.xLims lims(3:4)]);
xlabel('Post mile');
ylabel('Densities (vpm)');
legend('critical', 'jam');
plot(g_fdGUI.pmData(indx:indx+1), dc(indx:indx+1), 'b', 'LineWidth', 3);
plot(g_fdGUI.pmData(indx:indx+1), dj(indx:indx+1), 'm', 'LineWidth', 3);
axis([g_fdGUI.xLims lims(3:4)]);
hold off;
axes(handles.flowM);
fm = get_max_flows(g_fdGUI.cellData);
fm = [fm' fm(end, 1)];
plot(g_fdGUI.pmData, fm, '-kd');
hold on;
plot(g_fdGUI.pmData(indx:indx+1), fm(indx:indx+1), 'k', 'LineWidth', 3);
lims = axis;
axis([g_fdGUI.xLims lims(3:4)]);
xlabel('Post mile');
ylabel('Maximal flows (vph)');
hold off;
axes(handles.FD);
plotfd(g_fdGUI.cellData, indx);
return;
% --- Executes on button press in saveButton.
function saveButton_Callback(hObject, eventdata, handles)
% hObject handle to saveButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global g_fdGUI;
save_fd(g_fdGUI.cellData, g_fdGUI.configFile);
return;
% --- Executes on button press in cancelButton.
function cancelButton_Callback(hObject, eventdata, handles)
% hObject handle to cancelButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fdGUIclose;
return;
% --- Executes on button press in okButton.
function okButton_Callback(hObject, eventdata, handles)
% hObject handle to okButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global g_fdGUI;
g_fdGUI.OK = 1;
fdGUIclose;
return;
% --- Executes during object creation, after setting all properties.
function vTxt_CreateFcn(hObject, eventdata, handles)
% hObject handle to vTxt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
function vTxt_Callback(hObject, eventdata, handles)
% hObject handle to vTxt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of vTxt as text
% str2double(get(hObject,'String')) returns contents of vTxt as a double
global g_fdGUI;
indx = get(handles.cellList, 'Value');
val = str2double(get(hObject, 'String'));
if ~(val > 0)
val = g_fdGUI.cellData(indx).FDfmax / g_fdGUI.cellData(indx).FDrhocrit;
set(handles.vTxt, 'String', num2str(val));
end
g_fdGUI.cellData(indx).FDrhocrit = g_fdGUI.cellData(indx).FDfmax / val;
set(handles.rhocText, 'String', num2str(g_fdGUI.cellData(indx).FDrhocrit));
wv = g_fdGUI.cellData(indx).FDfmax / (g_fdGUI.cellData(indx).FDrhojam - g_fdGUI.cellData(indx).FDrhocrit);
set(handles.wTxt, 'String', num2str(wv));
axes(handles.rhoCJ);
dc = get_critical_densities(g_fdGUI.cellData);
dc = [dc' dc(end, 1)];
dj = get_jam_densities(g_fdGUI.cellData);
dj = [dj' dj(end, 1)];
plot(g_fdGUI.pmData, dc, '-bd');
hold on;
plot(g_fdGUI.pmData, dj, '-md');
lims = axis;
axis([g_fdGUI.xLims lims(3:4)]);
xlabel('Post mile');
ylabel('Densities (vpm)');
legend('critical', 'jam');
plot(g_fdGUI.pmData(indx:indx+1), dc(indx:indx+1), 'b', 'LineWidth', 3);
plot(g_fdGUI.pmData(indx:indx+1), dj(indx:indx+1), 'm', 'LineWidth', 3);
axis([g_fdGUI.xLims lims(3:4)]);
hold off;
axes(handles.flowM);
fm = get_max_flows(g_fdGUI.cellData);
fm = [fm' fm(end, 1)];
plot(g_fdGUI.pmData, fm, '-kd');
hold on;
plot(g_fdGUI.pmData(indx:indx+1), fm(indx:indx+1), 'k', 'LineWidth', 3);
lims = axis;
axis([g_fdGUI.xLims lims(3:4)]);
xlabel('Post mile');
ylabel('Maximal flows (vph)');
hold off;
axes(handles.FD);
plotfd(g_fdGUI.cellData, indx);
return;
% --- Executes during object creation, after setting all properties.
function wTxt_CreateFcn(hObject, eventdata, handles)
% hObject handle to wTxt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
function wTxt_Callback(hObject, eventdata, handles)
% hObject handle to wTxt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of wTxt as text
% str2double(get(hObject,'String')) returns contents of wTxt as a double
global g_fdGUI;
indx = get(handles.cellList, 'Value');
val = str2double(get(hObject, 'String'));
if ~(val > 0)
val = g_fdGUI.cellData(indx).FDfmax / (g_fdGUI.cellData(indx).FDrhojam - g_fdGUI.cellData(indx).FDrhocrit);
set(handles.wTxt, 'String', num2str(val));
end
g_fdGUI.cellData(indx).FDrhojam = (g_fdGUI.cellData(indx).FDfmax / val) + g_fdGUI.cellData(indx).FDrhocrit;
set(handles.rhojText, 'String', num2str(g_fdGUI.cellData(indx).FDrhojam));
axes(handles.rhoCJ);
dc = get_critical_densities(g_fdGUI.cellData);
dc = [dc' dc(end, 1)];
dj = get_jam_densities(g_fdGUI.cellData);
dj = [dj' dj(end, 1)];
plot(g_fdGUI.pmData, dc, '-bd');
hold on;
plot(g_fdGUI.pmData, dj, '-md');
lims = axis;
axis([g_fdGUI.xLims lims(3:4)]);
xlabel('Post mile');
ylabel('Densities (vpm)');
legend('critical', 'jam');
plot(g_fdGUI.pmData(indx:indx+1), dc(indx:indx+1), 'b', 'LineWidth', 3);
plot(g_fdGUI.pmData(indx:indx+1), dj(indx:indx+1), 'm', 'LineWidth', 3);
axis([g_fdGUI.xLims lims(3:4)]);
hold off;
axes(handles.flowM);
fm = get_max_flows(g_fdGUI.cellData);
fm = [fm' fm(end, 1)];
plot(g_fdGUI.pmData, fm, '-kd');
hold on;
plot(g_fdGUI.pmData(indx:indx+1), fm(indx:indx+1), 'k', 'LineWidth', 3);
lims = axis;
axis([g_fdGUI.xLims lims(3:4)]);
xlabel('Post mile');
ylabel('Maximal flows (vph)');
hold off;
axes(handles.FD);
plotfd(g_fdGUI.cellData, indx);
return;