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

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

% Last Modified by GUIDE v2.5 04-Oct-2006 11:56:21

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @iofpGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @iofpGUI_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 iofpGUI is made visible.
function iofpGUI_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 iofpGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes iofpGUI 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 'orpGUI' is initiated from 'ctmGUI'
global g_iofpGUI;

g_iofpGUI.configFile = g_ctmGUI.configFile;
g_iofpGUI.OK         = 0;

if isfield(g_ctmGUI, 'ifKnob')
  g_iofpGUI.ifKnob = g_ctmGUI.ifKnob;
else
  g_iofpGUI.ifKnob = 1;
end

if isfield(g_ctmGUI, 'ofKnob')
  g_iofpGUI.ofKnob = g_ctmGUI.ofKnob;
else
  g_iofpGUI.ofKnob = 1;
end

set(handles.ifknobTxt, 'String', num2str(g_iofpGUI.ifKnob));
set(handles.ofknobTxt, 'String', num2str(g_iofpGUI.ofKnob));

set(handles.header, 'String', [g_ctmGUI.freeway ' in-, out- flow parameters']);

return;





% --- Outputs from this function are returned to the command line.
function varargout = iofpGUI_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;





% --- 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_iofpGUI;

save_iofknobs(g_iofpGUI);

return;

function save_iofknobs(g_data)

load(g_data.configFile);

configFile = g_data.configFile;
ifKnob     = g_data.ifKnob;
ofKnob     = g_data.ofKnob;

clear g_data;

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

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)

iofpGUIclose;

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_iofpGUI;

g_iofpGUI.OK = 1;

iofpGUIclose;

return;




% --- Executes during object creation, after setting all properties.
function ifknobTxt_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ifknobTxt (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 ifknobTxt_Callback(hObject, eventdata, handles)
% hObject    handle to ifknobTxt (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 ifknobTxt as text
%        str2double(get(hObject,'String')) returns contents of ifknobTxt as a double

global g_iofpGUI;

v = str2double(get(hObject, 'String'));

if v >= 0
  g_iofpGUI.ifKnob = v;
else
  set(hObject, 'String', num2str(g_iofpGUI.ifKnob));
end

return;



% --- Executes during object creation, after setting all properties.
function ofknobTxt_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ofknobTxt (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 ofknobTxt_Callback(hObject, eventdata, handles)
% hObject    handle to ofknobTxt (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 ofknobTxt as text
%        str2double(get(hObject,'String')) returns contents of ofknobTxt as a double

global g_iofpGUI;

v = str2double(get(hObject, 'String'));

if v >= 0
  g_iofpGUI.ofKnob = v;
else
  set(hObject, 'String', num2str(g_iofpGUI.ofKnob));
end

return;

Contact us at files@mathworks.com