% FIND_MDLREFS finds referenced models and Model blocks
%
% [models, blocks] = find_mdlrefs(sys) finds all referenced models and 
% Model blocks in the model hierarchy below the specified model.
%
% [models, blocks] = find_mdlrefs(sys, Name, Value, ...) finds
% referenced model and Model blocks with additional options specified by
% one or more name-value pair arguments.
% ...
%
%  Input Arguments:
%     sys -- The name of the model to be searched.
%
%  Name-Value Pair Arguments:
%     'KeepModelsLoaded' -- Controls whether to keep the referenced models 
%       loaded that the function loads:
%       false - Close referenced models that were loaded by the
%               function.
%       true  - Keeps all the models loaded that the function loads.
%       The default is false.
%     
%     'AllLevels' -- Controls how to search within the model hierarchy:
%       false - Searches only the top level.
%       true  - Searches the complete hierarchy of which modelName is the
%       top model.
%       The default is true.
%
%     'IncludeProtectedModels' -- Controls if Protected Models are
%     included:
%       false - Omits Protected Models.
%       true  - Includes Protected Models. The names of any Protected Models
%       will have an extension.
%       The default is false.
%
%     'IncludeCommented' -- Controls if commented blocks are included:
%       false - Skip commented blocks.
%       true  - Include commented blocks.
%       The default is false.
%
%     'ReturnTopModelAsLastElement' -- Controls if the top model passed in as the 
%       first input should be included:
%       false - Omits the top model.
%       true  - Includes the top model as the last element in output 'models'.
%       The default is true.
%
%     'MatchFilter' -- Select model blocks using @fcn, a function handle, which is invoked by
%        find_mdlrefs. find_mdlrefs traverses the Simulink block diagram starting at SYSTEM. 
%        Using @fcn you can process each block that is seen during the traversal. @fcn 
%        should return match set to true if the block is to be returned by find_mdlrefs. 
%        @fcn should set prune to false if that branch (subsystem) of the tree should be 
%        trimmed from the search.
%        
%        [match, prune] = fcn(element)
%           element - Handle of the model element (block, line, annotation) being processed.
%           match   - Logical. If false, do not return the element in the find_mdlrefs answer.
%           prune   - Optional logical (default false). If true, skip search of the current
%                     element, which only applies to subsystems.
%     Variants
%          Simulink provides the following post-compile match filters for variant block processing:
% 
%     1. Simulink.match.activeVariants: match blocks which are active in simulation.
%     2. Simulink.match.codeCompileVariants: match blocks which are part of generated code.
%
%      Example: to find all blocks active in simulation use
%        >> set_param(SYSTEM, 'SimulationCommand', 'update');
%        >> find_mdlrefs(SYSTEM, 'MatchFilter', @Simulink.match.activeVariants);
% 
%      Example: to find blocks that will be in the generated code, use
%        >> MODEL([],[],[],'compileForCodegen')
%        >> find_mdlrefs(MODEL, 'MatchFilter', @Simulink.match.codeCompileVariants);
%        >> MODEL([],[],[],'term')
%
%     'Variants' -- Include variant models in search:
%       'ActivePlusCodeVariants' - Include all variant models for Variant Subsystem blocks with 
%            'VariantActivationTime' set to 'code compile', otherwise search in only the 
%            active variants choices.
%       'ActiveVariants' - Include active variant models for Variant Subsystem blocks.
%       'AllVariants' - Include all variant models in Variant Subsystem blocks.
%       The default is 'ActivePlusCodeVariants'.
%
%       The 'Variants' constraint applies only to Variant Subsystems that have the
%       VariantControlMode set to 'expression' or 'label'. Use the find_mdlrefs
%       function with the MatchFilter option to operate on all types of variant blocks.
%
%  Output Arguments:
%     models -- An list of models found by the function.
%       By default, the last element in the list is the name of the specified model.
%
%     blocks -- A list of the Model blocks found by the function.

 
% Copyright 1994-2020 The MathWorks, Inc.

