%% Generate Code by Using Lookup Table 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. 
% A Lookup table function is replaced with a call to a custom function in the generated code. 
% This example does not provide an implementation function. 
% Write your own implementation.

%   Copyright 2020 The MathWorks, Inc.

%% Example Model
% Open the model |crl_LUTfunction| for configuring the code replacement library.
open_system('crl_LUTfunction');

copyfile LutFnRtwTargetInfo.txt rtwTargetInfo.m
%% 
% Run the MATLAB customization file to create a code replacement table and register the file. The customization file has already been executed. 
% Run the sl_refresh_customizations function to load 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 LUT function replacement| to the *Selected code replacement libraries - prioritized* list pane.

%
% Alternatively, use the command-line API to enable the code replacement:
set_param('crl_LUTfunction', 'CodeReplacementLibrary', 'CRL for LUT function replacement');
%%
% Generate code from the model:
evalc('rtwbuild(bdroot)');

%%
% View the generated code. Here is a portion of |crl_LUTfunction.c|.
cfile = fullfile('crl_LUTfunction_ert_rtw','crl_LUTfunction.c');
rtwdemodbtype(cfile,'/* Model step function ','/* Model initialize function',1, 1);
%%
% The Lookup Table function is replaced with a custom |my_Lookup1D_Repl| function.
%%
% Close the model and code generation report.
delete ./rtwTargetInfo.m
bdclose('crl_LUTfunction');
rtwdemoclean;


