function varargout=xdevdemo(varargin)
%XDEVDEMO Gatway function used to call XDEV demos
%
% DEMOLIST = XDEVDEMO returns the list of valide demos that can be
% used with this function. DESCRIPTION = XDEVDEMO(DEMONUMBER)returns
% the desription for demos in a specific category if DEMONUMBER is a
% multiple of 100 (i.e. 100, 200, 300, ...). If DEMONUMBER is a valid
% identifier for a demo, then the description of the particular demo
% is returned.
%
% WFORMOUT=XDEVDEMO(DEMONUMBER,WFORMIN1, ...) executes demo DEMONUMBER
% by passing WFORMIN1 and any additional input arguments to that demo.
%
% Example:
% WformOut = xdevdemo(101,WformIn1);
%
% To get help on demo 101
% xdevdemo(101)
%
% See also DEMOS.
% $Author: Tgaudett $Revision: 1.0 $ $Date: 9/30/02 10:20a $
% Testing:
% This function was tested on the WAVEMASTER series scope.
%
% $Notes:
% $EndNotes
switch (nargin)
case 0
help xdevdemo
str=buildfunctionlist(0,['D:\Scripts']);
helptxt = buildhelp(str);
disp(sprintf('Current function list includes:'));
disp(helptxt)
if nargout==1
varargout{1}=str;
end;
case 1
str=buildfunctionlist(varargin{1},['D:\Scripts']);
if length(str)==1
help(str{1})
else
helptxt = buildhelp(str);
disp(helptxt);
end
if nargout==1
varargout{1}=str;
end;
otherwise
wformout = [];
fname = sprintf('xdevdemo%d',varargin{1});
if (exist(fname,'file'));
try
wformout = feval(fname,varargin{2:end});
catch
msg=lasterror;
errorstr = char(msg.message(25:end));
disp(sprintf('%s\nProblem calling function. Check arguments.',errorstr));
end;
disp([getH1Line(fname)]);
else
disp('Incorrect function number. Type xdevdemo for help');
end;
if ~isempty(wformout)
varargout{1} = wformout;
else
varargout{1} = [];
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Local Functions
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function str=buildfunctionlist(subsystem,strpath)
%
%
%
if isempty(strpath)
x=what;
else
x=what(strpath);
end;
filelist = {x.m{:},x.mex{:},x.p{:}};
for c=1:length(filelist)
filelist{c}=filelist{c}(1:end-2);
end;
filelist = unique(filelist);
if subsystem == 0
token = 'xdevdemo';
elseif (floor(subsystem/100)*100==subsystem)
token = sprintf('xdevdemo%d',floor(subsystem/100));
else
token = sprintf('xdevdemo%d',subsystem);
end;
str = findtoken(filelist,token);
str = sort(str);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function str = findtoken(flist,token)
%
%
%
str = [];
for c=1:length(flist)
if strfind(flist{c},token)
str{end+1}=flist{c};
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function helptxt = buildhelp(str);
%
%
%
helptxt = [];
for c=1:length(str)
x = help(str{c});
idx=strfind(x,sprintf('\n'));
number = str2num(x(10:13));
if isempty(number)
helptxt(end+1:idx(1)+end-6)=sprintf('000 %s',x(11:idx(1)));
elseif (floor(number/100)*100==number)
helptxt(end+1:idx(1)+end-8)=sprintf('\n%s',x(10:idx(1)));
else
helptxt(end+1:idx(1)+end-8)=sprintf('\t%s',x(10:idx(1)));
end;
end;
helptxt=char(helptxt);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function h1text=getH1Line(str)
try
x = help(str);
catch
x=sprintf('No Help avalible\n');
end;
idx=strfind(x,sprintf('\n'));
h1text=strrep(x(1:idx(1)-1),upper(str),'');
%Remove Leading Spaces
while(strcmp(h1text(1),' '))
h1text=h1text(2:end);
end;