%% 
%% $Revision: 1.1.6.2 $
%% 
%%
%% Copyright 1994-2003 The MathWorks, Inc.
%%
%% Abstract: While iterator block target file

%implements WhileIterator "C"

%% Function: BlockInstanceSetup ================================================
%% Abstract:
%%      Set output signal storage class to Auto for wide tunable expressions
%%      since the loop roller can't not handle this case.
%%
%function BlockInstanceSetup(block,system) void
  %<LibBlockSetIsExpressionCompliant(block)>
%endfunction

%% Function: BlockOutputSignal ================================================
%% Abstract:
%%      Output the signal as 
%%
%function Outputs(system, block) void
  %if NumDataOutputPorts > 0
    %assign loopSuffix = SYSNAME(Name)[0]
    %assign var = "iter%<loopSuffix>"
    %if !LibBlockOutputSignalIsInBlockIO(0)
      %% It's a local variable, but not an expression.  There are two possible
      %% reasons for this: 1. Downstream block(s) are not accepting expressions
      %% and 2. The output data type is double, so we use a local variable
      %% to cast the integer iteration variable to double.
      %if (LibBlockOutputSignalAliasedThruDataTypeId(0) != tSS_DOUBLE)
        %return "%<LibBlockOutputSignal(0,"","",0)> = %<var>;\n\n"
      %else 
        %return "%<LibBlockOutputSignal(0,"","",0)> = (double)%<var>;\n\n" 
      %endif
    %else
      %% The subsystem block will transfer the iteration variable to
      %% the global output of this block.
      %return ""
    %endif
  %else
    %return ""
  %endif
%endfunction

%% Function: BlockOutputSignal =================================================
%% Abstract:
%%      Return the appropriate reference to the iterator.  This function *may*
%%      be used by Simulink when optimizing the Block IO data structure.
%%
%function BlockOutputSignal(block,system,portIdx,ucv,lcv,idx,retType) void
  %switch retType
    %case "Signal"
      %assign loopSuffix = SYSNAME(Name)[0]
      %return "iter%<loopSuffix>"
      %%START_ASSERT
    %default
      %assign errTxt = "Unsupported return type: %<retType>"
      %<LibBlockReportError(block,errTxt)>
      %%END_ASSERT
  %endswitch
%endfunction
%% [EOF] whileiter.tlc
