%% Generate Row-Major Code for S-Functions
%
% You can generate row-major code for models that contain 
% S-functions. By default, the code generator generates column-major code. 
% To learn more about row-major code generation, see <docid:rtw_ug#bs_kwk_ 
% Code Generation of Matrices and Arrays>.
%
% For an existing model that contains S-functions, when you set the 
% configuration parameter <docid:rtw_ref#mw_c7ade187-b9cd-40a4-b7ac-2545000444ea
% *Array layout*> as |Row-major|, the configuration parameter 
% <docid:rtw_ref#mw_60ffe2c2-f7f6-45e9-b45b-9b5a61f91e99 *External functions 
% compatibility for row-major code generation*> is enabled and set to |error|
% by default. When you try to build the existing model, you get an error 
% because the S-functions are not enabled for row-major code generation by 
% default. You can test the compatibility of your S-function for row-major 
% code generation by using the *External functions compatibility for row-major 
% code generation* configuration parameter.
%
% This workflow is also applicable to C Caller blocks in a model.
%
%% Example
% 1. Open example model <matlab:ex_sfcn_rowmajor_unset |ex_sfcn_rowmajor_unset|>. 
%    The model needs these additional files:
%
% * S-function: <matlab:ex_sfcn_rowmajor.c |ex_sfcn_rowmajor.c|> 
% * TLC: <matlab:ex_sfcn_rowmajor.tlc |ex_sfcn_rowmajor.tlc|>. 
%
% Save these files to your local folder.
open_system('ex_sfcn_rowmajor_unset');

%%
% 2. The model is configured with *Array layout* set to |Column-major|. 
%    To enable row-major code generation, set *Array layout* to |Row-major|.

%%
% 3. When you build the model, the code generator terminates the build and 
%    you see this error message:
%
% <<../sfunc_simple_unset_error.png>>
%
%%
% 4. To proceed, do one of the following:
%
% * If you want to test your existing S-functions with the row-major code 
%   for the model, change the setting of the configuration parameter 
%   *External functions compatibility for row-major code generation* to |warning| 
%   or |none|. The code generator completes the build without generating 
%   row-major code for the S-functions.
% * If you want to update your S-functions so that they are compatible with 
%   row-major array layout, use the S-function API to enable the S-function 
%   for row-major code generation.
%
% To test your model for S-functions with unspecified array layout, 
% you can also run the Model Advisor checks on the model. Select the 
% *Identify TLC S-functions with unset array layout* check and click the 
% *Run This Check* button. If the model includes S-functions with 
% unspecified array layout, you see a warning such as:
%
% <<../model_advisor_unset_sfunction.png>>
%
%%
% To specify the array layout of the user-defined S-function, use the 
% <docid:simulink_sfg#mw_953348cc-5123-4492-a076-aba380ac660c 
% |ssSetArrayLayoutForCodeGen|> function of the SimStruct API. You can set 
% the enumerated type |SSArrayLayout| to:
%
% * |SS_UNSET| &ndash; This setting is the default setting that disables 
% the block for row-major code generation.
% * |SS_COLUMN_MAJOR| &ndash; Specify the block for column-major code 
% generation only.
% * |SS_ROW_MAJOR| &ndash; Specify the block for row-major code generation only.
% * SS_ALL &ndash; Specify the block as allowed for code generation regardless 
% of the array layout.
%
%%
% 5. Update the |ex_sfcn_rowmajor.c| file by adding the 
%    |ssSetArrayLayoutForCodeGen| in the |mdlInitializeSizes| method:
%
% <include>s_function_update.txt</include>

%%
% If your S-function is not affected by an array layout, set |SSArrayLayout|
% to |SS_ALL|.
% 
% 6. Compile the S-function by using this command in the MATLAB Command Window:
%
mex ex_sfcn_rowmajor.c
%%
% 7. To build the model and generate code, press *Ctrl+B*.

%%
% If you generate S-functions by using S-Function Builder, use the parameter 
% *Array layout* to specify the majority of the S-function. For more information, 
% see <docid:simulink_sfg#f8-93765 S-Function Builder Dialog Box>.
% If you use the Legacy Code Tool to integrate C functions, use the 
% |convertNDArrayToRowMajor| option in <docid:simulink_ref#bqwyczg
% |legacy_code|>. The S-Function Builder and Legacy Code Tool apply 
% preceding transposes when the S-function is set to row-major array layout 
% during simulation in normal mode.
% 
% Copyright 2018 The MathWorks, Inc.