function [ret,x0,str,ts,xts]=onecart(t,x,u,flag);
%ONECART	is the M-file description of the SIMULINK system named ONECART.
%	The block-diagram can be displayed by typing: ONECART.
%
%	SYS=ONECART(T,X,U,FLAG) returns depending on FLAG certain
%	system values given time point, T, current state vector, X,
%	and input vector, U.
%	FLAG is used to indicate the type of output to be returned in SYS.
%
%	Setting FLAG=1 causes ONECART to return state derivatives, FLAG=2
%	discrete states, FLAG=3 system outputs and FLAG=4 next sample
%	time. For more information and other options see SFUNC.
%
%	Calling ONECART with a FLAG of zero:
%	[SIZES]=ONECART([],[],[],0),  returns a vector, SIZES, which
%	contains the sizes of the state vector and other parameters.
%		SIZES(1) number of states
%		SIZES(2) number of discrete states
%		SIZES(3) number of outputs
%		SIZES(4) number of inputs
%		SIZES(5) number of roots (currently unsupported)
%		SIZES(6) direct feedthrough flag
%		SIZES(7) number of sample times
%
%	For the definition of other parameters in SIZES, see SFUNC.
%	See also, TRIM, LINMOD, LINSIM, EULER, RK23, RK45, ADAMS, GEAR.

% Note: This M-file is only used for saving graphical information;
%       after the model is loaded into memory an internal model
%       representation is used.

% the system will take on the name of this mfile:
sys = mfilename;
new_system(sys)
simver(1.3)
if (0 == (nargin + nargout))
     set_param(sys,'Location',[39,91,571,446])
     open_system(sys)
end;
set_param(sys,'algorithm',     'Linear')
set_param(sys,'Start time',    '0')
set_param(sys,'Stop time',     '10000')
set_param(sys,'Min step size', '0.1')
set_param(sys,'Max step size', '0.1')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',   '')
set_param(sys,'Load callback','zeta=0.2;wn=1;');

add_block('built-in/Gain',[sys,'/','2*zeta*wn'])
set_param([sys,'/','2*zeta*wn'],...
		'orientation',2,...
		'Gain','2*0.2*1',...
		'position',[255,188,290,232])

add_block('built-in/Sum',[sys,'/','Sum2'])
set_param([sys,'/','Sum2'],...
		'inputs','+-',...
		'position',[250,127,270,163])

add_block('built-in/Gain',[sys,'/','wn^2'])
set_param([sys,'/','wn^2'],...
		'position',[195,111,230,159])

add_block('built-in/Integrator',[sys,'/','x2dot'])
set_param([sys,'/','x2dot'],...
		'position',[290,128,315,162])

add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
		'inputs','+-',...
		'position',[160,117,180,153])

add_block('built-in/Integrator',[sys,'/','x2'])
set_param([sys,'/','x2'],...
		'position',[355,128,380,162])

add_block('built-in/Transfer Fcn',[sys,'/','x1'])
set_param([sys,'/','x1'],...
		'Numerator','10',...
		'Denominator','[1 10]',...
		'position',[85,106,125,144])

add_block('built-in/Mux',[sys,'/','x1 & x2'])
set_param([sys,'/','x1 & x2'],...
		'inputs','2',...
		'position',[415,115,445,155])

add_block('built-in/Scope',[sys,'/',['Actual',13,'Position']])
set_param([sys,'/',['Actual',13,'Position']],...
		'Vgain','10.000000',...
		'Hgain','40.000000',...
		'Vmax','20.000000',...
		'Hmax','80.000000',...
		'Window',[335,187,623,419],...
		'position',[475,122,495,148])

add_block('built-in/Signal Generator',[sys,'/','Input'])
set_param([sys,'/','Input'],...
		'Peak','3.000000',...
		'Peak Range','Inf',...
		'Freq','0.300000',...
		'Freq Range','1.500000',...
		'Wave','Sqr',...
		'Units','Rads',...
		'position',[20,108,65,142])


%     Subsystem  'More Info'.

new_system([sys,'/','More Info'])
set_param([sys,'/','More Info'],'Location',[128,280,487,453])

add_block('built-in/Note',[sys,'/',['More Info/Try experimenting with different initial conditions and',13,'different settings for the forcing function.']])
set_param([sys,'/',['More Info/Try experimenting with different initial conditions and',13,'different settings for the forcing function.']],...
		'position',[175,115,180,120])

