%% Generate C++ Function and Class Code for Export-Function Model 
%
% This example shows how to generate function code for an export-function
% model that includes a function-call subsystem. The code generator produces 
% function and class code that does not include scheduling code.    
%
% To generate function code for export: 
%
% # Create a model that contains the functions for export. 
% # Create a test harness model that schedules execution of the functions
% during simulation.
% # Simulate the model that contains the functions by using the test harness model. 
% # Generate code for the model that contains the functions.
%
%% Create Model That Contains Functions and C++ Class Interface for Export
%
% The model with functions for export with a C++ model class interface must satisfy architectural constraints at 
% the model root level. For C++ class generation, blocks that are valid at the root level are:
%
% * Inport
% * Outport
% * Function-Call Subsystem
% * Goto
% * From
% * Merge 
% 
% *Note:* Export Function-Call Subsystem with C++ class interface does not 
% support Simulink Function blocks. 
% 
% The code generator produces function code for the Function-Call Subsystem block. 
% For a Function-call 
% Subsystem block, you connect the block input ports to root Inport blocks 
% that assert function-call signals.  The subsystem is executed based on the 
% function-call signal that it receives.
% 
% Model |rtwdemo_cppclass_functions| contains function-call subsystems |f1|, 
% |f2|, and |f3| for exporting functions.
open_system('rtwdemo_cppclass_functions')

%% Create Test Harness Model for Simulation
%
% When you export functions, the generated code does not include a scheduler.
% Create a test harness model to handle scheduling during simulation. Do 
% not use the test harness model to generate code that you deploy.
% 
% Model |rtwdemo_cppclass_export_functions| is a test harness.  The model 
% provides function-call signals to other models in this example to schedule 
% the model contents.
open_system('rtwdemo_cppclass_export_functions')

%% Simulate the Test Harness Model
%
% Verify that the model containing the functions that you want to export
% is executed as you expect by simulating the test harness model. For example,
% simulate |rtwdemo_cppclass_export_functions|.
sim('rtwdemo_cppclass_export_functions')

%% Generate Function Code and Report
%
% Generate code and a code generation report for the functions that you want 
% to export. For example, generate code for |rtwdemo_cppclass_functions|. 
rtwbuild('rtwdemo_cppclass_functions')

%% Review Generated Code
% From the code generation report, review the generated code.
%
% * |ert_main.cpp| is an example main program (execution framework) for the
% model. This code shows how to call the exported functions. The code also
% shows how to initialize and execute the generated code.
% * |rtwdemo_cppclass_functions.cpp| calls the initialization function, including
% |Initialize Function|, and exported functions for model subsystem components |f1|,
% |f2|, and |f3|.
% * |rtwdemo_cppclass_functions.h| declares model data structures and a public
% interface to the exported entry-point functions and data structures.
% * |rtwtypes.h| defines data types, structures, and macros that the
% generated code requires.
%
%% Write Interface Code 
% Open and review the Code Interface Report. To write the interface code 
% for your execution framework, use the information in that report.
%
% # Include the generated header files by adding directives 
% |#include rtwdemo_cppclass_functions.h| and |#include rtwtypes.h|.
% # Write input data to the generated code for model Inport blocks.
% # Call the generated entry-point functions.
% # Read data from the generated code for model Outport blocks.
%
% Input ports:
%
% * |rtU.U1| of type |real_T| with dimension 1
% * |rtU.U2| of type |real_T| with dimension 1
% * |rtU.U3| of type |real_T| with dimension 1
%
% Entry-point functions: 
%
% * Initialize entry-point function, |void initialize(void)|. At startup, call this function once.
% * Exported function, |void t_1tic_A(void)|. Call this function as needed.
% * Exported function, |void t_1tic_B(void)|. Call this function as needed.
% * Exported function, |void t_1tic_C(void)|. Call this function as needed.
%
% Output ports:
%
% * |rtY.TicToc1| of type |int8_T| with dimension [2]
% * |rtY.TicToc2| of type |int8_T| with dimension [2]
% * |rtY.TicToc10| of type |int8_T| with dimension 1
%
%% More About
%
% * <docid:ecoder_ug.bqnrwky-1 Generate Component Source Code for Export to External Code Base>
% * <docid:ecoder_ug.br54_tp Deploy Generated Standalone Executable Programs To Target Hardware>
% * <docid:ecoder_ug.f6010dfi4 Customize Code Organization and Format>
% * <docid:ecoder_ug.brre9ro-1 Customize Generated C++ Class Interfaces>
% * <docid:rtw_ug.bukg55s-1 Generate Code for a Simulink Function and Function Caller>

%% Close Example Models 
bdclose('rtwdemo_cppclass_export_functions')
bdclose('rtwdemo_cppclass_functions')


%% 
% Copyright 2012 The MathWorks, Inc.