function label=str_inp(def)

% function label=str_inp(def)
%
% This function is used in conjunction with FD3. It used to carry out the
% process of asking the user for a stream 'label'.  A stream label may only
% be a positive integer or a blank.  The default label placed in the input
% box will be 'def'.
%
% ACP

% Last update:  July 20, 1993
% Author:       Adrian C. Penisson

wflag=1;

while wflag

   % Querry user

   [label,flag]=di_inp_c('Enter the stream number.',def,1);

   if flag

      % If the user hits cancel, the label should be the default.  This
      % works for all cases in this program.

      label=def;

   end

   if strcmp(label,'')

      % If they enter blank, let it go as the label

      wflag=0;

   else

      % If this flag is set to 1, a warning will be displayed and the user
      % will have to try to enter a label again.  If flag stays 0, the label
      % label will be accepted.

      flag=0;

      % Find positions of legal delimeters.

      delimpos=find(label==',' | label==':');

      if any(delimpos==1) | any(delimpos==length(label)) | any(label=='.')

	 % A delimeter should not be the first or last character.
	 % Also, since streams are supposed to be integers, there should
	 % be no decimal.

	 flag=1;

      else

	 % There is two more delimeters, the "[" and the "]".  They can only
	 % appear on the end and if one appears, the other must appear.

	 lbracks=find(label=='[');
	 rbracks=find(label==']');

	 if all(lbracks==1) & all(rbracks==length(label)) & ...
	    length(delimpos)>0

	    % Make the left and right bracket delimeters since they are 
	    % properly placed.  Also, brackets should not be used if it is
	    % single streams number.

	    delimpos=[1 delimpos length(label)];

	 elseif length(lbracks)==0 & length(rbracks)==0

	    % Make the spot before the first character and the spot after the
	    % second character delimeters.

	    delimpos=[0 delimpos length(label)+1];
	 
	 else

	    % There are either mismatched brackets or internal brackets.
	    % Although internal brackets if properly matched are okay in
	    % matlab, they are not okay here.  Set delimpos to empty set
	    % so we don't have to waste time with for loop.

	    flag=1;
	    delimpos=[];

	 end


	 for i=1:(length(delimpos)-1)

	     % Extract whatever it is which lies between the two delimeters

	     num=str2num(label((delimpos(i)+1):(delimpos(i+1)-1)));

	     % Find out if it actually is (+) integer.  If it isn't, a warning
	     % will have to be issued.

	     flag=flag | any([(num<1) (num==[])]);

	 end

      end

      if flag

	 di_warn('WARNING!','Illegal Stream Label','CONTINUE')

      else

	 wflag=0;

      end

   end

end
