function fnorm = r8mat_is_sum_magic_weak ( m, n, a )

%*****************************************************************************80
%
%% R8MAT_IS_SUM_MAGIC_WEAK: is an R8MAT weakly magic.
%
%  Discussion:
%
%    An R8MAT is a matrix of real values.
%
%    A matrix is weakly magic if the rows and columns all sum to the same
%    value.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    15 April 2017
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer M, N, the row and column dimensions of 
%    the matrix.  M and N must be positive.
%
%    Input, real A(M,N), the matrix.
%
%    Output, real FNORM, is 0.0 if the matrix is exactly weakly magic.
%
  t = sqrt ( sum ( sum ( a(1:m,1:n) ) ) );

  fnorm = 0.0;

  for i = 1 : m
    s = sum ( a(i,1:n) );
    fnorm = fnorm + ( s - t ) ^ 2;
  end

  for j = 1 : n
    s = sum ( a(1:m,j) );
    fnorm = fnorm + ( s - t ) ^ 2;
  end

  fnorm = sqrt ( fnorm );

  return
end
