%% $Revision: 1.1.6.3 $
%% 
%%
%% Copyright 1994-2003 The MathWorks, Inc.
%%
%% Abstract: Data Store Write block target file

%implements DataStoreWrite "C"

%function GlobalDSMMdlRefSimTarget(block)
  %return IsModelReferenceSimTarget() && block.DataStoreGlobalDSM
%endfunction
  
%% Function: BlockInstanceSetup ==============================================
%% Abstract:
%%   Set expression folding compliance
%%
%function BlockInstanceSetup(block, system) void
  %<LibBlockSetIsExpressionCompliant(block)>
  %<LibBlockSetCustomStorageComplianceLevel(block, 2)>
%endfunction


%% Function: Outputs ==========================================================
%% Abstract:
%%      DSM.Identifier[i] = U[i]
%%
%function Outputs(block, system) Output
  %assign simMdlRefGlobalDSM = GlobalDSMMdlRefSimTarget(block)
  %assign dataType = LibBlockInputSignalDataTypeName(0, "")
  %assign width = LibBlockInputSignalWidth(0)
  %assign deref = (width == 1) ? "*" : ""
  %assign rollVars = ["U"]
  %roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars
    %assign u = LibBlockInputSignal(0, "", lcv, sigIdx)
    %if simMdlRefGlobalDSM
      %assign sigIndexer = SLibGet1DArrayIndexer(width, "", lcv, sigIdx)
      %<deref>((%<dataType>*)%<CompiledModel.Name>_DSM[%<block.ModelIndex>])%<sigIndexer> = %<u>;
    %else
      %assign dworkSrc = DWorkSrc
      %<LibBlockAssignDWork(dworkSrc, lcv, "", sigIdx, u)>
    %endif
  %endroll

%endfunction

%% [EOF] dswrite.tlc
