%% $Revision: 1.1.6.10 $
%%
%implements RateTransition "C"

%function FcnBlkName() void
  %return "Rate Transition Block: %<Name>"
%endfunction

%% Function: BlockInstanceSetup ==============================================
%% Abstract:
%%
%function BlockInstanceSetup(block, system) void
  %% cache whether or not state and output initialization is required
  %% for the scalar expanded case
  %if RateTransBlkHasIC
     %<SLibSetSkipInitializationFlag(system,block,X0)>
  %endif
%endfunction

%% Function: Start ============================================================
%%
%function Start(block, system) Output
  %if RateTransBlkHasIC && !block.SkipInitialization
    %% If possible, avoid re-initializing the block outputs to
    %% zero since they are initialized to zero in the model's registration
    %% function.
    %% Set the output to the state.
    %if LibBlockOutputSignalIsInBlockIO(0)
      %openfile tmpBuffer
      %assign icIsComplex = LibBlockParameterIsComplex(X0)
      %assign yIsComplex  = LibBlockOutputSignalIsComplex(0)
      %assign x0i = SLibGetFormattedValueFromId(LibBlockParameterDataTypeId(X0),0)
      %%
      %assign rollVars = ["P", "Y"]
      %assign rollRegion = [0:%<LibBlockOutputSignalWidth(0)-1>]
      %roll idx = rollRegion, lcv = RollThreshold, block, "Roller", rollVars
	%if SLibXBInitRequired(system, block, X0, "", lcv, idx)
	  %%
	  %assign yr  = LibBlockOutputSignal(0, "", lcv, "%<tRealPart>%<idx>")
	  %assign x0r = LibBlockParameter(X0, "", lcv, "%<tRealPart>%<idx>")
	  %<yr> = %<x0r>;
	  %if (yIsComplex)
	    %assign yi  = LibBlockOutputSignal(0, "", lcv, "%<tImagPart>%<idx>")
	    %if (icIsComplex)
	      %assign x0i = LibBlockParameter(X0, "", lcv, "%<tImagPart>%<idx>")
	    %endif
	    %<yi> = %<x0i>;
	  %endif
	%endif
      %endroll
      %closefile tmpBuffer
      %if (!WHITE_SPACE(tmpBuffer))
	/* %<Type> Block: %<Name> */
	%<tmpBuffer>\
	
      %endif
    %endif
  %endif
%endfunction %% Start


%% Function: InitializeConditions ==============================================
%% Abstract:
%%      X[i] = IC[i]
%%
%%  Initialize the DWork.
%%     If the transtion block is lower priority to higher priority rate transition 
%%  block ensuring data integrity (DirectFeedThrough is false in 
%%  for this case) and the initial condition is 
%%  not zero, DWork need to be initialized. Otherwise, not 
%%  InitializeConditions is needed.5
%%   
%function InitializeConditions(block,system) Output

  %if RateTransBlkHasIC && ...
    TransitionType != "L2H_INTEGRITY_TSOFFSET_TRANS" 
    %%
    %% Create header comment
    %%
    /* %<FcnBlkName()> */
    %%
    %% For initialization, the roll region is a function of the state
    %%
    %assign numStates = LibBlockDWorkWidth(block.Buffer0)
    %%
    %assign xRollRegion = [0:%<numStates-1>]
    %%
    %% Initialize the states
    %%
    %assign dwName = LibBlockDWorkName(block.Buffer0)
    %assign rollVars = ["<dwork>/%<dwName>", "P"]
    %%
    %roll xIdx = xRollRegion, xlcv = RollThreshold, block, "Roller", rollVars
      %% Set the real and imaginary part of the state to the initial value.
      %assign xr = LibBlockDWork(block.Buffer0, "", xlcv, "%<tRealPart>%<xIdx>")
      %assign rhs = LibBlockParameter(X0, "", xlcv, "%<tRealPart>%<xIdx>")
      %<xr> = %<rhs>;
      %if LibBlockDWorkIsComplex(block.Buffer0)
	%assign xi = LibBlockDWork(block.Buffer0, "", xlcv, "%<tImagPart>%<xIdx>")
	%if LibBlockParameterIsComplex(X0)
	  %assign rhs = LibBlockParameter(X0,"", xlcv, "%<tImagPart>%<xIdx>")
	%else
	  %assign rhs = ...
	    SLibGetFormattedValueFromId(LibBlockParameterDataTypeId(X0), 0)
	%endif
	%<xi> = %<rhs>; 
      %endif
    %endroll
    %if TransitionType == "NOPRIORITY_DBBUF_RTB"
       %<LibBlockDWork(block.write_buf,"","",0)> = -1;
       %<LibBlockDWork(block.read_buf,"","",0)> = -1;
       %<LibBlockDWork(block.last_buf_wr,"","",0)> = 0;
    %endif
  %endif
