%% 
%% $Revision: 1.1.6.3 $
%% 
%%
%% Copyright 1994-2003 The MathWorks, Inc.
%%
%% Abstract: Helper file used by assignment and selector blocks

%if EXISTS("_INDEXERLIB_") == 0
  %assign _INDEXERLIB_ = 1

%% Function: GenerateUpdateWorkAreaCode ========================================
%%
%% Abstract:
%%      Generates code for updating the block dworks.
%function GenerateUpdateWorkAreaCode(block, portIdx, dworkIdx) Output
  %%
  %assign width      = DataInputPort[portIdx].Width
  %assign rollRegion = [0:%<width-1>]
  %assign rollVars   = ["u%<portIdx>","<dwork>/DWORK%<dworkIdx+1>"]
  %assign iDTid      = LibBlockInputSignalAliasedThruDataTypeId(portIdx)
  %roll idx = rollRegion, lcv = RollThreshold, block, "Roller", rollVars
  %assign str = (LibBlockIsIndexZeroBased(block))? "" : "-1" 
  %<LibBlockDWork(DWork[dworkIdx],"",lcv,idx)> = ...
    (int32_T)(%<LibBlockInputSignal(portIdx,"",lcv,idx)>)%<str>;
  %endroll
%endfunction  %% GenerateUpdateWorkAreaCode

%% Function: SelectEnclVectInCurlyBraces =======================================
%%
%% Abstract:
%%      Utility function to enclose an input vector like [1 2.3 4.6] into
%%      a string of the form: "{1, 2.3, 4.6}"
%%
%function SelectEnclVectInCurlyBraces(input,nterms,base) void
  %assign outstr = "{"
  %foreach idx = nterms
    %assign thisInp = input[idx]-base
    %assign outstr  = outstr + "%<thisInp>"
    %assign suffix = (idx == nterms-1) ? "}" : ", "
    %assign outstr = outstr + suffix
  %endforeach
  %return outstr
%endfunction %% SelectEnclVectInCurlyBraces


%% Function: GenerateStaticConstDecl ===========================================
%%
%% Abstract:
%%      Generates a static const declaration of the block's index params
%function GenerateStaticConstDecl(vName,nTerms,vTerms,base) Output
  %%
  %assign termStr = SelectEnclVectInCurlyBraces(vTerms,nTerms,base)
  static const int_T %<vName>[%<nTerms>] = %<termStr>;
%endfunction  %% GenerateStaticConstDecl

%% Function: IndexerGetDwork ==================================================
%%
%% Abstract:
%%      Gets the DWORK with appropriate case for ADA if needed
%function IndexerGetDwork(block,idx,lcv,sigIdx) void
  %return LibBlockDWork(DWork[idx],"",lcv,sigIdx)
%endfunction  %% IndexerGetDwork

%endif %% _INDEXERLIB_
