%% Use Variant Source Block to Control Execution of Conditional Subsystem Blocks
% This example shows how to use a single-input/single-output Variant
% Source block to control the execution of a conditional subsystem block.

% Copyright 2016 The MathWorks, Inc.

%% Explore the Model
% Open the model |slexVariantControlPorts|. 
%%
 open_system('slexVariantControlPorts');
%%
%
% The model contains a single-input/single-output Variant Source block,
% |Variant Source1|, with variant condition set as |V==1|. The output from |Variant
% Source1| block is connected to the control port of the Enabled Subsystem 
% |Subsystem|. 
% 
% The *Allow zero active variant controls* parameter on the
% |Variant Source1| block is set to |on|.  When this option is selected and
% there is no active variant choice, Simulink(R) disables all the blocks
% connected to the input and output stream of the Variant Source block.
%
% When you simulate the model after setting |V=1|, the condition |V==1|
% propagates to the outport of |Variant Source1| and then to the control
% port of |Subsystem|. The condition assigned to the subsystem block then
% propagates to the blocks named |Sine2| and |Out1| connected to its input and
% output ports. If you set |V| to a value other than |1|, Simulink
% disables all the blocks connected to the inport and outport of |Variant
% Source1|.
%%
% <<../slexVariantControlPortssim.png>>
%% Propagate Variant Conditions to Function-Call Subsystems 
% A Function-Call Subsystem block is a subsystem that another block can
% invoke directly during simulation. The Function-Call Subsystem block is
% analogous to a function in procedural programming language. For more
% information, see <docid:simulink_ug.bqrmu3t-1>.
%% 
% You can use a Variant Source block to make the
% Function-Call Subsystem block conditional.
%%
% <<../varsource-functioncall.png>>
%%
% The Variant Source block has condition |V==1|, where |V| is a
% |Simulink.Parameter|. 
%
% The *Output function call* parameter on the Variant Source block is
% set to |on|. This enables the block to output function-call
% signals.
%
% The *Allow zero active variant controls* parameter on the
% Variant Source block is set to |on|.
%% 
% When you simulate this model, the variant condition from the Variant
% Source block propagates to the control port of the |SubA| subsystem block
% and further propagates to the blocks connected to its inports and
% outports.
%
% * When |V=1|, the |SubA| block is active and the
% variant condition propagates backward and forward to the blocks connected
% to the input (|In1|) and output (|Out1|) ports.
%
% * When |V~=1| (for example, |V=0|), |SubA| becomes inactive, which makes 
% |Out1| inactive. |In2| remains active because it is connected to |SubB|,
% which is active.
%
% * If |In2| is not connected to |SubB|, |In2| becomes inactive
% when |V~=1|.
%%
% *Note*: If the Function-Call Subsystem is placed inside a virtual grouped
% subsystem, the variant condition triggering the Function-Call Subsystem
% must match the corresponding condition on the input of the higher level
% subsystem block.
