function [ nst, ist, jst, Ast ] = crs_to_st (  m, n, nz, row, col, val )

%*****************************************************************************80
%
%% crs_to_st() converts sparse matrix information from CRS to ST format.
% 
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    24 March 2026
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer M, N: the order of the matrix.
%
%    integer NZ: the number of nonzero elements.
%
%    integer ROW(M+1): the nonzero offdiagonal 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.
%
%  Output:
%
%    integer NST, the number of ST elements.
%
%    integer IST(NST), JST(NST), the ST rows and columns.
%
%    real AST(NST), the ST values.
%
  nst = 0;
  ist = zeros ( nz );
  jst = zeros ( nz );
  Ast = zeros ( nz );

  if ( row(1) == 0 )
    for i = 1 : m
      for j = row(i) + 1 : row(i+1)
        nst = nst + 1;
        ist(nst) = i;
        jst(nst) = col(j) + 1;
        Ast(nst) = val(j);
      end
    end
  else
    for i = 1 : m
      for j = row(i) : row(i+1)-1
        nst = nst + 1;
        ist(nst) = i;
        jst(nst) = col(j);
        Ast(nst) = val(j);
      end
    end
  end

  return
end
