function [ret,x0,str]=logdemo(t,x,u,flag);
%LOGDEMO	is the M-file description of the SIMULINK system named LOGDEMO.
%	The block-diagram can be displayed by typing: LOGDEMO.
%
%	SYS=LOGDEMO(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 LOGDEMO 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 LOGDEMO with a FLAG of zero:
%	[SIZES]=LOGDEMO([],[],[],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.

% 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',[335,535,1042,882])
     open_system(sys)
end;
set_param(sys,'algorithm',     'RK-45')
set_param(sys,'Start time',    '0.0')
set_param(sys,'Stop time',     '9.9')
set_param(sys,'Min step size', '0.005')
set_param(sys,'Max step size', '.01')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',   '')

add_block('built-in/Note',[sys,'/','Digital Pulse Generator'])
set_param([sys,'/','Digital Pulse Generator'],...
		'position',[390,15,395,20])

add_block('built-in/Note',[sys,'/',['This system takes the output of the Modulo-4 counter and ',13,'generates a 1//2 clock cycle width pulse on every fourth clock pulse.',13,'Effectively, it produces a pulse whenever the value of the counter ',13,'output is one (01).']])
set_param([sys,'/',['This system takes the output of the Modulo-4 counter and ',13,'generates a 1//2 clock cycle width pulse on every fourth clock pulse.',13,'Effectively, it produces a pulse whenever the value of the counter ',13,'output is one (01).']],...
		'position',[390,46,395,51])


%     Subsystem  'D flip-flop'.

new_system([sys,'/','D flip-flop'])
set_param([sys,'/','D flip-flop'],'Location',[105,262,408,422])

add_block('built-in/Demux',[sys,'/','D flip-flop/Demux'])
set_param([sys,'/','D flip-flop/Demux'],...
		'outputs','2',...
		'position',[210,50,250,85])

add_block('built-in/Mux',[sys,'/','D flip-flop/Mux1'])
set_param([sys,'/','D flip-flop/Mux1'],...
		'inputs','3',...
		'position',[80,47,110,93])

add_block('built-in/Combinatorial Logic',[sys,'/','D flip-flop/Logic'])
set_param([sys,'/','D flip-flop/Logic'],...
		'Truth Table','[0 1;1 0;0 1;1 0;0 1;0 1;1 0;1 0]',...
		'position',[130,50,185,90])

add_block('built-in/Transport Delay',[sys,'/','D flip-flop/Transport Delay'])
set_param([sys,'/','D flip-flop/Transport Delay'],...
		'orientation',2,...
		'position',[140,115,185,145])

add_block('built-in/Inport',[sys,'/','D flip-flop/in_1'])
set_param([sys,'/','D flip-flop/in_1'],...
		'Port','2',...
		'position',[30,45,50,65])

add_block('built-in/Outport',[sys,'/','D flip-flop/out_1'])
set_param([sys,'/','D flip-flop/out_1'],...
		'position',[290,50,310,70])

add_block('built-in/Outport',[sys,'/','D flip-flop/out_2'])
set_param([sys,'/','D flip-flop/out_2'],...
		'Port','2',...
		'position',[280,65,300,85])

add_block('built-in/Inport',[sys,'/','D flip-flop/in_2'])
set_param([sys,'/','D flip-flop/in_2'],...
		'position',[30,60,50,80])
add_line([sys,'/','D flip-flop'],[115,70;125,70])
add_line([sys,'/','D flip-flop'],[190,70;205,70])
add_line([sys,'/','D flip-flop'],[255,60;275,60;275,130;190,130])
add_line([sys,'/','D flip-flop'],[135,130;55,130;55,85;75,85])
add_line([sys,'/','D flip-flop'],[55,55;75,55])
add_line([sys,'/','D flip-flop'],[55,70;75,70])
add_line([sys,'/','D flip-flop'],[255,60;285,60])
add_line([sys,'/','D flip-flop'],[255,75;275,75])
set_param([sys,'/','D flip-flop'],...
		'Mask Display','D   1\n\n>   0',...
		'Mask Type','D flip-flop',...
		'Mask Dialogue','D flip-flop')
set_param([sys,'/','D flip-flop'],...
		'Mask Help','While the clock signal is high, the ouput will be the same as the input signal.  The flip-flop then latches to the value of the input at the trailing edge of the clock pulse for the remainder to the clock cycle.')


%     Finished composite block 'D flip-flop'.

set_param([sys,'/','D flip-flop'],...
		'Drop Shadow',4,...
		'position',[395,152,430,203])


%     Subsystem  ['Modulo-4',13,'Counter'].

new_system([sys,'/',['Modulo-4',13,'Counter']])
set_param([sys,'/',['Modulo-4',13,'Counter']],'Location',[474,84,1019,428])

add_block('built-in/Outport',[sys,'/',['Modulo-4',13,'Counter/Low-Order',13,'Bit']])
set_param([sys,'/',['Modulo-4',13,'Counter/Low-Order',13,'Bit']],...
		'Port','2',...
		'position',[250,145,270,165])

add_block('built-in/Outport',[sys,'/',['Modulo-4',13,'Counter/High-Order',13,'Bit']])
set_param([sys,'/',['Modulo-4',13,'Counter/High-Order',13,'Bit']],...
		'position',[420,120,440,140])

add_block('built-in/Constant',[sys,'/',['Modulo-4',13,'Counter/Constant']])
set_param([sys,'/',['Modulo-4',13,'Counter/Constant']],...
		'position',[60,110,80,130])

add_block('built-in/Note',[sys,'/',['Modulo-4',13,'Counter/This system ouputs the binary sequence',13,'11 00 01 10']])
set_param([sys,'/',['Modulo-4',13,'Counter/This system ouputs the binary sequence',13,'11 00 01 10']],...
		'position',[265,35,270,40])

add_block('built-in/Inport',[sys,'/',['Modulo-4',13,'Counter/Clock']])
set_param([sys,'/',['Modulo-4',13,'Counter/Clock']],...
		'ForeGround',6,...
		'position',[60,200,80,220])


%     Subsystem  ['Modulo-4',13,'Counter/JK flip-flop1'].

new_system([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],'Location',[337,161,940,393])

add_block('built-in/Outport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/out_1']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/out_1']],...
		'position',[550,90,570,110])

add_block('built-in/Outport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/out_2']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/out_2']],...
		'Port','2',...
		'position',[520,105,540,125])

