function value = s_s_subanagram_sorted ( s1, s2 )

%*****************************************************************************80
%
%% s_s_subanagram_sorted determines if S2 is a "subanagram" of S1.
%
%  Discussion:
%
%    This routine assumes that S1 and S2 have already been sorted.
%
%    S2 is an anagram of S1 if S2 can be formed by permuting the letters
%    of S1
%
%    S2 is an subanagram of S1 if S2 can be formed by selecting SOME of
%    the letters of S1 and permuting them.
%
%    Blanks (trailing or otherwise), punctuation, and capitalization
%    are all significant, so be sure to input exactly the information
%    you want to check.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 August 2009
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string S1, the master sorted string.
%
%    string S2, the second sorted string.
%
%  Output:
%
%    logical VALUE is TRUE if S2 is a subanagram of S1.
%
  value = false;

  s1_length = length ( s1 );
  s2_length = length ( s2 );

  i1 = 0;

  for i2 = 1 : s2_length

    while ( true )

      i1 = i1 + 1;
%
%  Ran out of S1 before finishing.  No match is possible.
%
      if ( s1_length < i1 )
        return;
      end
%
%  The current character in S1 is already greater than the character in S2.
%  No match is possible.
%
      if ( s2(i2) < s1(i1) )
        return
      end
%
%  Found an exact match for current character.  Keep going.
%
      if ( s1(i1) == s2(i2) )
        break
      end
%
%  Didn't find a match, but one might be possible if we increase I1.
%
    end

  end
%
%  We matched every character of S2 with something in S1.
%
  value = true;

  return
end
