function sb2slspr(blkname,in,fl,cod,timer)
%SB2SLSPR converts spring-mass-damper blocks to SIMULINK.
%	SB2SLSPR(BLKNAME,IN,FL,COD,TIMER) 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 and real number FL.
%
%       COD is a three dimensional vector. The first element indicates
%       whether it is a continuous (0) or discrete (1) time system.
%       The second element indicates whether it does not need (0) or
%       does need (1) a mask. The third element indicates the
%       orientation of the block.
%
%       TIMER is designed for discrete time only. The first element of
%       TIMER is the sampling time. The second element is the initial time.

% Wes Wang 1/10/93
% Copyright (c) 1990-93 by The MathWorks, Inc.
% $Revision: 1.16 $  $Date: 1993/06/10 18:42:14 $

% in = [8, code1 code2, input, output, state,....
%   (input - 1)/output - 1 = highest order resettable   
% This block is designed for discrete and continuous systems.OB
%
% This block works for the case of in(2) == 4
% and                              in(3) == 10

% findout whether it is a zero initial condition or not.
x0=[0 0];
if in(35) ~= 0
 for i=1:in(35)
  x0(in(35+in(35)+i)) = fl(i);
 end;
end;

if cod(1) == 0
  %     Subsystem  'Continuous Spring Cart'.
  set_param([blkname,'/output2'],...
	'Port','2',...
	'position',[430,100,450,120])
  set_param([blkname,'/output1'],...
	'position',[430,55,450,75])
  set_param([blkname,'/input4'],...
	'orientation',2,...
	'Port','4',...
	'position',[420,165,440,185])
  add_block('built-in/Integrator',[blkname,'/Integrator1'])
  set_param([blkname,'/Integrator1'],...
	'Initial','x0(2)',...
	'position',[340,55,360,75])
  set_param([blkname,'/input3'],...
	'orientation',2,...
	'Port','3',...
	'position',[325,115,345,135])
  add_block('built-in/Integrator',[blkname,'/Integrator'])
  set_param([blkname,'/Integrator'],...
	'Initial','x0(1)',...
	'position',[260,55,280,75])
  add_block('built-in/Product',[blkname,'/Product1'])
  set_param([blkname,'/Product1'],...
	'position',[195,49,220,76])
  set_param([blkname,'/input2'],...
	'Port','2',...
	'position',[140,60,160,80])
  add_block('built-in/Product',[blkname,'/Product3'])
  set_param([blkname,'/Product3'],...
	'orientation',2,...
	'position',[210,154,240,181])
  add_block('built-in/Product',[blkname,'/Product2'])
  set_param([blkname,'/Product2'],...
	'orientation',2,...
	'position',[210,104,240,131])
  add_block('built-in/Sum',[blkname,'/Sum'])
  set_param([blkname,'/Sum'],...
	'inputs','+--',...
	'position',[95,37,115,73])
  set_param([blkname,'/input1'],...
	'position',[30,35,50,55])
  autoline(blkname,'input1/1','Sum/1');
  autoline(blkname,'Product2/1','Sum/2',[],[2,0]);
  autoline(blkname,'Product3/1','Sum/3',[],[2,0]);
  autoline(blkname,'Sum/1','Product1/1');
  autoline(blkname,'input2/1','Product1/2');
  autoline(blkname,'Product1/1','Integrator/1');
  autoline(blkname,'Integrator/1','Integrator1/1');
  autoline(blkname,'Integrator1/1','output1/1');
  autoline(blkname,'Integrator/1','output2/1');
  autoline(blkname,'input3/1','Product2/2',[],[2,2]);
  autoline(blkname,'Integrator/1','Product2/1',[],[0,2]);
  autoline(blkname,'input4/1','Product3/2',[],[2,2]);
  autoline(blkname,'Integrator1/1','Product3/1',[],[0,2]);
  set_param(blkname,'Mask Display',...
     'Time-Varying\nDifferential\nEquation');
%    'u1=u2x''''+u3x''+u4x\ny1=x\ny2=x''');
%   'plot(0,0,20,20,[1,1],[1,19],[1,4],[5,5],[7,4,4,7],[7,7,3,3],[5,5],[4,6],[5,10],[5,5],[1,3.5,4,5,6,7,8,8.5,10],[15,15,18,12,18,12,18,15,15],[9,19],[2,2],[10,10,18,18],[2,17,17,2],[12,12,14,16,16],[4,15,10,15,4])')
  set_param(blkname,'Mask Type','Spring Mass Damper',...
	'Mask Dialogue','Spring Mass Damper\nFor input u1,u2,u3,u4, output y1,y2.\nu1=u2*x''''+u3*x''+u4*x; y1=x; y2=x''.|Initial conditions:',...
	'Mask Translate','x0=@1')
  set_param(blkname,...
   'Mask Help','SPRING MASS DAMPER The Spring Mass Damper solves the second-order differential equation with time-varying coefficients:\nu1=u2*d(dx/dt)/dt+u3*dx/dt+u4*x; the outputs of the block are: y1=x; y2=dx/dt.',...
	'Mask Entries',[mat2str(x0) '\/'])
else  %discrete time case
  T = timer(1);
  %     Subsystem  'Discrete Spring Cart'.
  set_param([blkname,'/input1'],...
		'position',[30,35,50,55])
  add_block('built-in/Sum',[blkname,'/Sum'])
  set_param([blkname,'/Sum'],...
		'inputs','+--',...
		'position',[95,37,115,73])
  set_param([blkname,'/input2'],...
		'Port','2',...
		'position',[140,60,160,80])
  add_block('built-in/Product',[blkname,'/Product1'])
  set_param([blkname,'/Product1'],...
		'position',[195,49,220,76])
  add_block('built-in/Gain',[blkname,'/Gain'])
  set_param([blkname,'/Gain'],...
		'Gain','T',...
		'position',[250,55,270,75])
  add_block('built-in/Sum',[blkname,'/Sum1'])
  set_param([blkname,'/Sum1'],...
		'position',[300,60,320,80])
  add_block('built-in/Gain',[blkname,'/Gain1'])
  set_param([blkname,'/Gain1'],...
		'Gain','T',...
		'position',[380,60,400,80])
  add_block('built-in/Sum',[blkname,'/Sum2'])
  set_param([blkname,'/Sum2'],...
		'position',[425,65,445,85])
  set_param([blkname,'/input4'],...
		'orientation',2,...
		'Port','4',...
		'position',[290,210,310,230])
  set_param([blkname,'/input3'],...
		'orientation',2,...
		'Port','3',...
		'position',[285,160,305,180])
  add_block('built-in/Product',[blkname,'/Product2'])
  set_param([blkname,'/Product2'],...
		'orientation',2,...
		'position',[210,149,240,176])
  add_block('built-in/Product',[blkname,'/Product3'])
  set_param([blkname,'/Product3'],...
		'orientation',2,...
		'position',[210,199,240,226])
  add_block('built-in/Unit Delay',[blkname,'/Unit Delay'])
  set_param([blkname,'/Unit Delay'],...
		'orientation',2,...
		'x0','x0(1)',...
		'Sample time','T',...
		'position',[300,110,330,130])
  add_block('built-in/Unit Delay',[blkname,'/Unit Delay1'])
  set_param([blkname,'/Unit Delay1'],...
		'orientation',2,...
		'x0','x0(2)',...
		'Sample time','T',...
		'position',[425,110,455,130])
  set_param([blkname,'/output1'],...
		'position',[525,65,545,85])
  set_param([blkname,'/output2'],...
		'Port','2',...
		'position',[530,145,550,165])
  autoline(blkname,'input1/1','Sum/1');
  autoline(blkname,'Product2/1','Sum/2',[],[2,0]);
  autoline(blkname,'Product3/1','Sum/3',[],[2,0]);
  autoline(blkname,'Sum/1','Product1/1');
  autoline(blkname,'input2/1','Product1/2');
  autoline(blkname,'Product1/1','Gain/1');
  autoline(blkname,'Gain/1','Sum1/1');
  autoline(blkname,'Unit Delay/1','Sum1/2',[],[2,0]);
  autoline(blkname,'Sum1/1','Gain1/1');
  autoline(blkname,'Sum1/1','output2/1');
  autoline(blkname,'Sum1/1','Unit Delay/1',[],[0,2]);
  autoline(blkname,'Gain1/1','Sum2/1');
  autoline(blkname,'Sum2/1','output1/1');
  autoline(blkname,'Unit Delay1/1','Sum2/2',[],[2,0]);
  autoline(blkname,'Sum2/1','Unit Delay1/1',[],[0,2]);
  autoline(blkname,'input3/1','Product2/1',[],[2,2]);
  autoline(blkname,'Sum1/1','Product2/2',[],[0,2]);
  autoline(blkname,'input4/1','Product3/1',[],[2,2]);
  autoline(blkname,'Sum2/1','Product3/2',[],[0,2]);
  set_param(blkname,'Mask Display',...
     'Time-Varying\nDifferential\nEquation');
%    'u1=u2x''''+u3x''+u4x\ny1=x\ny2=x''');
%   'plot(0,0,20,20,[1,1],[1,19],[1,4],[5,5],[7,4,4,7],[7,7,3,3],[5,5],[4,6],[5,10],[5,5],[1,3.5,4,5,6,7,8,8.5,10],[15,15,18,12,18,12,18,15,15],[9,19],[2,2],[10,10,18,18],[2,17,17,2],[12,12,14,16,16],[4,15,10,15,4])')
  set_param(blkname,...
    'Mask Type','Spring Mass Damper',...
    'Mask Dialogue','Discretisized Spring Mass Damper\nBlock input u1,u2,u3,u4, output y1,y2.\nu1=u2*d(dx)+u3*dx+u4*x; y1=x; y2=dx.|Initial condition:|Sampling time:',...
    'Mask Translate','x0=@1;T=@2;')
  set_param(blkname,'Mask Type','Spring Mass Damper',...
	'Mask Dialogue','Spring Mass Damper\nFor input u1,u2,u3,u4, output y1,y2.\nu1=u2*x''''+u3*x''+u4*x; y1=x; y2=x''.|Initial conditions:|Sampling Time:',...
	'Mask Translate','x0=@1;T=@2')
  set_param(blkname,...
   'Mask Help','DISCRETE SPRING MASS DAMPER The Spring Mass Damper solves the second-order differential equation with time-varying coefficients:\nu1=u2*d(dx/dt)/dt+u3*dx/dt+u4*x; the outputs of the block are: y1=x; y2=dx/dt.',...
   'Mask Entries',[mat2str(x0) '\/' num2str(T) '\/'])
end;

