function sb2slml(blkname,in);
%SB2SLML converts multiplication blocks to SIMULINK.
%	SB2SLML(BLKNAME,IN) converts a SystemBuild block
%       to a SIMULINK block.  BLKNAME is a string containing the name of
%       the block. The parameters are set up for this block based on the
%       SystemBuild file coding integer IN.

%multiplication block (including element by element product
%                       and dot product)

% Wes Wang 9/15/92 
% Copyright (c) 1990-93 by The MathWorks, Inc.
% $Revision: 1.14 $  $Date: 1993/06/09 22:09:40 $

% in = [8, code1 code2, input, output, state,....
%      code2=2 summary
%      code2=4 element by element prod 
%      code2=5 dot prod
%      code2=6 cross product 
%      code2=7 element by element divider
% in(x:x+in(6)-1) the sign of summary calculation
% x == in(4)*2 + in(8) + 10 ?? 14 ??

if in(3) == 6
  %in this case, it is a fixed format
  set_param(blkname,'Location',[20,385,582,681]);
  set_param([blkname '/output3'],'Port','3',...
		'position',[390,175,410,195]);
  set_param([blkname '/output2'],'Port','2',...
		'position',[390,120,410,140]);
  set_param([blkname '/output1'],...
		'position',[390,65,410,85])
  add_block('built-in/Mux',[blkname '/Mux'])
  set_param([blkname '/Mux'],'inputs','6',...
		'position',[145,97,175,163])
  add_block('built-in/Fcn',[blkname '/Fcn1'])
  set_param([blkname '/Fcn1'],'Expr','u[2]*u[6]-u[3]*u[5];',...
		'position',[255,60,360,90])
  add_block('built-in/Fcn',[blkname '/Fcn2'])
  set_param([blkname '/Fcn2'],'Expr','u[2]*u[6]-u[3]*u[5];',...
		'position',[255,115,360,145])
  add_block('built-in/Fcn',[blkname '/Fcn3'])
  set_param([blkname '/Fcn3'],'Expr','u[2]*u[6]-u[3]*u[5];',...
		'position',[255,170,360,200])
  for i=1:6,
    set_param([blkname '/input' num2str(i)],...
      'Port', num2str(i),...
      'position',[30+rem(i,2)*30,35+25*i,50+rem(i,2)*30,55+25*i]);
    autoline(blkname,['input' num2str(i) '/1'],['Mux/' num2str(i)]);
  end;
  autoline(blkname,'Mux/1','Fcn1/1');
  autoline(blkname,'Mux/1','Fcn2/1');
  autoline(blkname,'Mux/1','Fcn3/1');
  autoline(blkname,'Fcn1/1','output1/1');
  autoline(blkname,'Fcn2/1','output2/1');
  autoline(blkname,'Fcn3/1','output3/1');
  set_param(blkname,'Mask Display','plot([1,3,2,1,3],[1,3,2,3,1],0,0,4,4)')
  %end of cross production
elseif (in(3) == 4 | in(3) == 5) & in(5) > 1
  %element by element product or dot product
  set_param(blkname,'Location',[105,671,429,910])
  if in(5) > 1
    %in the case of in(5) = 1, it is two input and one output
    %otherwise, we need to add the blocks
    if in(3) == 5,
      %put summary and output here and add a connection line between them
      add_block('built-in/Sum',[blkname '/Sum']);
      for i=1:in(5),
         pl=[pl '+'];
      end;
      set_param([blkname '/Sum'],'inputs',pl,...
		'position',[225,77,250,133]);
      set_param([blkname '/output1'],...
		'position',[295,95,315,115])
      autoline(blkname, 'Sum/1', 'output1/1');
      set_param([blkname '/dot_prod'],...
		'Mask Display','dot\nprod.')
    else
      set_param(blkname,...
		'Mask Display','plot([1,1,0.7,0.7,1,3,2,1,3,2,1,3,2,2,2],[1,1.2,1.2,1,1,3,2,3,1,2,2,2,2,1,3],0,0,4,4);')
    end;
    for i=1:in(5)
      add_block('built-in/Product',[blkname '/Product' num2str(i)]);
      set_param([blkname '/Product' num2str(i)],...
        'position',[145,50*i,170,50*i+35]);
      set_param([blkname '/input' num2str(i)],...
        'Port', num2str(i),'position',[45,50*i,65,50*i+20]);
      set_param([blkname '/input' num2str(i+in(5))],...
        'Port', num2str(i+in(5)),'position',[80,12+50*i,100,32+50*i]);
      autoline(blkname, ['input' num2str(i) '/1'],...
        ['Product' num2str(i) '/1']);
      autoline(blkname, ['input' num2str(i+in(5)) '/1'],...
        ['Product' num2str(i) '/2']);
      if in(3) == 4
         set_param([blkname '/output' num2str(i)],...
           'Port', num2str(i),'position',[210,50*i+7,230,50*i+27]);
         autoline(blkname, ['Product' num2str(i) '/1'],...
           ['output' num2str(i) '/1']);
      elseif in(3) == 5
         %connect to summary
         autoline(blkname, ['Product' num2str(i) '/1'],...
           ['Sum/' num2str(i)]);
      end;
    end;
  end;
elseif in(3) ==7
  %element by element divide
  set_param(blkname,'Mask Display','plot([1,1,0.7,0.7,1,3],[1,1.2,1.2,1,1,3],0,0,4,4);')
%  if in(5) <= 1
%    set_param(blkname, 'Expr','u[1]/u[2]');
%  else
   set_param(blkname,'Location',[105,671,429,910])
   for i=1:in(5)
    add_block('built-in/Mux',[blkname '/Mux' num2str(i)]);
    set_param([blkname '/Mux' num2str(i)],...
	'inputs','2',...
        'position',[145,50*i,170,50*i+35]);
    set_param([blkname '/input' num2str(i)],...
        'Port', num2str(i),'position',[45,50*i,65,50*i+20]);
    set_param([blkname '/input' num2str(i+in(5))],...
        'Port', num2str(i+in(5)),'position',[80,10+50*i,100,30+50*i]);
    autoline(blkname, ['input' num2str(i) '/1'],...
        ['Mux' num2str(i) '/1']);
    autoline(blkname, ['input' num2str(i+in(5)) '/1'],...
        ['Mux' num2str(i) '/2']);
    add_block('built-in/Fcn',[blkname '/Fcn' num2str(i)]);
    set_param([blkname '/Fcn' num2str(i)],...
	'position',[210,50*i+5,250,50*i+25],...
        'Expr','u[1]/u[2]');
    autoline(blkname, ['Mux' num2str(i) '/1'], ['Fcn' num2str(i) '/1']);
    set_param([blkname '/output' num2str(i)],...
           'Port', num2str(i),'position',[300,50*i+5,320,50*i+25]);
    autoline(blkname, ['Fcn' num2str(i) '/1'],...
           ['output' num2str(i) '/1']);
   end;
%  end;
elseif in(3) == 2
%summary
  for i = 1:in(4)/in(5)
    if (in(in(4)*2+in(8)+10+i)>0)
      sig = [sig '+'];
    else
      sig = [sig '-'];
    end;
  end;
  if in(5) == 1
    set_param(blkname,'inputs',sig);
  else
    %vector output
    set_param(blkname,'Location',[218,426,742,743])
    add_block('built-in/Sum',[blkname '/Sum']);
    set_param([blkname '/Sum'],'inputs',sig,...
	'position',[285,70+in(5)*5-in(4)/in(5)*10,305,70+in(5)*5+in(4)/in(5)*10]);
    add_block('built-in/Demux',[blkname '/Demux']);
    set_param([blkname '/Demux'], 'outputs',num2str(in(5)),...
	'position',[335,65,375,75+in(5)*5]);
   tmp = get_param([blkname '/Demux'],'position');
   set_param([blkname '/Demux'],'position',tmp);
    add_line(blkname,'Sum/1','Demux/1');
    for i = 1:in(5)
      set_param([blkname '/output' num2str(i)],'Port',num2str(i),...	
	'position',[540-40*rem(i-1,4),60+i*5,560-40*rem(i-1,4),80+i*5]);
      add_line(blkname,['Demux/' num2str(i)],['output' num2str(i) '/1']);
    end;
    for i = 1:in(4)/in(5)
      add_block('built-in/Mux',[blkname '/Mux' num2str(i)]);
      set_param([blkname '/Mux' num2str(i)],'inputs',num2str(in(5)),...
	'position',[195,50+(i-1)*(40+in(5)*5),225,60+(i-1)*(40+in(5)*5)+5*in(5)]);
      autoline(blkname,['Mux' num2str(i) '/1'],['Sum/' num2str(i)]);
      for j = 1:in(5)
        set_param([blkname '/input' num2str((i-1)*in(5)+j)],...
	   'Port',num2str((i-1)*in(5)+j),...
           'position',[50+40*rem(j-1,4),50+(i-1)*(40+in(5)*5)+j*5,...
	       70+40*rem(j-1,4),70+(i-1)*(40+in(5)*5)+j*5]);
        autoline(blkname, ['input' num2str((i-1)*in(5)+j) '/1'],...
		['Mux' num2str(i) '/' num2str(j)]);
      end; %forj
    end; %for i
  end %if in(4)/in(5)
  set_param(blkname,'Mask Display','plot([2,4,3,3,3],[3,3,3,2,4],1,1,5,5)')
elseif in(3) == 5 & in(5) ==1
  set_param(blkname,'inputs',num2str(in(4)));
end;

%end of sb2slml.m

