%% Copyright 1990-2000 The MathWorks, Inc. %% %% Abstract: Level-2 run-time parameter example block target file %implements "sfun_runtime1" "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. %% %% 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 /* % Block: % */ { %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 = "%" %else %assign u = "- %" %endif %else %assign u = u + " % %" %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 = %; %else sum = %; %endif % = sum * %; % = sum / %; %else % = (%) * %; %endif %endroll } %endfunction