%% Place Global Data Declarations and Definitions in Separate Files
% These examples show how to control the file placement of data items (signals, parameters, and states) to which
% you apply storage classes. 
%% Place Multiple Data Items in Single File by Default
% By default, the declarations and definitions generated for individual
% data items typically appear in the model source file. This example shows
% how to modularize the code by placing these global data in a separate
% file.
%
% Open the example model <matlab:rtwdemo_configinterface |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|.
% 
% # In the Simulink Editor, in the *Modeling* tab, under *Design*, click *Data Object Wizard*.
% # In the Data Object Wizard, click *Find*. The Data Object Wizard
% proposes the creation of |Simulink.Parameter| objects to replace the
% workspace variables and the creation of |Simulink.Signal| objects to
% represent the named signals and states.
% # Click *Select All* and *Create*. The Data Object Wizard creates the
% data objects in the base workspace. You can use these objects to specify
% code generation settings for the corresponding signals, parameters, and
% states in the model.
% # In the Model Explorer *Model Hierarchy* pane, select *Base Workspace*.
% # In the *Contents* pane, set *Column View* to |Storage Class|.
% # For all of the data objects, use the *StorageClass* column to apply the
% storage class |ExportedGlobal|. With this storage class, each data
% object appears in the generated code as a separate global variable.
% # Specify that global data items be defined in a separate file. Set
% *Configuration Parameters > Code Generation > Code Placement > Data
% definition* to |Data defined in a single separate source file|. Accept
% the default for *Data definition filename*, |global.c|.
% # Specify that data be declared in a separate file. Set *Data
% declaration* to |Data declared in a single separate header file| and
% accept the default for *Data declaration filename*, |global.h|. Then,
% click *Apply*.
% # Generate code from the model. Notice that the code generation report
% lists |global.c| and |global.h| files.
% # Inspect the code generation report. Notice that:
%
% * The global data are defined and, for parameters, initialized in
% |global.c|.
% * The file |rtwdemo_configinterface.c| includes |(#include)| |rtwdemo_configinterface.h|.
% * The file |rtwdemo_configinterface.h| includes |global.h|.
%% Place Each Data Item in Individual File
% In the previous example, you place global data in a separate definition
% file and a declaration file. You name the files |global.c| and
% |global.h|. You can override this specification and place each individual
% data item in its own file. In this example, move the |output| signal to a
% file named |outputsig.c|. Keep the other data defined in |global.c|.
%
% # In your current folder, delete the |slprj| subfolder.
% # In the Model Explorer, display the base workspace and select the
% |X| signal object. The *Simulink.Signal* properties appear in the
% right pane.
% # In the *Code generation options* section, set *Storage class* to
% |ExportToFile|. Set *HeaderFile* to |outputsig.h| and *DefinitionFile* to
% |outputsig.c|. Click *Apply*.
% # Generate code from the model. The code generation report still lists
% |global.c| and |global.h|, but adds |outputsig.c| and |outputsig.h|.
% # Inspect the new files. The |output| signal is defined in |outputsig.c|.
% Other data are still defined in |global.c|.

%% 
% Copyright 2012 The MathWorks, Inc.