function [stat,post] = blkdsmem(path,prop,bstr,bint,bflt,parent,name,sbSample,blk,links)
%BLKDSMEM Defines an array of scalar elements or registers in a memory.
%
%  See also BLKRVAR, BLKWVAR

% Initial coding by A S Bozin, 06-20-98
% Copyright 1997-2000 The MathWorks, Inc.
% $Revision: 1.9 $ $Date: 2000/06/14 16:09:12 $

   stat = 0;					   % Error flag
   nInputs = bint(5);
   nOutputs = bint(6);
   channels = nInputs;
   nreg = nInputs;
   %
   % Get the input port connectivity
   %
   indInt = bint(9);
   ind = indInt+nInputs+[1:nInputs];
   cInputs = find(bint(ind));
   ind = mfindstr(bstr,1,'|');
   mloc = bstr(1:ind-1);
   SP = char(32);
   mloc(:) = strrep(mloc,SP,'_');		   % Remove white spaces
   if (size(mloc,2) > 31)
      mloc = mloc(1:31);
   end
   %
   % Block optimization
   %
   copt = 0;					   % Optimization level
   if (prop.optimize)
      if (isempty(cInputs))
	 channels = 0;
	 copt = 1;			   	   % Data store read
      else
	 nBlocks = size(links,2);
	 bias = [5*ones(1,nBlocks-1) 6];
	 connected = 0;
	 for (k = 1:nBlocks)
	    bint = links{k};
	    nInputs = bint(bias(k));
	    indInt = bint(9);
	    ind = indInt+[1:nInputs];
	    if (~isempty(find(bint(ind) == blk)))
	       connected = 1;
	       break;
	    end
	 end
	 if (~connected)
	    nOutputs = 0;
	    if (size(cInputs,2) == channels)
	       copt = 2;			   % Data store write
	    else
	       copt = 3;
	    end
	 end
      end
   end
   %
   % Add mux and demux blocks if necessary
   %
   [post,rect] = blkio('port',channels,nOutputs,prop,path);
   %
   % Data store block
   %
   switch (copt)
   case 0
      bh = add_block('libsb2sl/SUP/DataStoreRW',path,...
		     'ForegroundColor',prop.fgColor,...
		     'BackgroundColor',prop.bgColor,...
		     'Orientation',prop.orientation,...
		     'DropShadow',prop.border,...
		     'Position',rect,...
		     'MLOC',mloc,...
		     'NREG',mat2char(nreg),...
		     'RIND',mat2char(cInputs),...
		     'TS',mat2char(sbSample));
   case 1
      bh = add_block('built-in/DataStoreRead',path,...
		     'ForegroundColor',prop.fgColor,...
		     'BackgroundColor',prop.bgColor,...
		     'Orientation',prop.orientation,...
		     'DropShadow',prop.border,...
		     'Position',rect,...
		     'DataStoreName',mloc,...
		     'SampleTime',mat2char(sbSample));
   case 2
      bh = add_block('built-in/DataStoreWrite',path,...
		     'ForegroundColor',prop.fgColor,...
		     'BackgroundColor',prop.bgColor,...
		     'Orientation',prop.orientation,...
		     'DropShadow',prop.border,...
		     'Position',rect,...
		     'DataStoreName',mloc,...
		     'SampleTime',mat2char(sbSample));
   case 3
      bh = add_block('libsb2sl/SUP/DataStoreW',path,...
		     'ForegroundColor',prop.fgColor,...
		     'BackgroundColor',prop.bgColor,...
		     'Orientation',prop.orientation,...
		     'DropShadow',prop.border,...
		     'Position',rect,...
		     'MLOC',mloc,...
		     'NREG',mat2char(nreg),...
		     'RIND',mat2char(cInputs),...
		     'TS',mat2char(sbSample));
   otherwise
   end
   %
   % Connect the current data store block with the mux and demux blocks
   %
   blkio('line',channels,nOutputs,post,parent,name);
   return					   % Last card of BLKDSMEM
