function [ret,x0,str,ts,xts]=extrconv(t,x,u,flag);
%EXTRCONV	is the M-file description of the SIMULINK system named EXTRCONV.
%	The block-diagram can be displayed by typing: EXTRCONV.
%
%	SYS=EXTRCONV(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 EXTRCONV 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 EXTRCONV with a FLAG of zero:
%	[SIZES]=EXTRCONV([],[],[],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',[126,137,284,544])
     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,'/','Conversion Library'])
set_param([sys,'/','Conversion Library'],...
		'position',[70,10,75,15])


%     Subsystem  'Cartesian to Spherical'.

new_system([sys,'/','Cartesian to Spherical'])
set_param([sys,'/','Cartesian to Spherical'],'Location',[0,0,623,352])

add_block('built-in/Mux',[sys,'/','Cartesian to Spherical/Mux1'])
set_param([sys,'/','Cartesian to Spherical/Mux1'],...
		'hide name',0,...
		'inputs','2',...
		'position',[315,107,345,143])

add_block('built-in/Fcn',[sys,'/','Cartesian to Spherical/r'])
set_param([sys,'/','Cartesian to Spherical/r'],...
		'Expr','hypot(u[1],u[2])',...
		'position',[395,112,500,138])

add_block('built-in/Fcn',[sys,'/','Cartesian to Spherical/theta'])
set_param([sys,'/','Cartesian to Spherical/theta'],...
		'Expr','atan2(u[1],u[2])',...
		'position',[395,299,500,321])

add_block('built-in/Outport',[sys,'/','Cartesian to Spherical/r '])
set_param([sys,'/','Cartesian to Spherical/r '],...
		'position',[560,115,580,135])

add_block('built-in/Outport',[sys,'/','Cartesian to Spherical/phi '])
set_param([sys,'/','Cartesian to Spherical/phi '],...
		'Port','2',...
		'position',[560,205,580,225])

add_block('built-in/Outport',[sys,'/','Cartesian to Spherical/theta '])
set_param([sys,'/','Cartesian to Spherical/theta '],...
		'Port','3',...
		'position',[565,300,585,320])

add_block('built-in/Inport',[sys,'/','Cartesian to Spherical/z'])
set_param([sys,'/','Cartesian to Spherical/z'],...
		'Port','3',...
		'position',[20,159,40,181])

add_block('built-in/Fcn',[sys,'/','Cartesian to Spherical/temp'])
set_param([sys,'/','Cartesian to Spherical/temp'],...
		'Expr','hypot(u[1],u[2])',...
		'position',[155,102,260,128])

add_block('built-in/Mux',[sys,'/','Cartesian to Spherical/Mux'])
set_param([sys,'/','Cartesian to Spherical/Mux'],...
		'hide name',0,...
		'inputs','2',...
		'position',[75,97,105,133])

add_block('built-in/Inport',[sys,'/','Cartesian to Spherical/x'])
set_param([sys,'/','Cartesian to Spherical/x'],...
		'position',[20,70,40,90])

add_block('built-in/Inport',[sys,'/','Cartesian to Spherical/y'])
set_param([sys,'/','Cartesian to Spherical/y'],...
		'Port','2',...
		'position',[20,114,40,136])

add_block('built-in/Note',[sys,'/','Cartesian to Spherical/Cartesian to Polar'])
set_param([sys,'/','Cartesian to Spherical/Cartesian to Polar'],...
		'position',[165,30,170,35])

add_block('built-in/Fcn',[sys,'/','Cartesian to Spherical/phi'])
set_param([sys,'/','Cartesian to Spherical/phi'],...
		'Expr','atan2(u[2],u[1])',...
		'position',[390,204,495,226])