add_block('built-in/Demux',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/Demux']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/Demux']],...
		'outputs','2',...
		'position',[435,90,475,125])

add_block('built-in/Combinatorial Logic',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/Logic']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/Logic']],...
		'Truth Table','[0 1;1 0;0 1;1 0;0 1;1 0;0 1;1 0;0 1;1 0;0 1;0 1;1 0;1 0;1 0;0 1]',...
		'position',[360,90,415,130])

add_block('built-in/Mux',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/Mux']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/Mux']],...
		'position',[300,87,330,133])


%     Subsystem  ['Modulo-4',13,'Counter/JK flip-flop1/AND'].

new_system([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND']],'Location',[59,237,323,377])

add_block('built-in/Outport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND/out_1']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND/out_1']],...
		'position',[215,65,235,85])

add_block('built-in/Combinatorial Logic',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND/AND']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND/AND']],...
		'Truth Table','[0;0;0;1]',...
		'position',[130,55,185,95])

add_block('built-in/Mux',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND/Mux']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND/Mux']],...
		'inputs','2',...
		'position',[65,55,95,90])

add_block('built-in/Inport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND/in_1']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND/in_1']],...
		'position',[15,55,35,75])

add_block('built-in/Inport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND/in_2']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND/in_2']],...
		'Port','2',...
		'position',[15,70,35,90])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND']],[100,75;125,75])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND']],[40,65;60,65])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND']],[40,80;60,80])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND']],[190,75;210,75])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND']],...
		'Mask Display','AND',...
		'Mask Type','AND',...
		'Mask Dialogue','AND Gate',...
		'Mask Help','Calculates the logical AND of the two inputs.')


