function [ m, n, nz, row, col, val ] = ccs_to_crs ( m, n, ncc, icc, ccc, acc )

%*****************************************************************************80
%
%% ccs_to_crs() converts a CCS matrix to CRS format.
%
%  Discussion:
%
%    A sparse mxn matrix with ncc nonzeros can be set in compressed 
%    column storage (CCS) format.
%
%    A sparse mxn matrix with nz nonzeros can be set in compressed 
%    row storage (CRS) format.
%
%    This function converts from CCS to CRS format.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 June 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer M, the number of rows.
%
%    integer N, the number of columns.
%
%    integer NCC, the number of values.
%
%    integer ICC(NCC), the rows.
%
%    integer CCC(N+1), the compressed columns
%
%    real ACC(NCC), the values.
%
%  Output:
%
%    integer M, N: the number of rows and columns.
%
%    integer NZ: the number of nonzero elements.
%
%    integer ROW(M+1): the nonzero elements 
%    of row I of A are contained in A(ROW(I)) through A(ROW(I+1)-1).
%
%    integer COL(NZ): the column indices of the nonzero elements of A.
%
%    real VAL(NZ): the nonzero elements of A.
%

%
%  Allocate space.
%
  row_length = zeros ( m, 1 );

  nz = ncc;
  row = zeros ( m + 1, 1 );
  col = zeros ( nz, 1 );
  val = zeros ( nz, 1 );
%
%  Compute the number of nonzeros in each row.
%
  for k = 1 : nz
    i = icc(k);
    row_length(i) = row_length(i) + 1;
  end
%
%  Construct the row pointer array.
%
  row(1) = 1;
  for i = 1 : m
    row(i+1) = row(i) + row_length(i);
  end
%
%  Record the first open position in each row.
%
  row_free = zeros ( m, 1 );
%
%  For each matrix entry, determine its row i, and place
%  the column j and value v in the next free spot for that row.
%
  for j = 1 : n
    for r = ccc(j) : ccc(j+1) - 1
      v = acc(r);
      i = icc(r);
      k = row(i) + row_free(i);
      val(k) = v;
      col(k) = j;
      row_free(i) = row_free(i) + 1;
    end
  end

  return
end

