function grid = new_grid(xmin, xmax, n)
%  1.  NAME
%
%  new_grid - Build a regular grid
%
%  2.  SYNOPSIS
%
%  grid = new_grid(xmin, xmax, n )
%
%  3.  DESCRIPTION
%
%  This Matlab function will create a regular grid. Extreme grid values
%  are included in the number of grid points. Hence, n must be at least
%  2.
%
%  4.  PARAMETERS
%
%     xmin
%        Minimum value for grid.
%
%     xmax
%        Maximum value for grid.
%
%     n  Number of points (including xmin and xmax).
%
%  5.  RETURNS
%
%     grid
%        Vector with the new grid points.
%
%  6.  AUTHORS
%
%  Pierre Jaccard, Geophysical Institute, University of Bergen, 1999
%

%--- Control the value of n:
if n < 2,
	error([ 'Too few data for new grid: n=' int2str(n) ]);
end

%--- Calculate the step:
step = (xmax - xmin)/(n-1);

%--- Build the new grid:
grid = xmin;
for n=1:(n-1),
  grid = [ grid, grid(n) + step ];
end

return;

