function [ret,x0,str]=fohdemo(t,x,u,flag);
%FOHDEMO	is the M-file description of the SIMULINK system named FOHDEMO.
%	The block-diagram can be displayed by typing: FOHDEMO.
%
%	SYS=FOHDEMO(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 FOHDEMO to return state derivitives, FLAG=2
%	discrete states, FLAG=3 system outputs and FLAG=4 next sample
%	time. For more information and other options see SFUNC.
%
%	Calling FOHDEMO with a FLAG of zero:
%	[SIZES]=FOHDEMO([],[],[],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.
%	For the definition of other parameters in SIZES, see SFUNC.
%	See also, TRIM, LINMOD, LINSIM, EULER, RK23, RK45, ADAMS, GEAR.

%	Copyright (c) 1990-94 by The MathWorks, Inc.

% 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',[0,0,392,193])
     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',	'.01')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',	'')

add_block('built-in/Scope',[sys,'/','All Signals'])
set_param([sys,'/','All Signals'],...
		'Vgain','12',...
		'Hgain','5',...
		'Vmax','24',...
		'Hmax','10',...
		'Window',[0,0,298,205],...
		'position',[340,67,360,93])

add_block('built-in/Discrete Transfer Fcn',[sys,'/','Zero Order Hold'])
set_param([sys,'/','Zero Order Hold'],...
		'Numerator','1',...
		'Denominator','1',...
		'Sample time','Ts',...
		'Mask Display','plot(0,0,100,100,[90,70,70,50,50,30,30,10],[30,30,50,50,80,80,20,20])',...
		'Mask Type','Zero Order Hold')
set_param([sys,'/','Zero Order Hold'],...
		'Mask Dialogue','Zero Order Hold|Sample Time:',...
		'Mask Translate','Ts=@1;',...
		'Mask Help','',...
		'Mask Entries','.2\/',...
		'position',[150,124,180,156])


%     Subsystem  'First Order Hold'.

new_system([sys,'/','First Order Hold'])
set_param([sys,'/','First Order Hold'],'Location',[273,449,677,620])

add_block('built-in/Outport',[sys,'/','First Order Hold/output'])
set_param([sys,'/','First Order Hold/output'],...
		'Port','1',...
		'position',[345,45,365,65])

add_block('built-in/Inport',[sys,'/','First Order Hold/input'])
set_param([sys,'/','First Order Hold/input'],...
		'Port','1',...
		'position',[25,35,45,55])

add_block('built-in/Unit Delay',[sys,'/','First Order Hold/Unit Delay'])
set_param([sys,'/','First Order Hold/Unit Delay'],...
		'x0','0',...
		'Sample time','Ts',...
		'position',[95,93,145,117])

add_block('built-in/Discrete Transfer Fcn',[sys,'/','First Order Hold/Zero Order Hold'])
set_param([sys,'/','First Order Hold/Zero Order Hold'],...
		'Numerator','1',...
		'Denominator','1',...
		'Sample time','Ts',...
		'position',[95,27,140,63])

add_block('built-in/Sum',[sys,'/','First Order Hold/Sum'])
set_param([sys,'/','First Order Hold/Sum'],...
		'inputs','+-',...
		'position',[190,37,210,68])

add_block('built-in/Integrator',[sys,'/','First Order Hold/Integrator'])
set_param([sys,'/','First Order Hold/Integrator'],...
		'Initial','0',...
		'position',[235,42,260,68])

add_block('built-in/Gain',[sys,'/','First Order Hold/Gain'])
set_param([sys,'/','First Order Hold/Gain'],...
		'Gain','1/Ts',...
		'position',[285,33,325,77])
add_line([sys,'/','First Order Hold'],[50,45;90,45])
add_line([sys,'/','First Order Hold'],[65,45;65,105;90,105])
add_line([sys,'/','First Order Hold'],[145,45;185,45])
add_line([sys,'/','First Order Hold'],[150,105;165,105;165,60;185,60])
add_line([sys,'/','First Order Hold'],[215,55;230,55])
add_line([sys,'/','First Order Hold'],[265,55;280,55])
add_line([sys,'/','First Order Hold'],[330,55;340,55])
set_param([sys,'/','First Order Hold'],...
		'Mask Display','plot(0,0,100,100,[90,70,50,30,10],[60,40,80,30,20])',...
		'Mask Type','First Order Hold',...
		'Mask Dialogue','First Order Hold|Sample Time:',...
		'Mask Translate','Ts=@1;')
set_param([sys,'/','First Order Hold'],...
		'Mask Help','',...
		'Mask Entries','.2\/')


%     Finished composite block 'First Order Hold'.

set_param([sys,'/','First Order Hold'],...
		'position',[150,65,180,95])

add_block('built-in/Signal Generator',[sys,'/','SigGen'])
set_param([sys,'/','SigGen'],...
		'Peak','5.000000',...
		'Peak Range','5.000000',...
		'Freq','1.000000',...
		'Freq Range','5.000000',...
		'Wave','Sin',...
		'Units','Hz',...
		'position',[15,63,60,97])

add_block('built-in/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'inputs','3',...
		'position',[265,62,295,98])
add_line(sys,[185,140;240,140;240,90;260,90])
add_line(sys,[185,80;260,80])
add_line(sys,[65,80;145,80])
add_line(sys,[100,80;100,140;145,140])
add_line(sys,[100,80;100,20;240,20;240,70;260,70])
add_line(sys,[300,80;335,80])
% Return any arguments.
if (nargin | nargout)
	% Must use feval here to access system in memory
	if (nargin > 3)
		if (flag == 0)
			eval(['[ret,x0,xstr]=',sys,'(t,x,u,flag);'])
		else
			eval(['ret =', sys,'(t,x,u,flag);'])
		end
	else
		[ret,x0,str] = feval(sys);
	end
end
