function grid_write ( m, n, seed, center, r, file_out_name ) %% GRID_WRITE writes a grid dataset to a file. % % Discussion: % % The initial lines of the file are comments, which begin with a % '#' character. % % Thereafter, each line of the file contains the NDIM-dimensional % components of the next entry in the dataset. % % Modified: % % 04 May 2005 % % Author: % % John Burkardt % % Parameters: % % Input, integer M, the spatial dimension. % % Input, integer N, the number of points. % % Input, integer SEED, the seed for the random number generator. % % Input, integer CENTER, specifies the 1D grid centering: % 1: first point is 0.0, last point is 1.0; % 2: first point is 1/(N+1), last point is N/(N+1); % 3: first point is 0, last point is (N-1)/N; % 4: first point is 1/N, last point is 1; % 5: first point is 1/(2*N), last point is (2*N-1)/(2*N); % % Input, real R(M,N), the points. % % Input, string FILE_OUT_NAME, the name of the output file. % file_out_unit = fopen ( file_out_name, 'w' ); if ( file_out_unit < 0 ) fprintf ( 1, '\n' ); fprintf ( 1, 'GRID_WRITE - Fatal error!\n' ); fprintf ( 1, ' Could not open the output file:\n' ); fprintf ( 1, ' "%s".\n', file_out_name ); error ( 'GRID_WRITE - Fatal error!' ); end today = timestring; fprintf ( file_out_unit, '# %s\n', file_out_name ); fprintf ( file_out_unit, '# created by GRID_WRITE.M\n' ); fprintf ( file_out_unit, '#\n' ); fprintf ( file_out_unit, '# File generated on %s\n', timestring ); fprintf ( file_out_unit, '#\n' ); fprintf ( file_out_unit, '# M = %d\n', m ); fprintf ( file_out_unit, '# N = %d\n', n ); fprintf ( file_out_unit, '# EPSILON (unit roundoff ) = %e\n', ... r8_epsilon ( 'DUMMY' ) ); fprintf ( file_out_unit, '# Initial SEED = %d\n', seed ); fprintf ( file_out_unit, '# Grid centering = %d\n', center ); fprintf ( file_out_unit, '#\n' ); for j = 1 : n for i = 1 : m fprintf ( file_out_unit, ' %10f', r(i,j) ); end fprintf ( file_out_unit, '\n' ); end fclose ( file_out_unit );