view m-toolbox/m/gui/gltpda/g_arrmult.m @ 29:54f14716c721 database-connection-manager

Update Java code
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children
line wrap: on
line source

function g_arrmult(block)

%             This is the automatic function wrapper
% ========================================================================
% ==================== level-2 M file S-function =========================
% ========================================================================
% This wrapper is the automatic function, called by every function block
% in Simulink, able to execute m-file functions retrieving from Simulink:
% (1) the pointer to the AO(s) to be analyzed, coming in as input of the
%     corresponding block (ie, the DATA),
% (2) the name of the function to be applied on those data, from the tag
%     of the currently executed block (ie, the true FUNCTION),
% (3) the parameters for that particular block, retrieved from the global
%     shared workspace by the handle of the block (ie, the PARAMETERS).
%
% The output is then generated as:
%    OUTPUT = FUNCTION(DATA,PARAMETERS)
%
% This output in the end is saved into the global array containing all
% the AOs (ie, all the DATA go together with other data): thus this output
% will be freely accessible by all the other functions.
%
% The only real output to Simulink will be just the ordinal number of the
% so-generated AO into the global array of AOs.
%
% =======================================================================
%                  For UNIVARIATE analysis functions
% =======================================================================
% (the difference with the other function, 'ltpdasimmulti', is the
% dimension of the output port, here set = DimInputPorts)
%
%
%  $Id: g_arrmult.m,v 1.1 2008/03/01 13:43:20 nicola Exp $

setup(block);
  
%%
function setup(block)
% global LTPDAinvar loopstatus


  %% Register dialog parameter: none, because they're retrieved directly
  %% from the memory. This will prevent the user to modify the parameters
  %% outside the proper parameters panel:
  block.NumDialogPrms = 0;

  %% Register number of input and output ports
  block.NumInputPorts  = 1;
  block.NumOutputPorts = 1;

  %% Setup functional port properties to dynamically inherited.
  block.SetPreCompInpPortInfoToDynamic;
  block.SetPreCompOutPortInfoToDynamic;
  
  block.InputPort(1).DirectFeedthrough = true;
  block.InputPort(1).DatatypeID = 0;
  block.InputPort(1).Complexity = 0;
  block.OutputPort(1).DatatypeID = 0;
  block.OutputPort(1).Complexity = 0;
block.OutputPort(1).Dimensions = 1;
%(block.InputPort(1).Dimensions)^2;
  block.SampleTimes = [0 0];
  block.SetAccelRunOnTLC(false);
 
  %% Register methods
  block.RegBlockMethod('SetInputPortSamplingMode',@SetInpPortFrameData);
  block.RegBlockMethod('SetInputPortDimensions',  @SetInpPortDims);
%   block.RegBlockMethod('SetOutputPortDimensions', @SetOutPortDims);
  block.RegBlockMethod('Outputs',                 @Outputs);
  
  function SetInpPortFrameData(block, idx, fd)
  block.InputPort(1).SamplingMode = fd;
  block.OutputPort(1).SamplingMode = fd;

  function SetInpPortDims(block, idx, di)
  block.InputPort(idx).Dimensions = di;
% outdims=(block.InputPort(1).Dimensions)^2;
% block.OutputPort(1).Dimensions = outdims;

%   function SetOutPortDims(block, idx, di)
%   block.OutputPort(idx).Dimensions = 1;


%%
function Outputs(block)
global LTPDAinvar

if length(block.InputPort(1).Data)~=2
    block.OutputPort(1).Data = block.InputPort(1).Data;
    disp('========================================================')
    disp('Something''s wrong. Please check ltpdaarrmult.m function')
    disp('========================================================')
    return
end

  outdata = LTPDAinvar{block.InputPort(1).Data(1)} .* LTPDAinvar{block.InputPort(1).Data(2)};
  outdata = num2cell(outdata);

  lineHandles = get_param(get_param(gcbh,'Parent'),'LineHandles');
  signalName = get(lineHandles.Outport,'Name');
  if ~isempty(signalName) && numel(outdata)==1
      outdata{1} = setnh(outdata{1},'name',signalName);
  end
  xx = size(LTPDAinvar,1);
  LTPDAinvar(xx+1,:) = [outdata,0];
  block.OutputPort(1).Data = xx+1;
  
%endfunction