function nz_num = r8ncf_dif2_nz_num ( m, n )

%*****************************************************************************80
%
%% R8NCF_DIF2_NZ_NUM counts nonzeros in an R8NCF second difference matrix.
%
%  Discussion:
%
%    The R8NCF storage format stores NZ_NUM, the number of nonzeros, 
%    a real array containing the nonzero values, a 2 by NZ_NUM integer 
%    array storing the row and column of each nonzero entry.
%
%    The R8NCF format is used by NSPCG.  NSPCG requires that the information
%    for the diagonal entries of the matrix must come first.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    20 July 2016
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer M, N, the number of rows and columns in
%    the matrix.
%
%    Output, integer NZ_NUM, the number of nonzero entries.
%
  if ( m < n )
    nz_num = 3 * m - 1;
  elseif ( m == n )
    nz_num = 3 * n - 2;
  else
    nz_num = 3 * n - 1;
  end

  return
end

