function [ icc, ccc ] = st_to_ccs_index ( nst, ist, jst, ncc, n )

%*****************************************************************************80
%
%% st_to_ccs_index() creates CCS indices from ST data.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    14 July 2014
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer NST, the number of ST elements.
%
%    integer IST(NST), JST(NST), the ST rows and columns.
%
%    integer NCC, the number of CCS elements.
%
%    integer N, the number of columns.
%
%  Output:
%
%    integer ICC(NCC), the CCS rows.
%
%    integer CCC(N+1), the compressed CCS columns.
%

%
%  Sort the elements.
%
  [ jst2, ist2 ] = i4vec2_sort_a ( nst, jst, ist );
%
%  Get the unique elements.
%
  [ jcc, icc ] = i4vec2_sorted_uniquely ( nst, jst2, ist2, ncc );
%
%  Compress the column index.
%
  ccc = zeros(n+1,1);

  ccc(1) = 1;
  jlo = 1;
  for i = 1 : ncc
    jhi = jcc(i);
    if ( jhi ~= jlo )
      ccc(jlo+1:jhi) = i;
      jlo = jhi;
    end
  end
  jhi = n + 1;
  ccc(jlo+1:jhi) = ncc + 1;

  return
end
