%% $RCSfile: resetint.tlc,v $
%% $Revision: 1.15.4.4 $ 
%% $Date: 2004/11/21 19:59:49 $
%%
%% Copyright 1994-2003 The MathWorks, Inc.
%%
%% Abstract: Void target file

%implements "ResetIntegrator" "C"

%% Function: InitializeConditions =============================================
%% Abstract:
%%      InitialConditions
%%
%function InitializeConditions(block, system) Output
  /* %<Type> Block: %<Name> */
  %assign rollVars = ["P","Xc"]
  %roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars
    %<LibBlockContinuousState("", lcv, sigIdx)> \
      = %<LibBlockParameter(InitialCondition, "", lcv, sigIdx)>;
  %endroll

%endfunction %% InitializeConditions


%% Function: Outputs ==========================================================
%% Abstract:
%%      Y = X
%%
%function Outputs(block, system) Output
  /* %<Type> Block: %<Name> */
  %assign rollVars = ["Y","Xc"]
  %roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars
    %<LibBlockOutputSignal(0, "", lcv, sigIdx)> \
      = %<LibBlockContinuousState("", lcv, sigIdx)>;
  %endroll
 
%endfunction

%% Function: Derivatives ======================================================
%% Abstract:
%%      Derivatives
%%
%function Derivatives(block, system) Output
  /* %<Type> Block: %<Name> */
  %%
  {
  %assign rollVars = ["u0","xdot"]
  %roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars
    %<LibBlockContinuousStateDerivative("",lcv,sigIdx)>
      = %<LibBlockInputSignal(0, "", lcv, sigIdx)>;
  %endroll
  }

%endfunction

%% Function: Update ===========================================================
%% Abstract:
%%      Update
%%
%function Update(block, system) Output
  /* %<Type> Block: %<Name> */
  %%
  %assign needBlkStateChange = ( isRSim || ...
                                 CodeFormat == "S-Function" || ...
				 IsModelReferenceForASimstructBasedTarget() )
  %%
  %assign resetPortWidth = DataInputPort[1].Width
  %if resetPortWidth == 1
    %assign resetSignal = LibBlockInputSignal(1, "", "", 0)
    if (%<resetSignal> != 0.0) {
      %assign rollVars = ["u2","Xc"]
      %roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars
	%<LibBlockContinuousState("", lcv, sigIdx)> \
	= %<LibBlockInputSignal(2, "", lcv, sigIdx)>;
      %endroll
      %if needBlkStateChange
	%<RTMSetBlkStateChange()>;
	%<RTMSetSolverNeedsReset()>;
      %endif
    }
  %else
    %assign rollVars = ["u1","u2","Xc"]
    %roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars
      %assign resetSignal = LibBlockInputSignal(1, "", lcv, sigIdx)
      if (%<resetSignal> != 0.0) {
        %<LibBlockContinuousState("", lcv, sigIdx)> \
          = %<LibBlockInputSignal(2, "", lcv, sigIdx)>;
	%if needBlkStateChange
	  %<RTMSetBlkStateChange()>;
	  %<RTMSetSolverNeedsReset()>;
	%endif
      }
    %endroll
  %endif
 
%endfunction

