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


%     Subsystem  'blackbox'.

new_system([sys,'/','blackbox'])
set_param([sys,'/','blackbox'],'Location',[20,6553690,375,6554000])

add_block('built-in/Integrator',[sys,'/','blackbox/Integrator'])
set_param([sys,'/','blackbox/Integrator'],...
		'Initial','1.2',...
		'position',[185,85,205,105])

add_block('built-in/Transport Delay',[sys,'/',['blackbox/Transport',13,'Delay']])
set_param([sys,'/',['blackbox/Transport',13,'Delay']],...
		'orientation',2,...
		'Delay Time','17',...
		'position',[150,200,190,230])

add_block('built-in/Mux',[sys,'/','blackbox/Mux'])
set_param([sys,'/','blackbox/Mux'],...
		'orientation',2,...
		'inputs','2',...
		'position',[85,171,120,229])

add_block('built-in/Note',[sys,'/','blackbox/x(t)'])
set_param([sys,'/','blackbox/x(t)'],...
		'position',[230,70,235,75])

add_block('built-in/Fcn',[sys,'/','blackbox/Fcn'])
set_param([sys,'/','blackbox/Fcn'],...
		'Expr','-0.1*u[1]+0.2*u[2]/(1+power(u[2],10))',...
		'position',[95,80,130,110])

add_block('built-in/Zero-Order Hold',[sys,'/',['blackbox/Zero-Order',13,'Hold']])
set_param([sys,'/',['blackbox/Zero-Order',13,'Hold']],...
		'position',[275,79,310,111])

add_block('built-in/Outport',[sys,'/','blackbox/out_1'])
set_param([sys,'/','blackbox/out_1'],...
		'position',[340,85,360,105])
add_line([sys,'/','blackbox'],[210,95;235,95;235,215;195,215])
add_line([sys,'/','blackbox'],[235,185;125,185])
add_line([sys,'/','blackbox'],[80,200;70,200;70,95;90,95])
add_line([sys,'/','blackbox'],[145,215;125,215])
add_line([sys,'/','blackbox'],[135,95;180,95])
add_line([sys,'/','blackbox'],[210,95;270,95])
add_line([sys,'/','blackbox'],[315,95;335,95])


%     Finished composite block 'blackbox'.

set_param([sys,'/','blackbox'],...
		'position',[185,87,245,143])

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