add_line([sys,'/','Cartesian to Spherical'],[350,125;390,125])
add_line([sys,'/','Cartesian to Spherical'],[360,125;360,310;390,310])
add_line([sys,'/','Cartesian to Spherical'],[505,310;560,310])
add_line([sys,'/','Cartesian to Spherical'],[500,215;555,215])
add_line([sys,'/','Cartesian to Spherical'],[110,115;150,115])
add_line([sys,'/','Cartesian to Spherical'],[125,115;125,215;385,215])
add_line([sys,'/','Cartesian to Spherical'],[505,125;555,125])
add_line([sys,'/','Cartesian to Spherical'],[45,170;255,170;255,135;310,135])
add_line([sys,'/','Cartesian to Spherical'],[265,115;310,115])
add_line([sys,'/','Cartesian to Spherical'],[45,80;70,105])
add_line([sys,'/','Cartesian to Spherical'],[45,125;70,125])
set_param([sys,'/','Cartesian to Spherical'],...
		'Mask Display','plot(0,0,100,100,[45,40,35,40,40],[85,95,85,95,30],[22,10,14,10,40,95,85,95,85],[12,10,20,10,30,30,25,30,35],[70,40],[80,30],[54,52,50,47,44,40],[53,55,56,58,59,59])')
set_param([sys,'/','Cartesian to Spherical'],...
		'Mask Type','[x,y,z]->[r,phi,theta]',...
		'Mask Dialogue','Tranformation from cartesian to spherical\ncoordinates. p=hypot(x,y), r=hypot(p,z)\nphi=atan(y/x), theta=atan(p/z)')
set_param([sys,'/','Cartesian to Spherical'],...
		'Mask Help','Unmask this block for more help.')


%     Finished composite block 'Cartesian to Spherical'.

set_param([sys,'/','Cartesian to Spherical'],...
		'position',[50,287,90,343])


%     Subsystem  'Polar to Cartesian'.

new_system([sys,'/','Polar to Cartesian'])
set_param([sys,'/','Polar to Cartesian'],'Location',[0,0,359,206])

add_block('built-in/Fcn',[sys,'/','Polar to Cartesian/r->x'])
set_param([sys,'/','Polar to Cartesian/r->x'],...
		'Expr','u[1]*cos(u[2])',...
		'position',[155,72,260,98])

add_block('built-in/Fcn',[sys,'/','Polar to Cartesian/theta->y'])
set_param([sys,'/','Polar to Cartesian/theta->y'],...
		'Expr','u[1]*sin(u[2])',...
		'position',[160,129,265,151])

add_block('built-in/Mux',[sys,'/','Polar to Cartesian/Mux'])
set_param([sys,'/','Polar to Cartesian/Mux'],...
		'hide name',0,...
		'inputs','2',...
		'position',[75,96,105,129])

add_block('built-in/Outport',[sys,'/','Polar to Cartesian/x'])
set_param([sys,'/','Polar to Cartesian/x'],...
		'position',[295,75,315,95])

add_block('built-in/Inport',[sys,'/','Polar to Cartesian/r '])
set_param([sys,'/','Polar to Cartesian/r '],...
		'position',[20,70,40,90])

add_block('built-in/Inport',[sys,'/','Polar to Cartesian/theta '])
set_param([sys,'/','Polar to Cartesian/theta '],...
		'Port','2',...
		'position',[20,129,40,151])

add_block('built-in/Outport',[sys,'/','Polar to Cartesian/y'])
set_param([sys,'/','Polar to Cartesian/y'],...
		'Port','2',...
		'position',[295,130,315,150])

add_block('built-in/Note',[sys,'/','Polar to Cartesian/Polar to Cartesian'])
set_param([sys,'/','Polar to Cartesian/Polar to Cartesian'],...
		'position',[170,25,175,30])
add_line([sys,'/','Polar to Cartesian'],[110,115;125,115;125,85;150,85])
add_line([sys,'/','Polar to Cartesian'],[125,115;125,140;155,140])
add_line([sys,'/','Polar to Cartesian'],[265,85;290,85])
add_line([sys,'/','Polar to Cartesian'],[45,80;70,105])
add_line([sys,'/','Polar to Cartesian'],[45,140;70,120])
add_line([sys,'/','Polar to Cartesian'],[270,140;290,140])
set_param([sys,'/','Polar to Cartesian'],...
		'Mask Display','plot(0,0,100,100,[25,20,15,20,20],[85,95,85,95,20],[70,20,95,86,95,85],[60,20,20,15,20,25],[70,70],[45,54],[70,70],[30,40],[70,70],[20,25],[55,65],[60,60],[40,50],[60,60],[25,34],[60,60],[20,21],[60,60],[70,70,68],[57,60,60])')
set_param([sys,'/','Polar to Cartesian'],...
		'Mask Type','[r,theta]->[x,y]',...
		'Mask Dialogue','Tranformation from polar to cartesian\ncoordinates.\nx=rcos(theta), y=rsin(theta)',...
		'Mask Help','Unmask this block for more help.')


