%% Generate Code using Addition and Subtraction Operator Code Replacement Library
% In this section, you generate code using the code replacement library that you created in the first two sections of this example. 
% The generated code contains the implementation function signature that modifies a addition operator. 
% For this example, the addition operator contains the |Cast before operation| parameter. This example does not provide an implementation function. 
% You should write the implementation function that contains the optimization that you want to see in the generated code.
%   Copyright 2020 The MathWorks, Inc.
%% Example Model
% Open the model |crl_AddSubfunction| for configuring code replacement library.
open_system('crl_AddSubfunction');

copyfile AddSubFnRtwTargetInfo.txt rtwTargetInfo.m
%% 
% Run the MATLAB customization file to create a code replacement table and register the file. The customization file has already be executed for your benefit.   
% Run the sl_refresh_customizations function to register the library.
sl_refresh_customizations;

%% Enable Code Replacement Library
% # Open the Configuration Parameters dialog box.  
% # On the *Interface* pane, set *Code Replacement Library* by clicking *Select* and adding |CRL for Addition and Subtraction operator replacement| to the *Selected code replacement libraries - prioritized* list pane.
% Alternatively, use the command-line API to enable the code replacement:

set_param('crl_AddSubfunction', 'CodeReplacementLibrary', 'CRL for Addition and Subtraction operator replacement');
%%
% Generate code from the model:
evalc('rtwbuild(''crl_AddSubfunction'')');

%%
% View the generated code. Here is a portion of |crl_AddSubfunction.c|.
cfile = fullfile('crl_AddSubfunction_ert_rtw','crl_AddSubfunction.c');
rtwdemodbtype(cfile,'/* Model step function ','/* Model initialize function',1, 1);
%% 
% The |+| operator can be replaced with your custom implementation. The
% code is type cast before the replacement.

%%
% Close the model and code generation report.
delete ./rtwTargetInfo.m
bdclose('crl_AddSubfunction');
rtwdemoclean;