%     Finished composite block ['Modulo-4',13,'Counter/JK flip-flop1/AND'].

set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/AND']],...
		'position',[200,34,235,61])

add_block('built-in/Combinatorial Logic',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/NOT1']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/NOT1']],...
		'Truth Table','[1;0]',...
		'Mask Display','NOT',...
		'Mask Type','NOT',...
		'Mask Dialogue','NOT Gate',...
		'Mask Help','Negates the input.')
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/NOT1']],...
		'position',[135,28,170,52])

add_block('built-in/Transport Delay',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/Transport Delay1']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/Transport Delay1']],...
		'Initial Input','1',...
		'position',[65,25,115,55])

add_block('built-in/Inport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/in_1']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/in_1']],...
		'Port','2',...
		'position',[15,75,35,95])

add_block('built-in/Inport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/in_2']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/in_2']],...
		'position',[50,95,70,115])

add_block('built-in/Inport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/in_3']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/in_3']],...
		'Port','3',...
		'position',[75,105,95,125])

add_block('built-in/Fcn',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/Fcn']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/Fcn']],...
		'orientation',2,...
		'Expr','u[1]>.2',...
		'position',[290,175,330,195])

add_block('built-in/Transport Delay',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/Transport Delay']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1/Transport Delay']],...
		'orientation',2,...
		'Initial Input','ini',...
		'position',[400,170,445,200])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],[480,100;500,100;500,185;450,185])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],[335,110;355,110])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],[420,110;430,110])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],[480,100;545,100])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],[480,115;515,115])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],[100,115;295,115])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],[75,105;295,105])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],[40,85;40,40;60,40])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],[120,40;130,40])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],[175,40;195,40])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],[40,85;175,85;175,55;195,55])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],[240,50;255,50;255,95;295,95])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],[395,185;335,185])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],[285,185;250,185;250,125;295,125])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],...
		'Mask Display','J    1\n\n>        \n\nK    0',...
		'Mask Type','JK flip-flop',...
		'Mask Dialogue','JK flip-flop|Initial State for Output "1":')
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],...
		'Mask Translate','ini=(@1~=0);')
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],...
		'Mask Help','When the clock signal is high, if the uncomp- lemented output is currently zero and J becomes one, the output will change to one.  K has no effect on the output in this case.  If the current value of the uncomplemented output is one and K becomes one, the output will change to zero.  J will have no effect on the output in this case.  The system clock period is used to set the state feedback delay of the flip-flop.')
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],...
		'Mask Entries','0\/')


%     Finished composite block ['Modulo-4',13,'Counter/JK flip-flop1'].

set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop1']],...
		'Drop Shadow',4,...
		'position',[155,107,200,183])


%     Subsystem  ['Modulo-4',13,'Counter/JK flip-flop2'].

new_system([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],'Location',[337,161,940,393])

add_block('built-in/Transport Delay',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/Transport Delay']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/Transport Delay']],...
		'orientation',2,...
		'Initial Input','ini',...
		'position',[400,170,445,200])

add_block('built-in/Fcn',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/Fcn']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/Fcn']],...
		'orientation',2,...
		'Expr','u[1]>.2',...
		'position',[290,175,330,195])

add_block('built-in/Inport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/in_3']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/in_3']],...
		'Port','3',...
		'position',[75,105,95,125])

add_block('built-in/Inport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/in_2']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/in_2']],...
		'position',[50,95,70,115])

add_block('built-in/Inport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/in_1']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/in_1']],...
		'Port','2',...
		'position',[15,75,35,95])

