function area = boundary_word_area ( s )

%*****************************************************************************80
%
%% boundary_word_area() returns the area of a polyomino defined by a boundary word.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    05 May 2020
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Srecko Briek, Gilbert Labelle, Ariane Lacasse,
%    Algorithms for polyominoes based on the discrete Green theorem,
%    Discrete Applied Mathematics,
%    Volume 147, pages 187-205, 2005.
%
%  Input:
%
%    char s(*): a string of the characters 'u', 'd', 'l' and 'r' that should
%    represent a path around the boundary of a polyomino.
%
%  Output:
%
%    integer area: the area of the polyomino.
%
  check = boundary_word_check ( s );

  if ( ~ check )
    area = -1;
    return
  end

  s_len = length ( s );
  s = lower ( s );

  x = 0;
  y = 0;
  area = 0;
  for i = 1 : s_len

    if ( s(i) == 'u' )
      y = y + 1;
      area = area + x;
    elseif ( s(i) == 'd' )
      y = y - 1;
      area = area - x;
    elseif ( s(i) == 'l' )
      x = x - 1;
    elseif ( s(i) == 'r' )
      x = x + 1;
    end

  end

  return
end
