%% Copyright (C) 2012, SRI International.  All Rights Reserved.

%% This program is free software; you can redistribute it and/or
%% modify it under the terms of the GNU General Public License
%% as published by the Free Software Foundation; either version 2
%% of the License, or (at your option) any later version.

%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.


%% Define global variables

clc
tic

global mdlPathName;



%% Chose one of the following examples or add the path and name of your example. 

%mdlPathName = '../examples/sldemo_househeat/';
%modelName = 'sldemo_househeat.mdl';

%mdlPathName = '../examples/cruise_ctrl/';
%modelName = 'cruise_ctrl.mdl';
%modelName = 'cruise_ctrl_error.mdl';
%modelName = 'cruise_ctrl_without_dimension.mdl';

%mdlPathName = '../examples/sldemo_clutch/';
%modelName = 'sldemo_clutch_if.mdl';

%mdlPathName = '../examples/sldemo_engine/';
%modelName = 'sldemo_enginewc.mdl';

 
%mdlPathName = '../examples/prb/';
%modelName = 'hybrid_analysis_prb2.mdl';

%mdlPathName = '../examples/cd2d/';
%modelName = 'cd2d.mdl';



%% Open the model and compile the model

eval(['cd ', mdlPathName]);

% Run any matlab script file that is required to run the model
%prb2;       % For prb
%cd2d_par;   % For cd2d

open_system(modelName);
SLDIAGNOSTICS(gcs,'CountBlocks')
eval([get_param(gcs, 'Name'), '([], [], [], ''compile'');']);


%% Run the tool

cd ../../src;
%createGEInputFile(get_param(gcs, 'Name'));
%createDimensionEqualityFile(get_param(gcs, 'Name'));



%% Terminate compilation and close the model.

% If the program crashes, run the following two commands to terminate
% compilation and close the model.
try eval([get_param(gcs, 'Name'), '([], [], [], ''term'');']); catch end
close_system(modelName);


toc