function M = magic_even_doubly ( n )

%*****************************************************************************80
%
%% magic_even_doubly returns a MAGIC matrix of order divisible by 4.
%
%  Modified:
%
%    16 December 2019
%
%  Author:
%
%    The Mathworks, Inc.
%
%  Input:
%
%    integer N, the order of A.
%    N must be divisible by 4.
%
%  Output:
%
%    real A(N,N), the matrix.
%
  M = reshape(1:n^2,n,n)';
  [I,J] = ndgrid(1:n);
  K = fix(mod(I,4)/2) == fix(mod(J,4)/2);
  M(K) = n^2+1 - M(K);

  return
end

