function filename = filename_inc_nowrap ( filename )

%*****************************************************************************80
%
%% filename_inc_nowrap() increments a partially numeric filename.
%
%  Discussion:
%
%    It is assumed that the digits in the name, whether scattered or
%    connected, represent a number that is to be increased by 1 on
%    each call.  Non-numeric letters of the name are unaffected..
%
%    If the (nonempty) name contains no digits, or all the digits are
%    9, then the empty string is returned.
%
%    If the empty string is input, the routine stops.
%
%  Example:
%
%      Input            Output
%      -----            ------
%      'a7to11.txt'     'a7to12.txt'  (typical case.  Last digit incremented)
%      'a7to99.txt'     'a8to00.txt'  (last digit incremented, with carry.)
%      'a8to99.txt'     'a9to00.txt'
%      'a9to99.txt'     ' '
%      'cat.txt'        ' '
%      ' '              STOP!
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 November 2011
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string FILENAME, the string to be incremented.
%
%  Output:
%
%    string FILENAME, the incremented string.
%
  lens = s_len_trim ( filename );

  if ( lens <= 0 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'filename_inc_nowrap(): Fatal error!\n' );
    fprintf ( 1, '  The input filename is empty.\n' );
    error ( 'filename_inc_nowrap(): Fatal error!' );
  end

  change = 0;
  carry = 0;

  for i = lens : -1 : 1

    c = filename(i);

    if ( '0' <= c && c <= '9' )

      change = change + 1;

      if ( c == '9' )
        c = '0';
        carry = 1;
      else
        c = c + 1;
        carry = 0;
      end
    
      filename(i) = c;

      if ( c ~= '0' )
        return
      end

    end

  end
%
%  Unsatisfied carry.  The input digits were all 9.  Return blank.
%
  if ( carry == 1 )
    filename = ' ';
  end
%
%  No digits were found.  Return blank.
%
  if ( change == 0 )
    filename = ' ';
  end

  return
end