%endfunction   

%%-------------------------------------------------------
%% Function: Update
%function Update(block,system) Output
  %% 
  %% Update function is needed if the rate transition 
  %% is lower priority to higher priority and ensure date integrity.
  %%
  %assign inportTID  = LibBlockInputSignalSampleTimeIndex(0)
  
  %if LibAsynchronousTriggeredTID(inportTID)
    %% code for async tid is always rate grouped, 
    %% we don't generate code for async tid when system generate
    %% non-rate grouping code.
    %return 
  %endif
  
  %openfile tmpBuf
  %<GenUpdateForTID(block,system)>
  %closefile tmpBuf
  
  %if !WHITE_SPACE(tmpBuf)
    %<FcnGenerateTidGuardOpenCode(inportTID)>
    %<tmpBuf>
    %<FcnGenerateTidGuardCloseCode(inportTID)>
  %endif
%endfunction

%% Function: UpdateForTID
%function UpdateForTID(block,system,tid) Output
  %assign inportTID  = LibBlockInputSignalSampleTimeIndex(0)
  %assign outportTID = LibBlockOutputSignalSampleTimeIndex(0)
  %if tid == inportTID
    %<GenUpdateForTID(block,system)>
  %endif
 %endfunction


%% Function: GenUpdateForTID
%function GenUpdateForTID(block,system) Output
  %assign width = LibBlockOutputSignalWidth(0)
  %% 
  %% Update function is needed only if the rate transition 
  %% is lower priority to higher priority and ensure date integrity.
  %%
  %assign inputDataType = LibBlockInputSignalDataTypeName(0, "")

  %switch TransitionType
    %case "L2H_INTEGRITY_DETERMINISTIC_RTB"
      /* %<FcnBlkName()> */
      %assign width = LibBlockOutputSignalWidth(0)
      /* Update of lower priority to higher priority determinsitic   */
      /* rate transition, ensure data integrity */
      %if width == 1
	%<LibBlockDWork(block.Buffer0,"","",0)> = ...
	  %<LibBlockInputSignal(0,"","",0)>;
      %else
	%assign x = LibBlockDWorkAddr(block.Buffer0, "", "", 0)
	%assign u = LibBlockInputSignalAddr(0, "", "", 0)
	(void) memcpy(%<x>, %<u>, %<width>*sizeof(%<inputDataType>));
      %endif
      %break
    %case "L2H_INTEGRITY_RTB"
      %%
      %%  atomic memory copy using double buffer
      %%
      /* Update of lower priority to higher priority nondeterminsitic   */
      /* rate transition, ensure data integrity    */
      %if width == 1
	if (%<LibBlockDWork(block.ActiveBufIdx,"","",0)>) {
	   %<LibBlockDWork(block.Buffer0,"","",0)> = ...
	    %<LibBlockInputSignal(0,"","",0)> ;
	}
	else{
	  %<LibBlockDWork(block.Buffer1,"","",0)> = ...
	    %<LibBlockInputSignal(0,"","",0)> ;
	}
      %else
	%assign x0 = LibBlockDWorkAddr(block.Buffer0, "", "", 0)
	%assign x1 = LibBlockDWorkAddr(block.Buffer1, "", "", 0)
	%assign u = LibBlockInputSignalAddr(0, "", "", 0)

	(void) memcpy(...
	  (%<LibBlockDWork(block.ActiveBufIdx,"","",0)> ? ...
	  %<x0> : %<x1>), %<u>, %<width>*sizeof(%<inputDataType>));
      %endif
      %<LibBlockDWork(block.ActiveBufIdx,"","",0)> = ...
	!(%<LibBlockDWork(block.ActiveBufIdx,"","",0)>);
      %break
    %case "TRIVIAL_TRANS"
    %case "H2L_INTEGRITY_TSOFFSET_TRANS"
    %case "L2H_INTEGRITY_TSOFFSET_TRANS"
    %case "H2L_INTEGRITY_DETERMINISTIC_RTB"
    %case "H2L_INTEGRITY_RTB"
    %case "H2L_INTEGRITY_DBBUF_RTB"
    %case "NOPRIORITY_DBBUF_RTB"
      %% do nothing
      %break
    %default
      %<LibBlockReportFatalError(block,"Invalid rate transition type for update fcn")>
  %endswitch