%     Finished composite block 'Polar to Cartesian'.

set_param([sys,'/','Polar to Cartesian'],...
		'position',[50,41,85,94])


%     Subsystem  'Cartesian to Polar'.

new_system([sys,'/','Cartesian to Polar'])
set_param([sys,'/','Cartesian to Polar'],'Location',[0,0,359,206])

add_block('built-in/Note',[sys,'/','Cartesian to Polar/Cartesian to Polar'])
set_param([sys,'/','Cartesian to Polar/Cartesian to Polar'],...
		'position',[165,30,170,35])

add_block('built-in/Outport',[sys,'/','Cartesian to Polar/theta'])
set_param([sys,'/','Cartesian to Polar/theta'],...
		'Port','2',...
		'position',[295,130,315,150])

add_block('built-in/Inport',[sys,'/','Cartesian to Polar/y'])
set_param([sys,'/','Cartesian to Polar/y'],...
		'Port','2',...
		'position',[20,129,40,151])

add_block('built-in/Inport',[sys,'/','Cartesian to Polar/x'])
set_param([sys,'/','Cartesian to Polar/x'],...
		'position',[20,70,40,90])

add_block('built-in/Outport',[sys,'/','Cartesian to Polar/r'])
set_param([sys,'/','Cartesian to Polar/r'],...
		'position',[295,75,315,95])

add_block('built-in/Mux',[sys,'/','Cartesian to Polar/Mux'])
set_param([sys,'/','Cartesian to Polar/Mux'],...
		'inputs','2',...
		'position',[75,96,105,129])

add_block('built-in/Fcn',[sys,'/','Cartesian to Polar/x->theta'])
set_param([sys,'/','Cartesian to Polar/x->theta'],...
		'Expr','atan2(u[2],u[1])',...
		'position',[160,129,265,151])

add_block('built-in/Fcn',[sys,'/','Cartesian to Polar/x->r'])
set_param([sys,'/','Cartesian to Polar/x->r'],...
		'Expr','hypot(u[1],u[2])',...
		'position',[155,72,260,98])
add_line([sys,'/','Cartesian to Polar'],[270,140;290,140])
add_line([sys,'/','Cartesian to Polar'],[45,140;70,120])
add_line([sys,'/','Cartesian to Polar'],[45,80;70,105])
add_line([sys,'/','Cartesian to Polar'],[265,85;290,85])
add_line([sys,'/','Cartesian to Polar'],[110,115;125,115;125,85;150,85])
add_line([sys,'/','Cartesian to Polar'],[125,115;125,140;155,140])
set_param([sys,'/','Cartesian to Polar'],...
		'Mask Display','plot(0,0,100,100,[24,20,15,20,20],[85,95,85,95,20],[80,20,95,85,95,85],[70,20,20,15,20,24],[56,56,55,52,50,46],[20,26,31,35,38,42])',...
		'Mask Type','[x,y]->[r,theta]')
set_param([sys,'/','Cartesian to Polar'],...
		'Mask Dialogue','Tranformation from cartesian to polar\ncoordinates.\nr=sqrt(x^2+y^2), theta=atan(y/x)',...
		'Mask Help','Unmask this block for more help.')


%     Finished composite block 'Cartesian to Polar'.

set_param([sys,'/','Cartesian to Polar'],...
		'position',[50,122,85,173])


%     Subsystem  'Spherical to Cartesian'.

new_system([sys,'/','Spherical to Cartesian'])
set_param([sys,'/','Spherical to Cartesian'],'Location',[0,0,623,352])

add_block('built-in/Inport',[sys,'/','Spherical to Cartesian/phi'])
set_param([sys,'/','Spherical to Cartesian/phi'],...
		'Port','3',...
		'position',[20,114,40,136])

add_block('built-in/Inport',[sys,'/','Spherical to Cartesian/theta'])
set_param([sys,'/','Spherical to Cartesian/theta'],...
		'Port','2',...
		'position',[20,164,40,186])

add_block('built-in/Note',[sys,'/','Spherical to Cartesian/Spherical to cartesian'])
set_param([sys,'/','Spherical to Cartesian/Spherical to cartesian'],...
		'position',[165,30,170,35])