add_block('built-in/Transport Delay',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/Transport Delay1']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/Transport Delay1']],...
		'Initial Input','1',...
		'position',[65,25,115,55])

add_block('built-in/Combinatorial Logic',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/NOT1']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/NOT1']],...
		'Truth Table','[1;0]',...
		'Mask Display','NOT',...
		'Mask Type','NOT',...
		'Mask Dialogue','NOT Gate',...
		'Mask Help','Negates the input.')
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/NOT1']],...
		'position',[135,28,170,52])


%     Subsystem  ['Modulo-4',13,'Counter/JK flip-flop2/AND'].

new_system([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND']],'Location',[59,237,323,377])

add_block('built-in/Inport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND/in_2']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND/in_2']],...
		'Port','2',...
		'position',[15,70,35,90])

add_block('built-in/Inport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND/in_1']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND/in_1']],...
		'position',[15,55,35,75])

add_block('built-in/Mux',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND/Mux']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND/Mux']],...
		'inputs','2',...
		'position',[65,55,95,90])

add_block('built-in/Combinatorial Logic',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND/AND']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND/AND']],...
		'Truth Table','[0;0;0;1]',...
		'position',[130,55,185,95])

add_block('built-in/Outport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND/out_1']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND/out_1']],...
		'position',[215,65,235,85])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND']],[190,75;210,75])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND']],[40,80;60,80])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND']],[40,65;60,65])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND']],[100,75;125,75])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND']],...
		'Mask Display','AND',...
		'Mask Type','AND',...
		'Mask Dialogue','AND Gate',...
		'Mask Help','Calculates the logical AND of the two inputs.')


%     Finished composite block ['Modulo-4',13,'Counter/JK flip-flop2/AND'].

set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/AND']],...
		'position',[200,34,235,61])

add_block('built-in/Mux',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/Mux']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/Mux']],...
		'position',[300,87,330,133])

add_block('built-in/Combinatorial Logic',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/Logic']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/Logic']],...
		'Truth Table','[0 1;1 0;0 1;1 0;0 1;1 0;0 1;1 0;0 1;1 0;0 1;0 1;1 0;1 0;1 0;0 1]',...
		'position',[360,90,415,130])

add_block('built-in/Demux',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/Demux']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/Demux']],...
		'outputs','2',...
		'position',[435,90,475,125])

add_block('built-in/Outport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/out_2']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/out_2']],...
		'Port','2',...
		'position',[520,105,540,125])

add_block('built-in/Outport',[sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/out_1']])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2/out_1']],...
		'position',[550,90,570,110])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],[285,185;250,185;250,125;295,125])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],[395,185;335,185])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],[240,50;255,50;255,95;295,95])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],[40,85;175,85;175,55;195,55])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],[175,40;195,40])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],[120,40;130,40])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],[40,85;40,40;60,40])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],[75,105;295,105])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],[100,115;295,115])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],[480,115;515,115])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],[480,100;545,100])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],[420,110;430,110])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],[335,110;355,110])
add_line([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],[480,100;500,100;500,185;450,185])
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],...
		'Mask Display','J    1\n\n>        \n\nK    0',...
		'Mask Type','JK flip-flop',...
		'Mask Dialogue','JK flip-flop|Initial State for Output "1":')
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],...
		'Mask Translate','ini=(@1~=0);')
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],...
		'Mask Help','When the clock signal is high, if the uncomp- lemented output is currently zero and J becomes one, the output will change to one.  K has no effect on the output in this case.  If the current value of the uncomplemented output is one and K becomes one, the output will change to zero.  J will have no effect on the output in this case.  The system clock period is used to set the state feedback delay of the flip-flop.')
set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],...
		'Mask Entries','0\/')


%     Finished composite block ['Modulo-4',13,'Counter/JK flip-flop2'].

