%% Function Call
% This example shows how to generate a function call by adding a subsystem, 
% which implements the operations that you want.

% Copyright 2018 The MathWorks, Inc.

%% C Construct
% <include>c_construct_func_call.txt</include> 
%% Procedure
% 1. Open example model <matlab:ex_function_call |ex_function_call|>.
open_system('ex_function_call')

%%
% The subsystem has two inputs and returns one output.
open_system('ex_function_call/Add_Subsystem')

%%
% Selecting the *Treat as atomic unit* parameter enables parameters on the
% *Code Generation* tab. The *Code Generation* tab provides these
% customizations:  
%
% * *Function packaging* set to |Nonreusable function|
% * *Function name options* set to |User specified|
% * *Function name* specified as |add_function|
% * *File name options* set to |Use function name|

%%
% 2. To build the model and generate code, press *Ctrl+B*.
evalc('rtwbuild(''ex_function_call'')'); 

%% Results
% In |ex_function_call.c|, the function is called from |ex_function_call_step|:
file = fullfile('ex_function_call_ert_rtw','ex_function_call.c');
rtwdemodbtype(file,'/* Model step function */', ...
    '/* Model initialize function */',1,0);

%%
% The function prototype is externally declared through the subsystem file,
% |add_function.h|:
file = fullfile('ex_function_call_ert_rtw','add_function.h');
rtwdemodbtype(file,'extern void add_function(void);', ...
    '/* RTW_HEADER_add_function_h_ */',1,0);

%%
% The function definition is in the subsystem file |add_function.c|:
file = fullfile('ex_function_call_ert_rtw','add_function.c');
rtwdemodbtype(file,'void add_function(void)', ...
    '}',1,1);




