function [ret,x0,str,ts,xts]=blocklib(t,x,u,flag);
%BLOCKLIB	is the M-file description of the SIMULINK system named BLOCKLIB.
%	The block-diagram can be displayed by typing: BLOCKLIB.
%
%	SYS=BLOCKLIB(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 BLOCKLIB 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 BLOCKLIB with a FLAG of zero:
%	[SIZES]=BLOCKLIB([],[],[],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',[442,153,978,616])
     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', '10')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',   '')

add_block('built-in/Note',[sys,'/','Customize your own block library and save it in a file!'])
set_param([sys,'/','Customize your own block library and save it in a file!'],...
		'position',[180,433,185,438])

add_block('built-in/Note',[sys,'/',['This block library can be opened directly by typing ''blocklib'' at the MATLAB prompt. ']])
set_param([sys,'/',['This block library can be opened directly by typing ''blocklib'' at the MATLAB prompt. ']],...
		'position',[270,415,275,420])

add_block('built-in/From Workspace',[sys,'/','From Workspace'])
set_param([sys,'/','From Workspace'],...
		'position',[430,192,470,218])

add_block('built-in/Integrator',[sys,'/','Integrator'])
set_param([sys,'/','Integrator'],...
		'position',[360,195,380,215])

add_block('built-in/Rate Limiter',[sys,'/','Rate limiter'])
set_param([sys,'/','Rate limiter'],...
		'position',[380,290,405,310])

add_block('built-in/Saturation',[sys,'/','Saturation'])
set_param([sys,'/','Saturation'],...
		'position',[385,240,410,260])

add_block('built-in/Note',[sys,'/','Other commonly used blocks:'])
set_param([sys,'/','Other commonly used blocks:'],...
		'position',[95,160,100,165])

add_block('built-in/Note',[sys,'/','Most commonly used blocks:'])
set_param([sys,'/','Most commonly used blocks:'],...
		'position',[95,15,100,20])

add_block('built-in/Filter',[sys,'/','Filter'])
set_param([sys,'/','Filter'],...
		'Denominator','[1 2]',...
		'position',[250,336,305,374])

add_block('built-in/Unit Delay',[sys,'/','Unit Delay'])
set_param([sys,'/','Unit Delay'],...
		'position',[325,347,375,363])

add_block('built-in/State-Space',[sys,'/','State-space'])
set_param([sys,'/','State-space'],...
		'position',[175,190,235,220])

add_block('built-in/Zero-Pole',[sys,'/','Zero-pole'])
set_param([sys,'/','Zero-pole'],...
		'Poles','[0; -1]',...
		'position',[105,187,150,223])

add_block('built-in/Derivative',[sys,'/','Derivative'])
set_param([sys,'/','Derivative'],...
		'position',[45,195,75,215])

add_block('built-in/Discrete State-Space',[sys,'/','Dis. State-space'])
set_param([sys,'/','Dis. State-space'],...
		'position',[35,340,135,370])

add_block('built-in/Discrete Transfer Fcn',[sys,'/','Dis. Transfer Fcn'])
set_param([sys,'/','Dis. Transfer Fcn'],...
		'Denominator','[1 0]',...
		'position',[365,97,410,133])

add_block('built-in/Discrete Zero-Pole',[sys,'/','Dis. Zero-Pole'])
set_param([sys,'/','Dis. Zero-Pole'],...
		'Poles','[0; 0.5]',...
		'position',[165,338,225,372])

add_block('built-in/S-Function',[sys,'/','S-function'])
set_param([sys,'/','S-function'],...
		'position',[220,290,270,310])

add_block('built-in/MATLAB Fcn',[sys,'/','MATLAB Fcn'])
set_param([sys,'/','MATLAB Fcn'],...
		'position',[140,285,190,315])

add_block('built-in/Transport Delay',[sys,'/','Transport Delay'])
set_param([sys,'/','Transport Delay'],...
		'Delay Time','1',...
		'position',[45,285,90,315])

add_block('built-in/Switch',[sys,'/','Switch'])
set_param([sys,'/','Switch'],...
		'position',[310,284,335,316])

add_block('built-in/Look Up Table',[sys,'/','Look Up Table'])
set_param([sys,'/','Look Up Table'],...
		'position',[305,240,330,260])

add_block('built-in/Product',[sys,'/','Product'])
set_param([sys,'/','Product'],...
		'position',[230,240,255,260])

add_block('built-in/Step Fcn',[sys,'/','Step input'])
set_param([sys,'/','Step input'],...
		'position',[50,240,70,260])

add_block('built-in/Sine Wave',[sys,'/','Sine wave'])
set_param([sys,'/','Sine wave'],...
		'position',[170,240,190,260])

add_block('built-in/Clock',[sys,'/','Clock'])
set_param([sys,'/','Clock'],...
		'position',[110,240,130,260])

add_block('built-in/To Workspace',[sys,'/','To Workspace'])
set_param([sys,'/','To Workspace'],...
		'mat-name','yout',...
		'position',[365,47,415,63])

add_block('built-in/Fcn',[sys,'/','Fcn'])
set_param([sys,'/','Fcn'],...
		'position',[285,100,325,120])

add_block('built-in/Transfer Fcn',[sys,'/','Transfer Fcn'])
set_param([sys,'/','Transfer Fcn'],...
		'Denominator','[1 0]',...
		'position',[285,37,320,73])

add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
		'position',[230,100,250,120])