%endfunction


%%------------------------------------------------------------
%% Function: Outputs
%function Outputs(block,system) Output
  %assign inportTID  = LibBlockInputSignalSampleTimeIndex(0)
  %assign outportTID = LibBlockOutputSignalSampleTimeIndex(0)

  %switch TransitionType
    %case "TRIVIAL_TRANS"
    %case "H2L_INTEGRITY_TSOFFSET_TRANS"
    %case "H2L_INTEGRITY_TSOFFSET_TRANS"
      %assign inputDataType = LibBlockInputSignalDataTypeName(0, "")
      %assign width = LibBlockOutputSignalWidth(0)
      %if width == 1
	%<LibBlockOutputSignal(0,"","",0)> = %<LibBlockInputSignal(0,"","",0)>;
      %else
	%assign u = LibBlockInputSignalAddr(0, "", "", 0)
	%assign y = LibBlockOutputSignalAddr(0, "", "", 0)
	(void) memcpy(%<y>, %<u>, %<width>*sizeof(%<inputDataType>));
      %endif
      %return
      %break
    %case "H2L_INTEGRITY_DETERMINISTIC_RTB"
    %case "H2L_INTEGRITY_RTB"
    %case "H2L_INTEGRITY_DBBUF_RTB"  %% inportTid has higher priority
    %case "NOPRIORITY_DBBUF_RTB" %% priority is not assigned 
      %% higher priority to lower priority
      %assign IdxTID0 = inportTID
      %assign IdxTID1 = outportTID
      %break
    %case "L2H_INTEGRITY_DETERMINISTIC_RTB"
    %case "L2H_INTEGRITY_RTB"  %% inportTid has lower priority
      %% lower to higher priority 
      %assign IdxTID0 = outportTID
      %assign IdxTID1 = inportTID
      %break
    %default
      %<LibBlockReportFatalError(block,"Invalid rate transition type")>
  %endswitch
  %% code for async tid is always rate grouped, 
  %% we don't generate code for async tid when system generate
  %% non-rate grouping code.
  %if !LibAsynchronousTriggeredTID(IdxTID0)
    %openfile tmpBuf
    %<OutputsForTID0(block,system)>
    %closefile tmpBuf
    %if !WHITE_SPACE(tmpBuf)
      %<FcnGenerateTidGuardOpenCode(IdxTID0)>
      %<tmpBuf>\
      %<FcnGenerateTidGuardCloseCode(IdxTID0)>
    %endif
  %endif
  %if !LibAsynchronousTriggeredTID(IdxTID1)
    %openfile tmpBuf
    %<OutputsForTID1(block,system)>
    %closefile tmpBuf
    %if !WHITE_SPACE(tmpBuf)
      %<FcnGenerateTidGuardOpenCode(IdxTID1)>
      %<tmpBuf>\
      %<FcnGenerateTidGuardCloseCode(IdxTID1)>
    %endif 
  %endif
  %undef tmpBuf