add_block('built-in/Note',[sys,'/',['More Info/Associated with the demo is an animation function that',13,'will automatically open a figure window and display to it.']])
set_param([sys,'/',['More Info/Associated with the demo is an animation function that',13,'will automatically open a figure window and display to it.']],...
		'position',[174,65,179,70])

add_block('built-in/Note',[sys,'/',['More Info/This system models a simple spring-mass-damper',13,'system with a periodically varying forcing function.']])
set_param([sys,'/',['More Info/This system models a simple spring-mass-damper',13,'system with a periodically varying forcing function.']],...
		'position',[168,20,173,25])
set_param([sys,'/','More Info'],...
		'Mask Display','?')


%     Finished composite block 'More Info'.

set_param([sys,'/','More Info'],...
		'hide name',0,...
		'Drop Shadow',4,...
		'position',[260,280,287,305])

add_block('built-in/Note',[sys,'/',['Mass-Spring System',13,'(Double click on the "?" for more info)']])
set_param([sys,'/',['Mass-Spring System',13,'(Double click on the "?" for more info)']],...
		'position',[130,280,135,285])

add_block('built-in/Note',[sys,'/',['To start and stop the simulation, use the "Start//Stop"',13,'selection in the "Simulation" pull-down menu']])
set_param([sys,'/',['To start and stop the simulation, use the "Start//Stop"',13,'selection in the "Simulation" pull-down menu']],...
		'position',[159,315,164,320])


%     Subsystem  'More Info1'.

new_system([sys,'/','More Info1'])
set_param([sys,'/','More Info1'],'Location',[128,280,487,453])

add_block('built-in/Note',[sys,'/',['More Info1/This system models a double pendulum system where',13,'the rest state has both pendulums hanging vertically.']])
set_param([sys,'/',['More Info1/This system models a double pendulum system where',13,'the rest state has both pendulums hanging vertically.']],...
		'position',[168,20,173,25])

add_block('built-in/Note',[sys,'/',['More Info1/Associated with the demo is an animation function that',13,'will automatically open a figure window and display to it.']])
set_param([sys,'/',['More Info1/Associated with the demo is an animation function that',13,'will automatically open a figure window and display to it.']],...
		'position',[174,65,179,70])

add_block('built-in/Note',[sys,'/',['More Info1/Try experimenting with different initial conditions for',13,'alpha and gamma to see the unusal coupling effects.']])
set_param([sys,'/',['More Info1/Try experimenting with different initial conditions for',13,'alpha and gamma to see the unusal coupling effects.']],...
		'position',[175,115,180,120])
set_param([sys,'/','More Info1'],...
		'Mask Display','Double click\nhere for\nSIMULINK Help',...
		'Mask Dialogue','eval(''[cs,cb]=get_param;str=[''''simcad '''' cs];eval(str);'')')


%     Finished composite block 'More Info1'.

set_param([sys,'/','More Info1'],...
		'hide name',0,...
		'Drop Shadow',4,...
		'position',[371,288,473,339])

add_block('built-in/S-Function',[sys,'/','Animation function'])
set_param([sys,'/','Animation function'],...
		'orientation',2,...
		'function name','crtanim1',...
		'parameters','.1',...
		'position',[255,22,320,58])
add_line(sys,[275,145;285,145])
add_line(sys,[250,210;235,210;245,155])
add_line(sys,[235,135;245,135])
add_line(sys,[320,145;350,145])
add_line(sys,[185,135;190,135])
add_line(sys,[330,145;330,210;295,210])
add_line(sys,[385,145;410,145])
add_line(sys,[395,145;395,260;140,260;140,145;155,145])
add_line(sys,[450,135;450,40;325,40])
add_line(sys,[130,125;155,125])
add_line(sys,[70,125;80,125])
add_line(sys,[450,135;470,135])
add_line(sys,[140,125;140,85;390,85;390,125;410,125])

drawnow

% Return any arguments.
if (nargin | nargout)
	% Must use feval here to access system in memory
	if (nargin > 3)
		if (flag == 0)
			eval(['[ret,x0,str,ts,xts]=',sys,'(t,x,u,flag);'])
		else
			eval(['ret =', sys,'(t,x,u,flag);'])
		end
	else
		[ret,x0,str,ts,xts] = feval(sys);
	end
else
	drawnow % Flash up the model and execute load callback
end
