Code covered by the BSD License  

Highlights from
CTMSIM - an interactive freeway traffic macrosimulator

image thumbnail
from CTMSIM - an interactive freeway traffic macrosimulator by Alex Kurzhanskiy
Freeway traffic simulation based on Asymmetric Cell Transmission Model

prmGUI(varargin)
function varargout = prmGUI(varargin)
% PRMGUI M-file for prmGUI.fig
%      PRMGUI, by itself, creates a new PRMGUI or raises the existing
%      singleton*.
%
%      H = PRMGUI returns the handle to a new PRMGUI or the handle to
%      the existing singleton*.
%
%      PRMGUI('Property','Value',...) creates a new PRMGUI using the
%      given property value pairs. Unrecognized properties are passed via
%      varargin to prmGUI_OpeningFcn.  This calling syntax produces a
%      warning when there is an existing singleton*.
%
%      PRMGUI('CALLBACK') and PRMGUI('CALLBACK',hObject,...) call the
%      local function named CALLBACK in PRMGUI.M with the given input
%      arguments.
%
%      *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 prmGUI

% Last Modified by GUIDE v2.5 15-Nov-2006 14:56:44

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @prmGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @prmGUI_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 prmGUI is made visible.
function prmGUI_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   unrecognized PropertyName/PropertyValue pairs from the
%            command line (see VARARGIN)

% Choose default command line output for prmGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes prmGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);

global g_ctmGUI;
global g_prmGUI;

g_prmGUI.OK         = 0;
g_prmGUI.configFile = g_ctmGUI.configFile;
g_prmGUI.TS         = g_ctmGUI.TS;
g_prmGUI.plotTS     = g_ctmGUI.TS * g_ctmGUI.plotPeriod;
g_prmGUI.timeout    = g_ctmGUI.timeout;

minl                = min(get_cell_lengths(g_ctmGUI.cellData));
maxv                = max(get_ff_speeds(g_ctmGUI.cellData));
g_prmGUI.limTS      = (minl / maxv) - eps;

set(handles.txtTS, 'String', num2str(g_prmGUI.TS));
set(handles.txtPP, 'String', num2str(g_prmGUI.plotTS));
set(handles.txtTimeout, 'String', num2str(g_prmGUI.timeout));

return;

% --- Outputs from this function are returned to the command line.
function varargout = prmGUI_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
return;





% ---------------------------------------------------------------
% Text fields
% ---------------------------------------------------------------

% Sampling period
function txtTS_CreateFcn(hObject, eventdata, handles)
return;
function txtTS_Callback(hObject, eventdata, handles)
global g_prmGUI;

v = eval(get(hObject, 'String'));
if ~(v >= 0) | (v > min([g_prmGUI.plotTS g_prmGUI.limTS]))
  v = g_prmGUI.TS;
end
set(hObject, 'String', num2str(v));
g_prmGUI.TS = v;

return;


% Plotting period
function txtPP_CreateFcn(hObject, eventdata, handles)
return;
function txtPP_Callback(hObject, eventdata, handles)
global g_prmGUI;

v = eval(get(hObject, 'String'));
if ~(v >= 0) | (v < g_prmGUI.TS)
  v = g_prmGUI.plotTS;
end
set(hObject, 'String', num2str(v));
g_prmGUI.plotTS = v;

return;


% Timeout
function txtTimeout_CreateFcn(hObject, eventdata, handles)
return;
function txtTimeout_Callback(hObject, eventdata, handles)
global g_prmGUI;

v = eval(get(hObject, 'String'));
if ~(v >= 0)
  v = g_prmGUI.timeout;
end
set(hObject, 'String', num2str(v));
g_prmGUI.timeout = v;

return;





% ---------------------------------------------------------------
% Buttons
% ---------------------------------------------------------------

% SAVE
function saveButton_Callback(hObject, eventdata, handles)
global g_prmGUI;

l_saveSettings(g_prmGUI);

return;


% CANCEL
function cancelButton_Callback(hObject, eventdata, handles)

prmGUIclose;

return;


% OK
function okButton_Callback(hObject, eventdata, handles)
global g_prmGUI;

g_prmGUI.OK = 1;
prmGUIclose;

return;





% ---------------------------------------------------------------
% Miscellaneous
% ---------------------------------------------------------------

function l_saveSettings(ss)
% Save simulation settings

load(ss.configFile);

TS         = ss.TS;
plotTS     = ss.plotTS;
timeout    = ss.timeout;
configFile = ss.configFile;

clear ss;

if str2num(version('-release')) >= 14
  feval(@save, '-v6', configFile);
else
  feval(@save, configFile);
end

return;

Contact us at files@mathworks.com