function varargout = strsplit(str, varargin)
% ------------------------------------------------------------------
% Split a string into an array of tokens. 
%
% SYNOPSIS:
%
%   
%   f = strsplit(str)
%   [f, n] = strsplit(str)
%   f = strsplit(str, delim)
%   [f, n] = strsplit(str, delim)
%
% PARAMETERS:
%
%   str
%      String to split.
%
%   delim
%      Character vector defining valid delimiters. If not present,
%      white spaces are used (see `strtok').
%
% RETURNS:
%
%   f
%      Array of strings containing each field.
%
%   n
%      Number of elements in `f'.
%
% ------------------------------------------------------------------
%Time:<Last updated on 98/07/14 at 19:03:56 by veins@PC159>
%File:<c:/codas3/gfi/matlab/matlab50/strsplit.m>

delim = [];
if nargin > 1,
  delim = varargin{1};
end

for i=1:nargout,
  varargout{i} = NaN;
end

% Get each token:
f = [];
rem = str;
while length(rem) > 0,
  if length(delim)>0,
	 [tok, rem] = strtok(rem, delim);
  else
	 [tok, rem] = strtok(rem);
  end
  f = strvcat(f, tok);
end

varargout{1} = f;
if nargout > 1,
  varargout{2} = size(f,1);
end


  
