function [ret,x0,str,ts,xts]=fsgen(t,x,u,flag);
%FSGEN	is the M-file description of the SIMULINK system named FSGEN.
%	The block-diagram can be displayed by typing: FSGEN.
%
%	SYS=FSGEN(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 FSGEN 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 FSGEN with a FLAG of zero:
%	[SIZES]=FSGEN([],[],[],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',[17,79,517,379])
     open_system(sys)
end;
set_param(sys,'algorithm',     'RK-45')
set_param(sys,'Start time',    '0.0')
set_param(sys,'Stop time',     '999999')
set_param(sys,'Min step size', '0.0001')
set_param(sys,'Max step size', '0.01')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',   '')

add_block('built-in/Sine Wave',[sys,'/','Sine, freq = 3'])
set_param([sys,'/','Sine, freq = 3'],...
		'frequency','3*2*pi',...
		'position',[55,115,75,135])

add_block('built-in/Sine Wave',[sys,'/','Sine, freq = 5'])
set_param([sys,'/','Sine, freq = 5'],...
		'frequency','5*2*pi',...
		'position',[55,175,75,195])

add_block('built-in/Gain',[sys,'/',['Slider',13,'Gain 2']])
set_param([sys,'/',['Slider',13,'Gain 2']],...
		'Gain','0',...
		'Mask Display','0',...
		'Mask Dialogue','eval(''slideg(-1,0,1,0)'');',...
		'position',[170,111,220,139])

add_block('built-in/Gain',[sys,'/',['Slider',13,'Gain 3']])
set_param([sys,'/',['Slider',13,'Gain 3']],...
		'Gain','0',...
		'Mask Display','0',...
		'Mask Dialogue','eval(''slideg(-1,0,1,0)'');',...
		'position',[170,171,220,199])

add_block('built-in/Gain',[sys,'/',['Slider',13,'Gain 1']])
set_param([sys,'/',['Slider',13,'Gain 1']],...
		'Mask Display','1',...
		'Mask Dialogue','eval(''slideg(-1,1,1,0)'');',...
		'position',[170,41,220,69])

add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
		'inputs','+++',...
		'position',[305,107,325,143])


%     Subsystem  'Sum Graph'.

new_system([sys,'/','Sum Graph'])
set_param([sys,'/','Sum Graph'],'Location',[0,59,274,252])

add_block('built-in/Inport',[sys,'/','Sum Graph/x'])
set_param([sys,'/','Sum Graph/x'],...
		'position',[65,55,85,75])

add_block('built-in/S-Function',[sys,'/',['Sum Graph/S-function',13,'M-file which plots',13,'lines',13,'']])
set_param([sys,'/',['Sum Graph/S-function',13,'M-file which plots',13,'lines',13,'']],...
		'function name','sfuny',...
		'parameters','ax, color,dt',...
		'position',[130,55,180,75])
add_line([sys,'/','Sum Graph'],[90,65;125,65])
set_param([sys,'/','Sum Graph'],...
		'Mask Display','plot(0,0,100,100,[90,10,10,10,90,90,10],[65,65,90,40,40,90,90],[90,78,69,54,40,31,25,10],[77,60,48,46,56,75,81,84])',...
		'Mask Type','Graph scope.')
set_param([sys,'/','Sum Graph'],...
		'Mask Dialogue','Graph scope using MATLAB graph window.\nEnter plotting ranges and line type.|Time range:|y-min:|y-max:|Line type (rgbw-:*). Seperate each plot by ''/'':')
set_param([sys,'/','Sum Graph'],...
		'Mask Translate','color = @4; ax = [0, @1, @2, @3]; dt = -1;')
set_param([sys,'/','Sum Graph'],...
		'Mask Help','This block plots to the MATLAB graph window and can be used as an improved version of the Scope block. Look at the m-file sfuny.m to see how it works. This block can take scalar or vector input signal.')
set_param([sys,'/','Sum Graph'],...
		'Mask Entries','2\/-2\/2\/''y-/g--/c-./w:/m*/ro/b+''\/')


%     Finished composite block 'Sum Graph'.

set_param([sys,'/','Sum Graph'],...
		'position',[385,106,415,144])

add_block('built-in/Sine Wave',[sys,'/','Sine, freq = 1'])
set_param([sys,'/','Sine, freq = 1'],...
		'frequency','2*pi',...
		'position',[60,45,80,65])

add_block('built-in/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'inputs','3',...
		'position',[180,239,210,271])


%     Subsystem  'Sine Graphs'.

new_system([sys,'/','Sine Graphs'])
set_param([sys,'/','Sine Graphs'],'Location',[0,59,274,252])

add_block('built-in/Inport',[sys,'/','Sine Graphs/x'])
set_param([sys,'/','Sine Graphs/x'],...
		'position',[65,55,85,75])

add_block('built-in/S-Function',[sys,'/',['Sine Graphs/S-function',13,'M-file which plots',13,'lines',13,'']])
set_param([sys,'/',['Sine Graphs/S-function',13,'M-file which plots',13,'lines',13,'']],...
		'function name','sfuny',...
		'parameters','ax, color,dt',...
		'position',[130,55,180,75])
add_line([sys,'/','Sine Graphs'],[90,65;125,65])
set_param([sys,'/','Sine Graphs'],...
		'Mask Display','plot(0,0,100,100,[90,10,10,10,90,90,10],[65,65,90,40,40,90,90],[90,78,69,54,40,31,25,10],[77,60,48,46,56,75,81,84])',...
		'Mask Type','Graph scope.')
set_param([sys,'/','Sine Graphs'],...
		'Mask Dialogue','Graph scope using MATLAB graph window.\nEnter plotting ranges and line type.|Time range:|y-min:|y-max:|Line type (rgbw-:*). Seperate each plot by ''/'':')
set_param([sys,'/','Sine Graphs'],...
		'Mask Translate','color = @4; ax = [0, @1, @2, @3]; dt = -1;')
set_param([sys,'/','Sine Graphs'],...
		'Mask Help','This block plots to the MATLAB graph window and can be used as an improved version of the Scope block. Look at the m-file sfuny.m to see how it works. This block can take scalar or vector input signal.')
set_param([sys,'/','Sine Graphs'],...
		'Mask Entries','2\/-2\/2\/''y-/g--/c-./w:/m*/ro/b+''\/')


%     Finished composite block 'Sine Graphs'.

set_param([sys,'/','Sine Graphs'],...
		'position',[265,236,295,274])
add_line(sys,[85,55;165,55])
add_line(sys,[80,125;165,125])
add_line(sys,[80,185;165,185])
add_line(sys,[225,55;255,55;255,115;300,115])
add_line(sys,[225,125;300,125])
add_line(sys,[225,185;255,185;255,135;300,135])
add_line(sys,[330,125;380,125])
add_line(sys,[215,255;260,255])
add_line(sys,[85,55;120,55;120,245;175,245])
add_line(sys,[80,125;120,125;120,255;175,255])
add_line(sys,[80,185;120,185;120,265;175,265])

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