add_block('built-in/Gain',[sys,'/','Gain'])
set_param([sys,'/','Gain'],...
		'position',[230,45,250,65])

add_block('built-in/Outport',[sys,'/','Outport'])
set_param([sys,'/','Outport'],...
		'position',[180,100,200,120])

add_block('built-in/Scope',[sys,'/','Scope'])
set_param([sys,'/','Scope'],...
		'Vgain','1.000000',...
		'Hgain','1.000000',...
		'Vmax','2.000000',...
		'Hmax','2.000000',...
		'Window',[100,100,380,320],...
		'position',[50,102,70,128])

add_block('built-in/Demux',[sys,'/','Demux'])
set_param([sys,'/','Demux'],...
		'outputs','2',...
		'position',[110,40,150,75])


%     Subsystem  'Simulink'.

new_system([sys,'/','Simulink'])
set_param([sys,'/','Simulink'],'Location',[-10,380,117,533])
set_param([sys,'/','Simulink'],...
		'Mask Display','Full Block\nLibrary',...
		'Mask Dialogue','eval(''simulink'')')


%     Finished composite block 'Simulink'.

set_param([sys,'/','Simulink'],...
		'position',[425,354,496,390])

add_block('built-in/Inport',[sys,'/','Inport'])
set_param([sys,'/','Inport'],...
		'position',[180,45,200,65])


%     Subsystem  'XY graph'.

new_system([sys,'/','XY graph'])
set_param([sys,'/','XY graph'],'Location',[0,0,274,193])

add_block('built-in/Inport',[sys,'/','XY graph/y'])
set_param([sys,'/','XY graph/y'],...
		'Port','2',...
		'position',[10,100,30,120])

add_block('built-in/Inport',[sys,'/','XY graph/x'])
set_param([sys,'/','XY graph/x'],...
		'position',[10,30,30,50])

add_block('built-in/Mux',[sys,'/','XY graph/Mux'])
set_param([sys,'/','XY graph/Mux'],...
		'inputs','2',...
		'position',[100,61,130,94])

add_block('built-in/S-Function',[sys,'/',['XY graph/S-function',13,'M-file which plots',13,'lines',13,'']])
set_param([sys,'/',['XY graph/S-function',13,'M-file which plots',13,'lines',13,'']],...
		'function name','sfunxy',...
		'parameters','ax',...
		'position',[185,70,235,90])
add_line([sys,'/','XY graph'],[35,110;70,110;70,85;95,85])
add_line([sys,'/','XY graph'],[35,40;70,40;70,70;95,70])
add_line([sys,'/','XY graph'],[135,80;180,80])
set_param([sys,'/','XY graph'],...
		'Mask Display','plot(0,0,100,100,[12,91,91,12,12],[90,90,45,45,90],[51,57,65,75,80,79,75,67,60,54,51,48,42,34,28,27,31,42,51],[71,68,66,66,72,79,83,84,81,77,71,60,54,54,58,65,71,74,71])')
set_param([sys,'/','XY graph'],...
		'Mask Type','XY scope.',...
		'Mask Dialogue','XY scope using MATLAB graph window.\nFirst input is used as time base.\nEnter plotting ranges.|x-min|x-max|y-min|y-max')
set_param([sys,'/','XY graph'],...
		'Mask Translate','ax = [@1, @2, @3, @4];',...
		'Mask Help','This block can be used to explore limit cycles. Look at the m-file sfunxy.m to see how it works.',...
		'Mask Entries','-10\/10\/-10\/10\/')


%     Finished composite block 'XY graph'.

set_param([sys,'/','XY graph'],...
		'position',[460,96,490,134])

add_block('built-in/Signal Generator',[sys,'/',['Signal',13,'generator']])
set_param([sys,'/',['Signal',13,'generator']],...
		'Peak','1.000000',...
		'Peak Range','5.000000',...
		'Freq','1.000000',...
		'Freq Range','5.000000',...
		'Wave','Sin',...
		'Units','Rads',...
		'position',[35,38,80,72])

add_block('built-in/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'inputs','2',...
		'position',[110,101,145,134])


%     Subsystem  'PID controller'.

new_system([sys,'/','PID controller'])
set_param([sys,'/','PID controller'],'Location',[0,0,362,244])

