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

add_block('built-in/Gain',[sys,'/','TM'])
set_param([sys,'/','TM'],...
		'Gain','1/TM',...
		'position',[125,282,150,308])

add_block('built-in/Sum',[sys,'/','Sum2'])
set_param([sys,'/','Sum2'],...
		'inputs','+-',...
		'position',[70,285,90,305])

add_block('built-in/Integrator',[sys,'/','Motor'])
set_param([sys,'/','Motor'],...
		'position',[180,285,200,305])

add_block('built-in/Integrator',[sys,'/',' Load'])
set_param([sys,'/',' Load'],...
		'position',[560,285,580,305])

add_block('built-in/Sum',[sys,'/','Sum4'])
set_param([sys,'/','Sum4'],...
		'inputs','+-',...
		'position',[95,110,115,130])

add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
		'inputs','-+',...
		'position',[470,285,490,305])

add_block('built-in/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'inputs','3',...
		'position',[445,99,475,131])


%     Subsystem  'Graph'.

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

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

add_block('built-in/S-Function',[sys,'/',['Graph/S-function',13,'M-file which plots',13,'lines',13,'']])
set_param([sys,'/',['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,'/','Graph'],[90,65;125,65])
set_param([sys,'/','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,'/','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,'/','Graph'],...
		'Mask Translate','color = @4; ax = [0, @1, @2, @3]; dt = -1;')
set_param([sys,'/','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,'/','Graph'],...
		'Mask Entries','251\/-0.3\/0.6\/''y-/g--/c-./w:/m*/ro/b+''\/')


%     Finished composite block 'Graph'.

set_param([sys,'/','Graph'],...
		'position',[525,96,555,134])

add_block('built-in/Zero-Order Hold',[sys,'/','Sample//Hold'])
set_param([sys,'/','Sample//Hold'],...
		'Sample time','T',...
		'position',[135,104,170,136])

add_block('built-in/Sum',[sys,'/','Sum5'])
set_param([sys,'/','Sum5'],...
		'orientation',2,...
		'inputs','+++',...
		'position',[125,192,145,228])

add_block('built-in/Gain',[sys,'/',['Load',13,'observer']])
set_param([sys,'/',['Load',13,'observer']],...
		'orientation',2,...
		'Gain','K4',...
		'position',[430,197,455,223])

add_block('built-in/Gain',[sys,'/','Spring torque'])
set_param([sys,'/','Spring torque'],...
		'orientation',2,...
		'Gain','K2',...
		'position',[235,167,260,193])

add_block('built-in/Gain',[sys,'/','Differential speed'])
set_param([sys,'/','Differential speed'],...
		'orientation',2,...
		'Gain','K1',...
		'position',[235,217,260,243])

add_block('built-in/Step Fcn',[sys,'/','Load torque'])
set_param([sys,'/','Load torque'],...
		'orientation',2,...
		'Time','T',...
		'After','-0.4',...
		'position',[565,245,585,265])

add_block('built-in/To File',[sys,'/','To File'])
set_param([sys,'/','To File'],...
		'File name','brsist_x.mat',...
		'Matrix name','brsist_x',...
		'position',[525,160,600,190])

add_block('built-in/Zero-Order Hold',[sys,'/','Sample//Hold3'])
set_param([sys,'/','Sample//Hold3'],...
		'orientation',2,...
		'Sample time','T',...
		'position',[495,194,530,226])

add_block('built-in/Integrator',[sys,'/','Spring'])
set_param([sys,'/','Spring'],...
		'position',[365,290,385,310])

add_block('built-in/Gain',[sys,'/','TF'])
set_param([sys,'/','TF'],...
		'Gain','1/TF',...
		'position',[305,287,330,313])

add_block('built-in/Sum',[sys,'/','Sum1'])
set_param([sys,'/','Sum1'],...
		'inputs','+-',...
		'position',[245,290,265,310])

add_block('built-in/Transfer Fcn',[sys,'/',['First-order',13,'time delay']])
set_param([sys,'/',['First-order',13,'time delay']],...
		'Denominator','[Tel 1]',...
		'position',[310,102,345,138])

add_block('built-in/Sum',[sys,'/','Sum3'])
set_param([sys,'/','Sum3'],...
		'inputs','+-',...
		'position',[270,110,290,130])

add_block('built-in/Gain',[sys,'/',['Motor speed',13,'dynamic error']])
set_param([sys,'/',['Motor speed',13,'dynamic error']],...
		'Gain','K3',...
		'position',[205,107,230,133])

add_block('built-in/Step Fcn',[sys,'/',['Command',13,'variable']])
set_param([sys,'/',['Command',13,'variable']],...
		'Time','T',...
		'After','0',...
		'position',[40,105,60,125])

add_block('built-in/Zero-Order Hold',[sys,'/','Sample//Hold1'])
set_param([sys,'/','Sample//Hold1'],...
		'orientation',2,...
		'Sample time','T',...
		'position',[310,164,345,196])

add_block('built-in/Zero-Order Hold',[sys,'/','Sample//Hold2'])
set_param([sys,'/','Sample//Hold2'],...
		'orientation',2,...
		'Sample time','T',...
		'position',[310,214,345,246])

add_block('built-in/Gain',[sys,'/','TL'])
set_param([sys,'/','TL'],...
		'Gain','1/TL',...
		'position',[510,282,535,308])
add_line(sys,[65,115;90,115])
add_line(sys,[560,255;455,255;465,290])
add_line(sys,[95,295;120,295])
add_line(sys,[155,295;175,295])
add_line(sys,[270,300;300,300])
add_line(sys,[335,300;360,300])
add_line(sys,[495,295;505,295])
add_line(sys,[540,295;555,295])
add_line(sys,[205,295;240,295])
add_line(sys,[390,300;465,300])
add_line(sys,[215,295;215,265;80,265;90,125])
add_line(sys,[120,210;110,210;110,160;255,160;265,125])
add_line(sys,[585,295;610,295;610,155;430,155;440,125])
add_line(sys,[480,115;520,115])
add_line(sys,[230,180;180,180;180,200;150,200])
add_line(sys,[295,120;305,120])
add_line(sys,[500,115;500,175;520,175])
add_line(sys,[120,120;130,120])
add_line(sys,[175,120;200,120])
add_line(sys,[235,120;240,120;240,115;265,115])
add_line(sys,[215,265;395,265;395,115;440,115])
add_line(sys,[425,210;150,210])
add_line(sys,[490,210;460,210])
add_line(sys,[550,255;550,210;535,210])
add_line(sys,[230,230;180,230;180,220;150,220])
add_line(sys,[305,230;265,230])
add_line(sys,[280,300;280,275;380,275;380,230;350,230])
add_line(sys,[380,230;380,105;440,105])
add_line(sys,[305,180;265,180])
add_line(sys,[410,300;410,180;350,180])
add_line(sys,[410,300;410,330;40,330;40,300;65,300])
add_line(sys,[610,295;610,345;215,345;215,305;240,305])
add_line(sys,[350,120;360,120;360,95;20,95;20,290;65,290])

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