set_param([sys,'/',['Modulo-4',13,'Counter/JK flip-flop2']],...
		'Drop Shadow',4,...
		'position',[325,112,370,188])
add_line([sys,'/',['Modulo-4',13,'Counter']],[85,120;150,120])
add_line([sys,'/',['Modulo-4',13,'Counter']],[130,120;130,170;150,170])
add_line([sys,'/',['Modulo-4',13,'Counter']],[85,210;100,210;100,145;150,145])
add_line([sys,'/',['Modulo-4',13,'Counter']],[100,210;290,210;290,150;320,150])
add_line([sys,'/',['Modulo-4',13,'Counter']],[205,125;320,125])
add_line([sys,'/',['Modulo-4',13,'Counter']],[300,125;300,175;320,175])
add_line([sys,'/',['Modulo-4',13,'Counter']],[375,130;415,130])
add_line([sys,'/',['Modulo-4',13,'Counter']],[225,125;225,155;245,155])


%     Finished composite block ['Modulo-4',13,'Counter'].

set_param([sys,'/',['Modulo-4',13,'Counter']],...
		'ForeGround',2,...
		'Drop Shadow',4,...
		'position',[150,120,180,175])

add_block('built-in/Note',[sys,'/','ouput pulse'])
set_param([sys,'/','ouput pulse'],...
		'position',[640,210,645,215])

add_block('built-in/Note',[sys,'/','clock'])
set_param([sys,'/','clock'],...
		'position',[620,270,625,275])

add_block('built-in/Note',[sys,'/','counter MSB'])
set_param([sys,'/','counter MSB'],...
		'position',[645,230,650,235])

add_block('built-in/Note',[sys,'/','counter LSB'])
set_param([sys,'/','counter LSB'],...
		'position',[640,250,645,255])


%     Subsystem  'Display'.

new_system([sys,'/','Display'])
set_param([sys,'/','Display'],'Location',[426,219,899,692])

add_block('built-in/Inport',[sys,'/','Display/in_3'])
set_param([sys,'/','Display/in_3'],...
		'Port','3',...
		'position',[25,230,45,250])

add_block('built-in/Inport',[sys,'/','Display/in_2'])
set_param([sys,'/','Display/in_2'],...
		'Port','2',...
		'position',[25,205,45,225])

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

add_block('built-in/Inport',[sys,'/','Display/in_4'])
set_param([sys,'/','Display/in_4'],...
		'Port','4',...
		'position',[25,255,45,275])

add_block('built-in/Mux',[sys,'/','Display/Mux'])
set_param([sys,'/','Display/Mux'],...
		'position',[160,173,190,282])

add_block('built-in/Scope',[sys,'/','Display/Scope'])
set_param([sys,'/','Display/Scope'],...
		'Vgain','2.700000',...
		'Hgain','10.000000',...
		'Vmax','5.400000',...
		'Hmax','20.000000',...
		'Window',[538,277,922,443])
open_system([sys,'/','Display/Scope'])
set_param([sys,'/','Display/Scope'],...
		'position',[315,212,335,238])

add_block('built-in/Sum',[sys,'/','Display/Sum'])
set_param([sys,'/','Display/Sum'],...
		'position',[240,215,260,235])

add_block('built-in/Constant',[sys,'/','Display/Constant'])
set_param([sys,'/','Display/Constant'],...
		'Value','[1.3 0.1 -1.2 -2.4]',...
		'position',[80,108,190,132])
add_line([sys,'/','Display'],[195,120;215,120;215,220;235,220])
add_line([sys,'/','Display'],[265,225;310,225])
add_line([sys,'/','Display'],[195,230;235,230])
add_line([sys,'/','Display'],[50,215;155,215])
add_line([sys,'/','Display'],[50,190;155,190])
add_line([sys,'/','Display'],[50,240;155,240])
add_line([sys,'/','Display'],[50,265;155,265])


%     Finished composite block 'Display'.

