function fnorm = r8mat_is_sum_magic ( m, n, a )

%*****************************************************************************80
%
%% r8mat_is_sum_magic(): is an R8MAT magic.
%
%  Discussion:
%
%    An R8MAT is a matrix of real values.
%
%    A matrix is magic if the rows and columns and main diagonals all 
%    sum to the same value.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    16 April 2017
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer M, N, the row and column dimensions of 
%    the matrix.  M and N must be positive.
%
%    real A(M,N), the matrix.
%
%  Output:
%
%    real FNORM, is 0.0 if the matrix is exactly 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
%
%  The matrix might not be square.
%  Assume the diagonals start at A(1,1) and A(1,N) and work from there.
%
  s = 0.0;
  for k = 1 : min ( m, n )
    s = s + a(k,k);
  end
  fnorm = fnorm + ( s - t ) ^ 2;

  s = 0.0;
  for k = 1 : min ( m, n )
    s = s + a(k,n+1-k);
  end
  fnorm = fnorm + ( s - t ) ^ 2;

  fnorm = sqrt ( fnorm );

  return
end