%endfunction

%% Function: OutputsForTID
%function OutputsForTID(block,system,tid) Output
  %assign inportTID  = LibBlockInputSignalSampleTimeIndex(0)
  %assign outportTID = LibBlockOutputSignalSampleTimeIndex(0)
  %switch TransitionType
    %case "TRIVIAL_TRANS"
    %case "H2L_INTEGRITY_TSOFFSET_TRANS"
    %case "H2L_INTEGRITY_TSOFFSET_TRANS"
      %assign inputDataType = LibBlockInputSignalDataTypeName(0, "")
      %assign width = LibBlockOutputSignalWidth(0)
      %if tid == outportTID
	/* %<FcnBlkName()> */
	/* (unprotected) rate transition block */
	%if width == 1
	  %<LibBlockOutputSignal(0,"","",0)> = %<LibBlockInputSignal(0,"","",0)>;
	%else
	  %assign u = LibBlockInputSignalAddr(0, "", "", 0)
	  %assign y = LibBlockOutputSignalAddr(0, "", "", 0)
	  (void) memcpy(%<y>, %<u>, %<width>*sizeof(%<inputDataType>));
	%endif
      %endif
    %case "H2L_INTEGRITY_DETERMINISTIC_RTB"
    %case "H2L_INTEGRITY_RTB"        %% inportTid has higher priority 
    %case "H2L_INTEGRITY_DBBUF_RTB"  
    %case "NOPRIORITY_DBBUF_RTB" %% priority is not assigned 
      %% higher priority to lower priority
      %assign tid0 = inportTID
      %assign tid1 = outportTID
      %break
    %case "L2H_INTEGRITY_DETERMINISTIC_RTB"
    %case "L2H_INTEGRITY_RTB"  %% inportTid has lower priority
      %% lower to higher priority 
      %assign tid0 = outportTID
      %assign tid1 = inportTID
      %break
    %default  
      %<LibBlockReportFatalError(block,"Invalid rate transition type")>
  %endswitch

  %if tid == tid0
    %<OutputsForTID0(block,system)>
  %elseif tid == tid1
    %<OutputsForTID1(block,system)>
  %endif
%endfunction

