%% Convert a Matrix Multiplication Operation to MathWorks BLAS Through Code Replacement
% In this section, you generate code using the code replacement library that you created in the first two sections of this example. 
% A floating-point matrix/matrix multiplication operation is replaced with a custom multiplication function |dgemm| 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_blas| for configuring the code replacement library.
open_system('crl_blas');

copyfile BlasTargetInfo.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 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 matrix multiplication for Mathworks Blas code| to the *Selected code replacement libraries - prioritized* list pane.
% Alternatively, use the command-line API to enable the code replacement:
set_param('crl_blas', 'CodeReplacementLibrary', 'CRL for matrix multiplication for Mathworks Blas code');
%%
% Generate code from the model:
evalc('rtwbuild(''crl_blas'')');

%%
% View the generated code. Here is a portion of |crl_blas.c|.
cfile = fullfile('crl_blas_ert_rtw','crl_blas.c');
rtwdemodbtype(cfile,'/* Model step function ','/* Model initialize function',1, 1);
%% 
% The matrix/matrix multiplication operation is repalced with the custom |dgemm32| function.

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