add_block('built-in/Sum',[sys,'/','PID controller/Sum'])
set_param([sys,'/','PID controller/Sum'],...
		'inputs','+++',...
		'position',[245,57,265,93])

add_block('built-in/Gain',[sys,'/','PID controller/D'])
set_param([sys,'/','PID controller/D'],...
		'Gain','D',...
		'position',[95,129,115,151])

add_block('built-in/Gain',[sys,'/','PID controller/Proportional'])
set_param([sys,'/','PID controller/Proportional'],...
		'Gain','P',...
		'position',[120,13,140,37])

add_block('built-in/Transfer Fcn',[sys,'/','PID controller/Integral'])
set_param([sys,'/','PID controller/Integral'],...
		'Numerator','[I]',...
		'Denominator','[1 0]',...
		'position',[110,57,145,93])

add_block('built-in/Derivative',[sys,'/','PID controller/Derivative'])
set_param([sys,'/','PID controller/Derivative'],...
		'position',[150,128,190,152])

add_block('built-in/Outport',[sys,'/','PID controller/Out_1'])
set_param([sys,'/','PID controller/Out_1'],...
		'position',[290,65,310,85])

add_block('built-in/Inport',[sys,'/','PID controller/In_1'])
set_param([sys,'/','PID controller/In_1'],...
		'position',[25,65,45,85])
add_line([sys,'/','PID controller'],[120,140;145,140])
add_line([sys,'/','PID controller'],[270,75;285,75])
add_line([sys,'/','PID controller'],[50,75;105,75])
add_line([sys,'/','PID controller'],[65,75;65,140;90,140])
add_line([sys,'/','PID controller'],[80,75;80,25;115,25])
add_line([sys,'/','PID controller'],[195,140;215,140;215,85;240,85])
add_line([sys,'/','PID controller'],[150,75;240,75])
add_line([sys,'/','PID controller'],[145,25;210,25;210,65;240,65])
set_param([sys,'/','PID controller'],...
		'Mask Display','PID',...
		'Mask Type','PID Controller',...
		'Mask Dialogue','Enter expressions for proportional, integral, and derivative terms.\nP+I/s+Ds|Proportional:|Integral|Derivative:')
set_param([sys,'/','PID controller'],...
		'Mask Translate','P=@1; I=@2; D=@3;')
set_param([sys,'/','PID controller'],...
		'Mask Help','This block implements a PID controller where parameters are entered for the Proportional, Integral and Derivative terms. Unmask this block to see how it works. The derivative term is implemented using a true derivative block.')
set_param([sys,'/','PID controller'],...
		'Mask Entries','1\/1\/0\/')


%     Finished composite block 'PID controller'.

set_param([sys,'/','PID controller'],...
		'position',[275,189,315,221])

add_block('built-in/Constant',[sys,'/','Constant'])
set_param([sys,'/','Constant'],...
		'position',[450,240,470,260])


%     Subsystem  ['Auto-Scale',13,'Graph'].

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

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

add_block('built-in/S-Function',[sys,'/',['Auto-Scale',13,'Graph/S-function',13,'M-file which plots',13,'lines',13,'']])
set_param([sys,'/',['Auto-Scale',13,'Graph/S-function',13,'M-file which plots',13,'lines',13,'']],...
		'function name','sfunyst',...
		'parameters','ax, color, npts, dt',...
		'position',[130,55,180,75])
add_line([sys,'/',['Auto-Scale',13,'Graph']],[90,65;125,65])
set_param([sys,'/',['Auto-Scale',13,'Graph']],...
		'Mask Display','plot(0,0,100,100,[83,76,63,52,42,38,28,16,11,84,11,11,11,90,90,11],[75,58,47,54,72,80,84,74,65,65,65,90,40,40,90,90])',...
		'Mask Type','Storage scope.')
set_param([sys,'/',['Auto-Scale',13,'Graph']],...
		'Mask Dialogue','Storage scope using MATLAB graph window.\nEnter plotting ranges and line type.|Initial Time Range:|Initial y-min:|Initial y-max:|Storage pts.:|Line type (rgbw-.:xo):|Sample time:')
set_param([sys,'/',['Auto-Scale',13,'Graph']],...
		'Mask Translate','npts = @4; color = @5; ax = [0, @1, @2, @3]; dt=@6;')
set_param([sys,'/',['Auto-Scale',13,'Graph']],...
		'Mask Help','Uses MATLAB''s graph window.\nUse only one block per system.\nLine type must be in quotes.\nSee the M-file sfunyst.m.')
set_param([sys,'/',['Auto-Scale',13,'Graph']],...
		'Mask Entries','5\/-10\/10\/200\/''y-/g--/c-./w:/m*/ro/b+''\/.1\/')


%     Finished composite block ['Auto-Scale',13,'Graph'].

set_param([sys,'/',['Auto-Scale',13,'Graph']],...
		'position',[455,25,485,65])

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
