function A = haar_step_2d_inverse ( A )

%*****************************************************************************80
%
%% haar_step_2d_inverse() inverts one step of the Haar transform on a 2D array.
%
%  Discussion:
%
%    Given an M by N array to which one or more steps of the Haar transform
%    has been applied, this function inverts one step of the Haar
%    transform.
%
%    It is necessary that the number of rows and columns of the matrix be
%    even in order for this operation to work correctly.  
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    15 March 2011
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real A(M,N), the array to be processed.
%
%  Output:
%
%    real A(M,N), the processed array.
%
  [ m, n ] = size ( A );
%
%  Recover rows.
%
  B(:,1:2:n) = ( A(:,1:n/2) + A(:,n/2+1:n) ) / sqrt ( 2.0 );
  B(:,2:2:n) = ( A(:,1:n/2) - A(:,n/2+1:n) ) / sqrt ( 2.0 );
%
%  Recover columns.
% 
  A(1:2:m,:) = ( B(1:m/2,:) + B(m/2+1:m,:) ) / sqrt ( 2.0 );
  A(2:2:m,:) = ( B(1:m/2,:) - B(m/2+1:m,:) ) / sqrt ( 2.0 );

  return
end
