%% Create Data Objects for Code Generation with Data Object Wizard
% To specify code generation options for signal lines, block parameters,
% and states in a model, you can use data objects that you store in a
% workspace or data dictionary. For basic information about data objects,
% see <docid:simulink_ug.f14-90636 Data Objects>.  
% 
% You can use the Data Object Wizard to create data objects for:
%
% * New or existing models that do not use data objects.
% * Existing models to which you have added signal lines or blocks.
%
% This example shows how to use the Data Object Wizard to create and
% configure data objects for code generation from the built-in package
% |Simulink|. 
%% Create Data Objects
% Open the example model <matlab:rtwdemo_configinterface |rtwdemo_configinterface|>.
%
%   open_system('rtwdemo_configinterface')
open_system('rtwdemo_configinterface')
%%
% The model creates numeric variables in the base workspace. Blocks in the
% model use these variables to set parameter values (such as the *Gain*
% parameter of a Gain block). Some of the signals and block states in the
% model have explicit names, such as |input1|.
% 
% On the *Modeling* tab, under *Design*, click *Data Object Wizard*.
% 
% <<../dow_select_model.png>>
%
% In the Data Object Wizard, click *Find*. The wizard proposes the creation
% of |Simulink.Parameter| objects to replace the variables and the creation
% of |Simulink.Signal| objects to represent the signals and states.
%
% <<../dow_find_data.png>>
%
% The wizard finds only signals, parameters, data stores, and states whose
% storage class is set to |Auto|. For example, if you use the Signal
% Properties dialog box to specify a storage class other than |Auto| for a
% signal line, the wizard does not propose a data object.
% 
% Click *Select All*.
%
% Click *Create*. The data objects appear in the base workspace.
% 
% For detailed information about the options that you can choose in the
% Data Object Wizard, see <docid:simulink_ug.bqgy1ty Create Data Objects for a Model Using Data Object Wizard>.
%% Set Storage Class for Data Objects
% Storage classes determine how the generated code uses variables to
% represent signals, parameters, and states. For data objects from the
% built-in package |Simulink|, the default storage class is |Auto|. 
% To specify storage classes for the new data objects, use the
% Model Explorer.
% 
% Open the Model Explorer.
%
% In the *Model Hierarchy* pane, select *Base Workspace*.
% 
% <<../setDataObjectProperty1.png>>
%
% In the *Contents* pane, from the drop-down list *Column View*, select
% |Storage Class|.
%
% Select all of the new data objects. For example, select the object |input1|,
% hold *Shift*, and select the object |X|.
% 
% Set the property |StorageClass| for all of the data objects to
% |ExportToFile|. To change the storage class for all of the selected
% objects, in the *StorageClass* column, click any of the objects. In the
% drop-down list, select |ExportToFile|. The change that you make
% propagates to all of the selected objects.
% 
% Specify the |HeaderFile| property for all of the objects as
% |myExportedHdrFile.h|.
% 
% In the model, set *Configuration Parameters > Code Generation > System
% target file* to |ert.tlc|. With this setting, the code generator honors
% storage classes such as |ExportToFile|.

X = Simulink.Signal;
X.CoderInfo.StorageClass = 'Custom';
X.CoderInfo.Alias = '';
X.CoderInfo.Alignment = -1;
X.CoderInfo.CustomStorageClass = 'ExportToFile';
X.CoderInfo.CustomAttributes.HeaderFile = 'myExportedHdrFile';
X.CoderInfo.CustomAttributes.Owner = '';
X.CoderInfo.CustomAttributes.DefinitionFile = '';
X.CoderInfo.CustomAttributes.ConcurrentAccess = false;
X.Description = '';
X.DataType = 'double';
X.Min = [];
X.Max = [];
X.DocUnits = '';
X.Dimensions = 1;
X.DimensionsMode = 'auto';
X.Complexity = 'auto';
X.SampleTime = -1;
X.InitialValue = '';



mode = Simulink.Signal;
mode.CoderInfo.StorageClass = 'Auto';
mode.Description = '';
mode.DataType = 'boolean';
mode.Min = [];
mode.Max = [];
mode.DocUnits = '';
mode.Dimensions = 1;
mode.DimensionsMode = 'auto';
mode.Complexity = 'auto';
mode.SampleTime = -1;
mode.InitialValue = '';

set_param('rtwdemo_configinterface','SignalResolutionControl','TryResolveAll')
evalc('disableimplicitsignalresolution(''rtwdemo_configinterface'');');

%% Generate and Inspect Code
% Generate code from the model.
rtwbuild('rtwdemo_configinterface')
%%
% In the code generation report, view the generated file
% |myExportedHdrFile.h|. The file contains |extern| declarations for the
% global variables that correspond to the data objects.
file = fullfile('slprj','ert','_sharedutils','myExportedHdrFile.h');
rtwdemodbtype(file,'/* Exported data declaration */',...
    '/* RTW_HEADER_myExportedHdrFile_h_ */',1,0)
%%
% View the file |rtwdemo_configinterface.c|. The file contains the definitions for
% the global variables. The code assigns numeric values for the variables
% that correspond to parameter objects.
file = fullfile('rtwdemo_configinterface_ert_rtw','rtwdemo_configinterface.c');
rtwdemodbtype(file,'/* Exported data definition */',...
    '/* ConstVolatile memory section */',1,0)

%% 
% Copyright 2012 The MathWorks, Inc.