%% Import Parameter Data with Conditionally Compiled Dimension Length
% Suppose your external code conditionally allocates memory for and
% initializes lookup table and breakpoint set data based on a dimension length that you specify
% as a |#define| macro. This example shows how to generate code that
% imports 
% this external global data. 
%% Create External Code Files
% Save the definition of the breakpoint set data |T1Break| and lookup table
% data |T1Data| in your current folder in a file called
% |ex_vec_symdim_src.c|. These global variables have either 9 or 11
% elements
% depending on the value of the macro |bpLen|.
%
% <include>ex_vec_symdim_src.c</include>
%
% Save the declarations of the variables and the definition of the macro in
% your current folder in file |ex_vec_symdim_decs.h|.
%
% <include>ex_vec_symdim_decs.h</include>
%% Explore and Configure Example Model
% Open the example model |rtwdemo_configinterface|.
open_system('rtwdemo_configinterface')
set_param('rtwdemo_configinterface/Table1','DataSpecification','Table and breakpoints');
%%
% Open the Table1 block dialog box. The block refers to
% variables, |T1Data| and |T1Break|, in the model
% workspace. These variables store the lookup table and breakpoint set
% data with 11 elements.
%
% At the command prompt, convert the variables to |Simulink.Parameter|
% objects.
mws = get_param('rtwdemo_configinterface','modelworkspace');
T1Data = mws.getVariable('T1Data');
T1Break = mws.getVariable('T1Break');
T1Data = Simulink.Parameter(T1Data);
T1Break = Simulink.Parameter(T1Break);

%%
% At the command prompt, create a |Simulink.Parameter| object to represent
% the custom macro |bpLen|.
bpLen = Simulink.Parameter(11);
bpLen.Min = 9;
bpLen.Max = 11;
bpLen.DataType = 'int32';
bpLen.CoderInfo.StorageClass = 'Custom';
bpLen.CoderInfo.CustomStorageClass = 'ImportedDefine';
bpLen.CoderInfo.CustomAttributes.HeaderFile = 'ex_vec_symdim_decs.h';
%%
% Use |bpLen| to set the dimensions of the lookup table and breakpoint set
% data. Configure the model to enable symbolic dimensions by selecting the
% configuration parameter *Allow symbolic dimension specification*.
T1Data.Dimensions = '[1 bpLen]';
T1Break.Dimensions = '[1 bpLen]';
set_param('rtwdemo_configinterface','AllowSymbolicDim','on');
%%
% Set *Configuration Parameters > Code Generation > Custom Code >
% Additional build information > Source files* to |ex_vec_symdim_src.c|.
set_param('rtwdemo_configinterface','CustomSource','ex_vec_symdim_src.c')
%%
% Configure the objects to import the data
% definitions from your external code.
mws.assignin('T1Data',T1Data);
mws.assignin('T1Break',T1Break);
cm = coder.mapping.utils.create('rtwdemo_configinterface');
setDataDefault(cm,'ModelParameters','StorageClass','Default');
setModelParameter(cm,'Table1','StorageClass','Model default');
setModelParameter(cm,'Table2','StorageClass','Model default');
setModelParameter(cm,'T1Data','StorageClass','ImportFromFile','HeaderFile','ex_vec_symdim_decs.h');
setModelParameter(cm,'T1Break','StorageClass','ImportFromFile','HeaderFile','ex_vec_symdim_decs.h');
%% Generate and Inspect Code
% Generate code from the model.
%
% The generated code algorithm is in the model |step| function in the
% generated file |rtwdemo_configinterface.c|. The algorithm passes |T1Break|, |T1Data|, and |bpLen|
% as argument values to the function that performs the table lookup. In
% this case, |bpLen| controls the upper bound of the binary search that the
% function uses.
%
% For more information about symbolic dimensions, see <docid:ecoder_ug.bu3c8bh-1 Implement Dimension Variants for Array Sizes in Generated Code>.

%% 
% Copyright 2012 The MathWorks, Inc.