add_block('built-in/Inport',[sys,'/','Spherical to Cartesian/r'])
set_param([sys,'/','Spherical to Cartesian/r'],...
		'position',[20,70,40,90])

add_block('built-in/Mux',[sys,'/','Spherical to Cartesian/Mux'])
set_param([sys,'/','Spherical to Cartesian/Mux'],...
		'hide name',0,...
		'inputs','2',...
		'position',[75,97,105,133])

add_block('built-in/Fcn',[sys,'/','Spherical to Cartesian/temp'])
set_param([sys,'/','Spherical to Cartesian/temp'],...
		'Expr','u[1]*sin(u[2])',...
		'position',[155,102,260,128])

add_block('built-in/Outport',[sys,'/','Spherical to Cartesian/Z'])
set_param([sys,'/','Spherical to Cartesian/Z'],...
		'Port','3',...
		'position',[565,305,585,325])

add_block('built-in/Outport',[sys,'/','Spherical to Cartesian/Y'])
set_param([sys,'/','Spherical to Cartesian/Y'],...
		'Port','2',...
		'position',[560,210,580,230])

add_block('built-in/Outport',[sys,'/','Spherical to Cartesian/X'])
set_param([sys,'/','Spherical to Cartesian/X'],...
		'position',[560,115,580,135])

add_block('built-in/Fcn',[sys,'/','Spherical to Cartesian/z'])
set_param([sys,'/','Spherical to Cartesian/z'],...
		'Expr','u[1]*cos(u[2])',...
		'position',[395,304,500,326])

add_block('built-in/Fcn',[sys,'/','Spherical to Cartesian/y'])
set_param([sys,'/','Spherical to Cartesian/y'],...
		'Expr','u[1]*sin(u[2])',...
		'position',[395,209,500,231])

add_block('built-in/Fcn',[sys,'/','Spherical to Cartesian/x'])
set_param([sys,'/','Spherical to Cartesian/x'],...
		'Expr','u[1]*cos(u[2])',...
		'position',[395,112,500,138])

add_block('built-in/Mux',[sys,'/','Spherical to Cartesian/Mux1'])
set_param([sys,'/','Spherical to Cartesian/Mux1'],...
		'hide name',0,...
		'inputs','2',...
		'position',[315,107,345,143])
add_line([sys,'/','Spherical to Cartesian'],[110,115;150,115])
add_line([sys,'/','Spherical to Cartesian'],[125,115;125,315;390,315])
add_line([sys,'/','Spherical to Cartesian'],[350,125;390,125])
add_line([sys,'/','Spherical to Cartesian'],[365,125;365,220;390,220])
add_line([sys,'/','Spherical to Cartesian'],[45,175;280,175;280,135;310,135])
add_line([sys,'/','Spherical to Cartesian'],[45,125;70,125])
add_line([sys,'/','Spherical to Cartesian'],[45,80;70,105])
add_line([sys,'/','Spherical to Cartesian'],[265,115;310,115])
add_line([sys,'/','Spherical to Cartesian'],[505,125;555,125])
add_line([sys,'/','Spherical to Cartesian'],[505,220;555,220])
add_line([sys,'/','Spherical to Cartesian'],[505,315;560,315])
set_param([sys,'/','Spherical to Cartesian'],...
		'Mask Display','plot(0,0,100,100,[45,40,35,40,40],[85,95,85,95,40],[85,95,85,95,40],[35,40,45,40,40],[60,40,10,20,10,14],[70,40,10,13,10,20],[56,45],[70,70],[60,60],[50,60],[60,60],[30,40],[50,60],[20,20],[30,40],[20,20],[45,55],[35,25],[75,65],[35,25])')
set_param([sys,'/','Spherical to Cartesian'],...
		'Mask Type','[r,phi,theta]->[x,y,z]',...
		'Mask Dialogue','Tranformation from spherical to cartesian\ncoordinates.x=rsin(phi)cos(theta)\ny=rsin(phi)sin(theta), z=rcos(phi)')
set_param([sys,'/','Spherical to Cartesian'],...
		'Mask Help','Unmask this block for more help.')


%     Finished composite block 'Spherical to Cartesian'.

set_param([sys,'/','Spherical to Cartesian'],...
		'position',[50,198,90,252])

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
