%% Generate Variant Control Macros in Same Header File
% This example shows how to aggregate multiple variant control macros (|#define|)
% into the same generated header file. This aggregation makes it easier for
% you to manage the complexities inherent in a system with multiple
% interacting variant conditions. 
%% Explore Example Model
% Run the script |prepare_rtwdemo_preproc_subsys|, which opens the model
% |rtwdemo_preprocessor_subsys| and prepares it for this example.
run(fullfile(matlabroot,'examples','ecoder','main','prepare_rtwdemo_preproc_subsys'));
%%
% The model contains two Variant Subsystem blocks.
%
% Navigate inside the variant subsystems. The subsystems each have a linear and
% a nonlinear algorithm variant.
% 
% At the root level of the model, open the block dialog box of the variant
% subsystem labeled |LeftController|. The algorithm variants in the subsystem activate based on
% the states of two |Simulink.Variant| objects, |LINEAR| and |NONLINEAR|, in the
% base workspace. 
%
% The state of each object depends on the values of two
% variant control variables, |MODE_A| and |MODE_B|, which are
% |Simulink.Parameter| objects in the base workspace. The parameter objects
% use the custom storage class |Define| and are configured to appear in the
% generated code as C-code macros in |macros.h|.
%% Change Name of Generated Header File Through Model Data Editor
% In this example, change the name of the generated header file from |macros.h| to
% |variant_controls.h|. You must change the file name in each parameter
% object.
%
% In the model, select *Modeling > Model Data Editor*.
%
% In the Model Data Editor, select the *Parameters* tab.
%
% Click the *Show/refresh additional information* button.
%
% Set the *Change view* drop-down list to |Code|.
%
% In the *Filter contents* box, enter |MODE|. The Model Data Editor shows
% two rows that correspond to the parameter objects.
%
% Select both rows. Then, for one of the rows, use the *Header File* column to change the header
% file name from |macros.h| to |variant_controls.h|. The Model Data Editor
% applies the change to both rows.
%% Reduce Maintenance Effort by Creating Custom Storage Class
% To change the name of the header file, you must change the configuration
% of each parameter object. You can use the Model Data Editor to perform
% batch editing, but when you add a new variant control variable (parameter
% object), you must remember to specify the name of the header file for
% that object. Also, the Model Data Editor shows the parameter objects
% used by only one model at a time.
%
% Instead, you can create a custom storage class and specify the name of the header file
% only once: In the definition of the custom storage class.
%
% Set your current folder to a writable location.
%
% At the command prompt, copy the built-in |SimulinkDemos| package into
% your current folder as |myPackage|.
copyfile(fullfile(matlabroot,...
    'toolbox','simulink','simdemos','dataclasses','+SimulinkDemos'),...
    '+myPackage','f')
%%
% Navigate inside the |+myPackage| folder to the file |Parameter.m| and
% open the file.
%
% Uncomment the |methods| section that defines the method |setupCoderInfo|.
% In the call to the function |useLocalCustomStorageClasses|, replace
% |'packageName'| with |'myPackage'|. When you finish, the section appears
% as follows:
%
% <include>myPackage_preproc_supp.m</include>
%
% Save and close the file.
%
% Set your current folder to the folder that contains the package
% |myPackage|.
%
% Open the Custom Storage Class Designer.
cscdesigner('myPackage')
%%
% Select the custom storage class |Define|.
%
% Click *Copy*. A new custom storage class, |Define_1|, appears. Select
% this new custom storage class.
%
% Set *Name* to |VariantControlVar|.
%
% Set *Header file* to |Specify|. In the text box, enter
% |variant_controls.h|.
%
% Click *Apply*, *Save*, and *OK*.
%
% At the command prompt, replace the |Simulink.Parameter| objects |MODE_A| and
% |MODE_B| with |myPackage.Parameter| objects. Apply the new custom storage
% class |VariantControlVar|.
%
% <include>mode_change_supp.m</include>
%
% Now, to indicate that a parameter object represents a variant control
% variable, you can apply the custom storage class |VariantControlVar|. To
% change the name of the header file, use the Custom Storage Class
% Designer.


%% 
% Copyright 2012 The MathWorks, Inc.