function [stat,post,dsblk] = dsbuild(bh,path,catalog,code,node,dsblk)
%DSBUILD 
%

% Initial coding by A S Bozin, 06-22-98
% Copyright 1997-2000 The MathWorks, Inc.
% $Revision: 1.6 $ $Date: 2000/06/14 16:11:53 $

   nInputs = catalog(node).nInputs;
   offset = 30*nInputs;				   % Vertical distance between the input ports
   rect = [20 offset 40 offset+20];
   ind = find(dsblk);
   ndsblk = size(ind,2);
   if (ndsblk > 0)
      dsnames = cell(ndsblk,1);
      [dsnames{:}] = deal(catalog(ind).name);
      for (sb = 1:ndsblk)
	 rect([2 4]) = rect([2 4])+40;
	 mloc = dsnames{sb};
	 SP = char(32);
	 if (size(mloc,2) > 31)
	    nsamechar = sum(strncmp(dsnames,mloc,31));
	    if (nsamechar > 1)
	       msg = {cat(2,'DataStore name ',dsnames{sb});...
		      sprintf('truncated to 31 characters. There are %d DataStore block',nsamechar);...
		      'names which have the same first 31 characters.'};
	       sbboxerror('write',msg);
	    end
	    mloc = mloc(1:31);
	 end
	 mloc(:) = strrep(mloc,SP,'_');		   % Remove white spaces
	 mh = add_block('built-in/DataStoreMemory',cat(2,path,'/',dsnames{sb}),...
			'Position',rect,...
			'FontSize',10,...
			'DataStoreName',mloc,...
			'InitialValue',mat2char(code(ind(sb)).flt.blk{1}));
      end
   end
   return					   % Last card of DSBUILD
