%% $Revision: 1.2 $ 
%% $Date: 2002/06/04 15:51:37 $
%% Copyright 1990-2002 The MathWorks, Inc.
%%
%% Abstract: Level-2 run-time parameter example block target file 

%implements "sfun_runtime3" "C"

%%      Run-time param S-function example. This S-function accepts N input
%%      signals (which can be scalar or vector) and produces 1 or 2
%%      outputs which are the sum*gain or both sum*gain and average of the
%%      input signals.  This example permits the gain parameter to be of
%%      type other than double.
%%
%%      To use this S-function, place it in an S-function block,
%%      the first parameter is the number of input ports specified as
%%      a string of '+' and '-' characters, e.g.
%%          '++-'
%%      The second parameter is one of the following text strings:
%%         'SumTimesGain'
%%         'SumTimesGainAndAverage'
%%      The third parameter is a gain to be applied to the sum of the
%%      input signals.
%%

%% Function: mdlOutputs =======================================================
%% Abstract:
%%
%%      y1 = "sum" * "gain" where sum operation is defined by a list of
%%           '+' and '-' characters.
%%      y2 = "modified" average of the input signals (i.e. sum/nInputPorts).
%%
%function Outputs(block, system) Output
  /* %<Type> Block: %<Name> */
  {
    %assign k = LibBlockParameter(Gain, "", "", 0)
    %assign signs = SFcnParamSettings.SignsStr
    %assign rollVars = ["U", "Y"]
    %roll sigIdx = RollRegions, lcv = 5, block, "Roller", rollVars
      %foreach portIdx = NumDataInputPorts
	%assign uport = LibBlockInputSignal(portIdx, "", lcv, sigIdx)
	%if portIdx == 0
	  %if signs[portIdx] == "+"
	    %assign u = "%<uport>"
	  %else
	    %assign u = "- %<uport>"
	  %endif
	%else
	  %assign u = u + " %<signs[portIdx]> %<uport>"
	%endif
	%if ((portIdx + 1) % 4) == 0
	  %assign u = u + "\n"
	%endif
      %endforeach
      %%
      %assign y0 = LibBlockOutputSignal(0, "", lcv, sigIdx)
      %if NumDataOutputPorts == 2
	%assign y1 = LibBlockOutputSignal(1, "", lcv, sigIdx)
	%if sigIdx == 0
	  real_T sum = %<u>;
	%else
	  sum = %<u>;
	%endif
	%<y0> = sum * %<k>;
	%<y1> = sum / %<NumDataInputPorts>;
      %else
	%<y0> = (%<u>) * %<k>;
      %endif
    %endroll
  }
  
%endfunction
