function [ i, j ] = node_to_ij ( node, imax )

%*****************************************************************************80
%
%% node_to_ij returns the IJ coordinates of the nodes of a triangulation.
%
%  Discussion:
%
%    We assigned a unique scalar index P to a node indexed (I,J).  
%    Letting IMAX be the largest value of I that we have recorded, we set
%    P = I + 1 + ( IMAX + 1 ) * J, so node (0,0) -> 1, (1,0) -> 2, 
%    (IMAX,0) -> IMAX+1, (0,1) -> IMAX+2, ...
%
%    This function takes the value P and returns the coordinates (I,J).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    01 September 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer NODE(*), the node index.  May be scalar, vector, or array.
%
%    integer IMAX, the largest I coordinate in the original grid.
%
%  Output:
%
%    integer I(*), J(*), the (I,J) coordinates.
%
  i = zeros ( size ( node ) );
  j = zeros ( size ( node ) );

  node_num = length ( node );

  for k = 1 : node_num
    i(k) = mod ( node(k) - 1, imax + 1 );
    j(k) = floor ( node(k) / ( imax + 1 ) );
  end

  return
end

