function [ node_xy, element_node, element_neighbor ] = example4_q4_mesh ( ...
  node_num, element_num )

%*****************************************************************************80
%
%% example4_q4_mesh() sets up example #4 Q4 mesh.
%
%  Discussion:
%
%    The region is a rectangle.
%
%    The appropriate values of NODE_NUM and ELEMENT_NUM can be found by
%    calling EXAMPLE4_Q4_MESH_SIZE first.
%
%   37---38---39---40---41---42---43---44---45
%    | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
%   28---29---30---31---32---33---34---35---36
%    | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
%   19---20---21---22---23---24---25---26---27
%    |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
%   10---11---12---13---14---15---16---17---18
%    |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |
%    1----2----3----4----5----6----7----8----9
%
%    This example is the same as example #3, except that the mesh has been
%    adjusted so that row 2 (counting up) and column 6 are 1/3 the widths 
%    of the other rows and columns, resulting in element 14 being 1/9 the 
%    area of the standard elements.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    18 September 2016
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer NODE_NUM, the number of nodes.
%
%    integer ELEMENT_NUM, the number of elements.
%
%  Output:
%
%    real NODE_XY(2,NODE_NUM), the coordinates of the
%    nodes.
%
%    integer ELEMENT_NODE(4,ELEMENT_NUM), the nodes
%    that make up the elements.
%
%    integer ELEMENT_NEIGHBOR(4,ELEMENT_NUM), the
%    element neighbors on each side.  Negative values indicate edges that
%    lie on the exterior.
%
  element_row_num = 4;
  element_col_num = 8;

  node_row_num = element_row_num + 1;
  node_col_num = element_col_num + 1;

  k = 0;
  for row = 1 : node_row_num
    for col = 1 : node_col_num
      k = k + 1;
      x = col - 1;
      if ( 7 <= col )
        x = x - 0.66;
      end
      y = row - 1;
      if ( 3 <= row )
        y = y - 0.66;
      end 
      node_xy(1,k) = x;
      node_xy(2,k) = y;
    end
  end
  
  element = 0;
  for row = 1 : element_row_num 
    for col = 1 : element_col_num
      element = element + 1;
      if ( row == 1 )
        element_node(1,element) = col;
        element_node(2,element) = col + 1;
        element_node(3,element) = col + 1 + node_col_num;
        element_node(4,element) = col     + node_col_num;
      else
        element_node(1,element) = element_node(4,element-element_col_num);
        element_node(2,element) = element_node(3,element-element_col_num);
        element_node(3,element) = element_node(2,element) + node_col_num;
        element_node(4,element) = element_node(1,element) + node_col_num;
      end
    end
  end

  element = 0;
  for row = 1 : element_row_num
    for col = 1 : element_col_num
      element = element + 1;

      if ( row == 1 )
        element_neighbor(1,element) = -1;
      else
        element_neighbor(1,element) = element - element_col_num;
      end

      if ( col == element_col_num )
        element_neighbor(2,element) = -1;
      else
        element_neighbor(2,element) = element + 1;
      end

      if ( row == element_row_num )
        element_neighbor(3,element) = - 1;
      else
        element_neighbor(3,element) = element + element_col_num;
      end

      if ( col == 1 )
        element_neighbor(4,element) = - 1;
      else
        element_neighbor(4,element) = element - 1;
      end

    end
  end

  return
end
