function yval = spline_constant_val ( ndata, tdata, ydata, tval )

%*****************************************************************************80
%
%% spline_constant_val() evaluates a piecewise constant spline at a point.
%
%  Discussion:
%
%    NDATA-1 points TDATA define NDATA intervals, with the first
%    and last being semi-infinite.
%
%    The value of the spline anywhere in interval I is YDATA(I).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    10 February 2004
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer NDATA, the number of data points defining the spline.
%
%    real TDATA(NDATA-1), the breakpoints.  The values of TDATA should
%    be distinct and increasing.
%
%    real YDATA(NDATA), the values of the spline in the intervals
%    defined by the breakpoints.
%
%    real TVAL, the point at which the spline is to be evaluated.
%
%  Output:
%
%    real YVAL, the value of the spline at TVAL.
%
  for i = 1 : ndata-1
    if ( tval <= tdata(i) )
      yval = ydata(i);
      return
    end 
  end

  yval = ydata(ndata);

  return
end