%% Function: OutputsForTID0
%function OutputsForTID0(block,system) Output
  %assign inputDataType = LibBlockInputSignalDataTypeName(0, "")
  %assign width = LibBlockOutputSignalWidth(0)
  
  %switch TransitionType
    %case "TRIVIAL_TRANS"
    %case "H2L_INTEGRITY_TSOFFSET_TRANS"
    %case "H2L_INTEGRITY_TSOFFSET_TRANS"
      %break
    %case "H2L_INTEGRITY_DETERMINISTIC_RTB"
      %% deterministic, ensure data integrity, H2L
      %assign inportTID  = LibBlockInputSignalSampleTimeIndex(0)
      %assign outportTID = LibBlockOutputSignalSampleTimeIndex(0)
      /* %<FcnBlkName()> */
      /* rate transiton block          */
      /* (Higher Priority to lower priority, deterministic, */
      /* ensure data integrity)        */
      if (%<LibIsSpecialSampleHit(outportTID, inportTID)>) {
	%if width == 1
	  %<LibBlockOutputSignal(0,"","",0)> = ...
	    %<LibBlockInputSignal(0,"","",0)>;
	%else
	  %assign u = LibBlockInputSignalAddr(0, "", "", 0)
	  %assign y = LibBlockOutputSignalAddr(0, "", "", 0)
	  (void) memcpy(%<y>, %<u>, %<width>*sizeof(%<inputDataType>));
	%endif
      }
      %break
    %case "H2L_INTEGRITY_RTB"
      /* %<FcnBlkName()>  */
      /* rate transiton block             */
      /* (Higher Priority to lower priority, */
      /* nondeterministic, */
      /* ensure data integrity)           */ 
      %assign semaphoreTaken = LibBlockDWork(block.semaphoreTaken,"","",0)
      if(!%<semaphoreTaken>) {
	%if width == 1
	  %<LibBlockDWork(block.Buffer0,"","",0)> = ...
	    %<LibBlockInputSignal(0,"","",0)>;
	%else
	  %assign u = LibBlockInputSignalAddr(0, "", "", 0)
	  %assign x  = LibBlockDWorkAddr(block.Buffer0, "", "", 0)
	  (void) memcpy(%<x>, %<u>, %<width>*sizeof(%<inputDataType>));
	%endif
      }
      %break
    %case "H2L_INTEGRITY_DBBUF_RTB" 
      /* %<FcnBlkName()>  */
      /* rate transiton block             */
      /* (Higher Priority to lower priority, */
      /* nondeterministic, */
      /* ensure data integrity)           */ 
      %assign semaphoreTaken = LibBlockDWork(block.semaphoreTaken,"","",0)
      %assign activeBuf      = LibBlockDWork(block.ActiveBufIdx,"","",0)
      if(%<semaphoreTaken> != 0) {
	%if width == 1
	  %<LibBlockDWork(block.Buffer0,"","",0)> = ...
	    %<LibBlockInputSignal(0,"","",0)>;
	%else
	  %assign u = LibBlockInputSignalAddr(0, "", "", 0)
	  %assign x  = LibBlockDWorkAddr(block.Buffer0, "", "", 0)
	  (void) memcpy(%<x>, %<u>, %<width>*sizeof(%<inputDataType>));
	%endif
	%<activeBuf> = 0;
      } else {
	%if width == 1
	  %<LibBlockDWork(block.Buffer1,"","",0)> = ...
	    %<LibBlockInputSignal(0,"","",0)>;
	%else
	  %assign u = LibBlockInputSignalAddr(0, "", "", 0)
	  %assign x  = LibBlockDWorkAddr(block.Buffer1, "", "", 0)
	  (void) memcpy(%<x>, %<u>, %<width>*sizeof(%<inputDataType>));
	%endif
	%<activeBuf> = 1;
      }
      %break
    %case "L2H_INTEGRITY_DETERMINISTIC_RTB"
      %assign inportTID  = LibBlockInputSignalSampleTimeIndex(0)
      %assign outportTID = LibBlockOutputSignalSampleTimeIndex(0)
      /* %<FcnBlkName()> */
      /* rate transiton block output   */
      /* (Lower Priority to higher priority, deterministic, */
      /* ensure data integrity)        */
      if (%<LibIsSpecialSampleHit(inportTID, outportTID)>) {
	%if width  == 1
	  %<LibBlockOutputSignal(0,"","",0)> = ...
	    %<LibBlockDWork(block.Buffer0,"","",0)>;
	%else
	  %assign y = LibBlockOutputSignalAddr(0, "", "", 0)
	  %assign x = LibBlockDWorkAddr(block.Buffer0,"","",0)
	  (void) memcpy(%<y>, %<x>, %<width>*sizeof(%<inputDataType>));
	%endif
      }
      %break
    %case "L2H_INTEGRITY_RTB"
       /* %<FcnBlkName()> */
       /* rate transiton block output */
       /* (Lower Priority to higher priority, ensure data  */
       /* integrity, nondeterminisitic) */
       %if width == 1
	 if (%<LibBlockDWork(block.ActiveBufIdx,"","",0)>) {
	   %<LibBlockOutputSignal(0,"","",0)> = ...
	     %<LibBlockDWork(block.Buffer1,"","",0)>;
	 } else {
	   %<LibBlockOutputSignal(0,"","",0)> = ...
	     %<LibBlockDWork(block.Buffer0,"","",0)>;
	 }
       %else
	 %assign x0 = LibBlockDWorkAddr(block.Buffer0, "", "", 0)
	 %assign x1 = LibBlockDWorkAddr(block.Buffer1, "", "", 0)
	 %assign y = LibBlockOutputSignalAddr(0, "", "", 0)
	 (void) memcpy(%<y>, ...
	   (%<LibBlockDWork(block.ActiveBufIdx,"","",0)> ? ...
	   %<x1> : %<x0>), ...
	   %<width>*sizeof(%<inputDataType>));
        %endif
	%break
      %case "NOPRIORITY_DBBUF_RTB"
	/* %<FcnBlkName()> 
	* write side code 
	* (Priority of the task associated with either input 
	* or output port is not assigned. Rate transition 
	* block ensures data integrity. Determinism of data 
	* transfer is not ensured */
	switch(%<LibBlockDWork(block.read_buf,"","",0)>) {
	  case 0:
	  %<LibBlockDWork(block.write_buf,"","",0)> = 1;
	  break;
	  case 1:
	  %<LibBlockDWork(block.write_buf,"","",0)> = 0;
	  break;
	  default:
	  %<LibBlockDWork(block.write_buf,"","",0)> = ...
	    !%<LibBlockDWork(block.last_buf_wr,"","",0)>;
	  break;
	}
	%if width == 1
	  if (%<LibBlockDWork(block.write_buf,"","",0)>==0) {
	    %<LibBlockDWork(block.Buffer0,"","",0)> = ...
	      %<LibBlockInputSignal(0,"","",0)>;
	  } else {
	    %<LibBlockDWork(block.Buffer1,"","",0)> = ...
	      %<LibBlockInputSignal(0,"","",0)>;
	  }
	%else
	  %assign u = LibBlockInputSignalAddr(0, "", "", 0)
	  %assign x0  = LibBlockDWorkAddr(block.Buffer0, "", "", 0)
	  %assign x1  = LibBlockDWorkAddr(block.Buffer1, "", "", 0)
	  if (%<LibBlockDWork(block.write_buf,"","",0)>==0) {
	    (void) memcpy(%<x0>, %<u>, %<width>*sizeof(%<inputDataType>));
	  } else {
	    (void) memcpy(%<x1>, %<u>, %<width>*sizeof(%<inputDataType>));
	  }
	%endif
	%<LibBlockDWork(block.last_buf_wr,"","",0)> = ...
	  %<LibBlockDWork(block.write_buf,"","",0)>;
	%<LibBlockDWork(block.write_buf,"","",0)> = -1;
	%break
      %default  
	 %<LibBlockReportFatalError(block,"Invalid rate transition type")>
     %endswitch

