function [CAM,Cam,st]=comstr(CAM,ind,opt)

if nargin==2&isstr(ind) %initial string comparison

   if ~isstr(CAM); CAM=0;
   elseif ~isempty(ind) & length(CAM)>=length(ind)
    if all(CAM(1:length(ind))==ind) CAM=1;return; end
   end
   CAM=0; return;

elseif isstr(ind)&nargin>2 % parameter extraction utility

   if length(CAM)<length(ind) ind=ind(1:length(CAM));end
   if ~isempty(ind)
    i1=min([find(lower(CAM(1:length(ind)))~=lower(ind)) ...
         length(ind)+1 length(CAM)+1]);
    CAM=CAM(i1:length(CAM));
   end
   if ~isempty(CAM)
    i1=find(CAM==','); if ~isempty(i1) CAM(i1)=setstr(32*ones(size(i1)));end
    i1=find(CAM==''''); if ~isempty(i1) CAM(i1)=setstr(32*ones(size(i1)));end
   end
   if isstr(opt) % format given
     if comstr(opt,'%s') [i1,i2,i3,i4]=sscanf(CAM,opt,1);
     else [i1,i2,i3,i4]=sscanf(CAM,opt);end
     Cam=CAM(i4:length(CAM));CAM=i1(:)';
     if ~isempty(Cam)
      ind = find(Cam~=32);ind = [min(ind):max(ind)];
      if ~isempty(ind) Cam = Cam(ind); else Cam=[]; end
     end
     if nargout==3 st=lower(Cam);
     elseif nargout<=2 & isstr(CAM) 
      if strcmp(opt,'%c') [CAM,Cam]=comstr(CAM,1);
      else Cam=lower(CAM); end
     end
   else Cam=lower(CAM); end % return the string

elseif length(ind)==1 & ind(1)>0  % eliminate front and tail blanks

   CAM = CAM(ind:length(CAM));

   if ~isempty(CAM)
    ind = find(CAM~=32&CAM~=0);
    if ~isempty(ind)
       CAM = CAM(ind(1):ind(length(ind))); Cam=lower(CAM);
    else CAM='';Cam='';end
   else Cam=''; end

elseif ind(1)==-1 % find numbers with error and default handling

   if ~isempty(CAM) i1 = find(CAM~=32&CAM~=10&CAM~=13);
     if ~isempty(i1) i1=min(i1):max(i1); end
   else i1=[]; end
   if length(i1)>0 & length(i1)<length(CAM) CAM=CAM(min(i1):max(i1)); end
   eval(['CAM=[' CAM '];'],'CAM=[];')

   if length(ind)>1
	i1 = length(CAM)+1:length(ind)-1;
	if ~isempty(i1) CAM(i1) = ind(i1+1); end	  
   end

elseif ind(1)==-8 % Extract string with matching {} 
  % [extract,CAM,Cam] 

  i1=find(CAM==opt(1)|CAM==opt(2));
  if isempty(i1) Cam=CAM;st=lower(Cam);CAM='';return; end
  i2=0; for j1=i1
    if     CAM(j1)==opt(1) i2=i2+1; 
    elseif CAM(j1)==opt(2) i2=i2-1; end
    if i2<0 error(sprintf('''%s'' contains non matching %s',CAM,opt));end
    if i2==0 break; end
  end
  Cam=CAM;Cam(i1(1):j1)=' '; st=lower(Cam); CAM=CAM(i1(1):j1);

elseif ind(1)==-27 % Extract string with matching {} 

  CAM=lower(CAM);

end
