function [ col, row, a ] = r8ccs_dif2 ( m, n, nz_num )

%*****************************************************************************80
%
%% r8ccs_dif2() sets the second difference as a CCS matrix.
%
%  Discussion:
%
%    The CCS format is the double precision sparse compressed column
%    format.  Associated with this format, we have an M by N matrix
%    with NZ_NUM nonzero entries.  We construct the column pointer
%    vector COL of length N+1, such that entries of column J will be
%    stored in positions COL(J) through COL(J+1)-1.  This indexing
%    refers to both the ROW and A vectors, which store the row indices
%    and the values of the nonzero entries.  The entries of the
%    ROW vector corresponding to each column are assumed to be
%    ascending sorted.
%
%    The CCS format is equivalent to the MATLAB "sparse" format,
%    and the Harwell Boeing "real unsymmetric assembled" (RUA) format.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    01 October 2015
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer M, the number of rows of the matrix.
%
%    integer N, the number of columns of the matrix.
%
%    integer NZ_NUM, the number of nonzero entries.
%
%  Output:
%
%    integer COL(N+1), indicate where each column's data begins.
%
%    integer ROW(NZ_NUM), the row indices.
%
%    real A(NZ_NUM), the nonzero entries.
%

%
%  Column pointers
%
  col = zeros ( n + 1, 1 );
  col(1) = 1;
  col(2) = 3;
  for j = 3 : n
    col(j) = col(j-1) + 3;
  end
  col(n+1) = col(n) + 2;
%
%  Row indices
%
  row = zeros ( nz_num, 1 );
  k = 0;
  k = k + 1;
  row(k) = 1;
  k = k + 1;
  row(k) = 2;
  for j = 2 : n - 1
    for i = j - 1 : j + 1
      k = k + 1;
      row(k) = i;
    end
  end
  k = k + 1;
  row(k) = m - 1;
  k = k + 1;
  row(k) = m;
%
%  Values
%
  a = zeros ( nz_num, 1 );
  k = 0;
  j = 1;
  i = 1;
  k = k + 1;
  a(k) = 2.0;
  i = 2;
  k = k + 1;
  a(k) = -1.0;

  for j = 2 : n - 1
    i = j - 1;
    k = k + 1;
    a(k) = -1.0;
    i = j;
    k = k + 1;
    a(k) =  2.0;
    i = j + 1;
    k = k + 1;
    a(k) = -1.0;
  end

  j = n;
  i = m - 1;
  k = k + 1;
  a(k) = -1.0;
  i = m;
  k = k + 1;
  a(k) = 2.0;

  return
end