%endfunction 

%% Function: OutputsForTID1
%function OutputsForTID1(block,system) Output
  %assign inputDataType = LibBlockInputSignalDataTypeName(0, "")
  %assign width = LibBlockOutputSignalWidth(0)

  %switch TransitionType
    %case "TRIVIAL_TRANS"
    %case "H2L_INTEGRITY_TSOFFSET_TRANS"
    %case "H2L_INTEGRITY_TSOFFSET_TRANS"
      %break
    %case "H2L_INTEGRITY_DETERMINISTIC_RTB"
      %break
    %case "H2L_INTEGRITY_RTB"
      /* %<FcnBlkName()> */
      /* (Higher Priority to lower priority, */ 
      /* nondeterministic, ensure data integrity) */ 
      %assign semaphoreTaken = LibBlockDWork(block.semaphoreTaken,"","",0)
      %<semaphoreTaken> = 1;
      %if width == 1
	%<LibBlockOutputSignal(0,"","",0)> = ...
	  %<LibBlockDWork(block.Buffer0,"","",0)>;
      %else
	%assign x = LibBlockDWorkAddr(block.Buffer0, "", "", 0)
	%assign y = LibBlockOutputSignalAddr(0, "", "", 0)
	(void) memcpy(%<y>, %<x>, %<width>*sizeof(%<inputDataType>));
      %endif
      %<semaphoreTaken> = 0;
      %break
    %case "H2L_INTEGRITY_DBBUF_RTB"  
      /* %<FcnBlkName()> */
      /* (Higher Priority to lower priority, */ 
      /* nondeterministic, ensure data integrity) */ 
      %assign semaphoreTaken = LibBlockDWork(block.semaphoreTaken,"","",0)
      %if width == 1
	if (%<LibBlockDWork(block.ActiveBufIdx,"","",0)> == 0) {
	  %<semaphoreTaken> = 0;
	  %<LibBlockOutputSignal(0,"","",0)> = ...
	    %<LibBlockDWork(block.Buffer0,"","",0)>;
	}
	else{
	  %<semaphoreTaken> = 1;
	  %<LibBlockOutputSignal(0,"","",0)> = ...
	    %<LibBlockDWork(block.Buffer1,"","",0)>;
	}
      %else
	%assign x0 = LibBlockDWorkAddr(block.Buffer0, "", "", 0)
	%assign x1 = LibBlockDWorkAddr(block.Buffer1, "", "", 0)
	%assign y = LibBlockOutputSignalAddr(0, "", "", 0)
	%<semaphoreTaken> = %<LibBlockDWork(block.ActiveBufIdx,"","",0)> ? 1:0;
	(void) memcpy(%<y>, ...
	  (%<LibBlockDWork(block.ActiveBufIdx,"","",0)> ? ...
	  %<x1> : %<x0>), ...
	  %<width>*sizeof(%<inputDataType>));
      %endif
      %break
    %case "L2H_INTEGRITY_DETERMINISTIC_RTB"
      %break
    %case "L2H_INTEGRITY_RTB" 
      %break
    %case "NOPRIORITY_DBBUF_RTB"
      /* %<FcnBlkName()> 
      * read side code
      * (Priority of the task associated with either input 
      * or output port is not assigned. Rate transition 
      * block ensures data integrity. Determinism of data 
      * transfer is not ensured */
      switch(%<LibBlockDWork(block.write_buf,"","",0)>) {
	case 0:
	%<LibBlockDWork(block.read_buf,"","",0)> = 1;
	break;
	case 1:
	%<LibBlockDWork(block.read_buf,"","",0)> = 0;
	break;
	default:
	%<LibBlockDWork(block.read_buf,"","",0)> = ...
	  %<LibBlockDWork(block.last_buf_wr,"","",0)>;
	break;
      }
      %if width == 1
	if (%<LibBlockDWork(block.read_buf,"","",0)>==0) {
	  %<LibBlockOutputSignal(0,"","",0)> = ...
	    %<LibBlockDWork(block.Buffer0,"","",0)>;
	} else {
	  %<LibBlockOutputSignal(0,"","",0)> = ...
	    %<LibBlockDWork(block.Buffer1,"","",0)>;
	}
      %else
	%assign y = LibBlockOutputSignalAddr(0, "", "", 0)
	%assign x0  = LibBlockDWorkAddr(block.Buffer0, "", "", 0)
	%assign x1  = LibBlockDWorkAddr(block.Buffer1, "", "", 0)
	if (%<LibBlockDWork(block.read_buf,"","",0)>==0) {
	  (void) memcpy(%<y>, %<x0>, %<width>*sizeof(%<inputDataType>));
	} else {
	  (void) memcpy(%<y>, %<x1>, %<width>*sizeof(%<inputDataType>));
	}
      %endif
      %<LibBlockDWork(block.read_buf,"","",0)> = -1;
      %break
    %default
      %<LibBlockReportFatalError(block,"Invalid rate transition type")>
  %endswitch
  
%endfunction

%% [EOF] rate_transition.tlc