set_param([sys,'/','Display'],...
		'Drop Shadow',4,...
		'position',[555,206,595,294])


%     Subsystem  'Clock'.

new_system([sys,'/','Clock'])
set_param([sys,'/','Clock'],'Location',[471,305,910,612])

add_block('built-in/Constant',[sys,'/','Clock/Constant'])
set_param([sys,'/','Clock/Constant'],...
		'position',[25,25,45,45])

add_block('built-in/Outport',[sys,'/','Clock/out_1'])
set_param([sys,'/','Clock/out_1'],...
		'position',[240,30,260,50])

add_block('built-in/Unit Delay',[sys,'/','Clock/Unit Delay'])
set_param([sys,'/','Clock/Unit Delay'],...
		'orientation',2,...
		'Sample time','duration',...
		'position',[125,80,175,100])

add_block('built-in/Sum',[sys,'/','Clock/Sum'])
set_param([sys,'/','Clock/Sum'],...
		'inputs','+-',...
		'position',[115,30,135,50])
add_line([sys,'/','Clock'],[140,40;235,40])
add_line([sys,'/','Clock'],[120,90;85,90;85,45;110,45])
add_line([sys,'/','Clock'],[140,40;210,40;210,90;180,90])
add_line([sys,'/','Clock'],[50,35;110,35])
set_param([sys,'/','Clock'],...
		'Mask Display','plot(0,0,100,100,[90,75,75,60,60,35,35,20,20,10],[20,20,80,80,19,20,80,80,20,20])',...
		'Mask Type','Digital clock')
set_param([sys,'/','Clock'],...
		'Mask Dialogue','Digital clock.\nOutput is set to 1 for the first half of the period.|Period:',...
		'Mask Translate','duration = @1/2;',...
		'Mask Help','Digital clock for logic systems.')
set_param([sys,'/','Clock'],...
		'Mask Entries','1\/')


%     Finished composite block 'Clock'.

set_param([sys,'/','Clock'],...
		'ForeGround',6,...
		'position',[60,266,100,294])

add_block('built-in/Logical Operator',[sys,'/',['Logical',13,'operator']])
set_param([sys,'/',['Logical',13,'operator']],...
		'hide name',0,...
		'Operator','AND',...
		'position',[475,157,510,188])

add_block('built-in/Logical Operator',[sys,'/',['Logical',13,'operator3']])
set_param([sys,'/',['Logical',13,'operator3']],...
		'hide name',0,...
		'Operator','AND',...
		'position',[330,121,360,174])

add_block('built-in/Logical Operator',[sys,'/',['Logical',13,'operator1']])
set_param([sys,'/',['Logical',13,'operator1']],...
		'hide name',0,...
		'Operator','NOT',...
		'Number of Input Ports','1',...
		'position',[330,180,360,200])

add_block('built-in/Logical Operator',[sys,'/',['Logical',13,'operator2']])
set_param([sys,'/',['Logical',13,'operator2']],...
		'hide name',0,...
		'Operator','NOT',...
		'Number of Input Ports','1',...
		'position',[270,150,300,170])
add_line(sys,[185,135;325,135])
add_line(sys,[365,150;375,150;375,165;390,165])
add_line(sys,[305,160;325,160])
add_line(sys,[185,160;265,160])
add_line(sys,[365,190;390,190])
add_line(sys,[435,165;470,165])
add_line(sys,[105,280;550,280])
add_line(sys,[305,280;305,190;325,190])
add_line(sys,[120,280;120,150;145,150])
add_line(sys,[210,160;210,260;550,260])
add_line(sys,[230,135;230,240;550,240])
add_line(sys,[515,175;535,175;535,220;550,220])
add_line(sys,[450,280;450,180;470,180])

% 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]=',sys,'(t,x,u,flag);'])
		else
			eval(['ret =', sys,'(t,x,u,flag);'])
		end
	else
		[ret,x0,str] = feval(sys);
	end
end
