function life_write ( output_filename, m, n, grid )

%*****************************************************************************80
%
%% life_write() writes a grid to a file.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 September 2013
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string OUTPUT_FILENAME, the output file name.
%
%    integer M, N, the number of rows and columns
%    of interior grid cells.
%
%    integer GRID(1+M+1,1+N+1), the data.
%

%
%  Open the file.
%
  output_unit = fopen ( output_filename, 'wt' );

  if ( output_unit < 0 ) 
    fprintf ( 1, '\n' );
    fprintf ( 1, 'LIFE_WRITE - Error!\n' );
    fprintf ( 1, '  Could not open the output file.\n' );
    error ( 'LIFE_WRITE - Error!' );
  end

  for j = 0 : n + 1
    fprintf ( output_unit, ' %d', grid(1:m+2,j+1) );
    fprintf ( output_unit, '\n' );
  end
%
%  Close the file.
%
  fclose ( output_unit );

  return
end
