Skip to content

foresight_smooth ​

foresight_smooth, gnuplot smooth filters of a data series.

The filters gnuplot computes from the data alone, without a fit: each run of placeable points (a block of the data file, broken by undefined points and by points not placeable on a log axis) is sorted by x, stably, and its points of equal x are merged into one:

  • unique: the mean of their y;
  • frequency: the sum of their y; fnormal divided by the sum of y over every run;
  • cumulative: the sum of y up to that x within the run; cnormal divided by the sum of y over every run.

Runs stay separate, joined by an undefined (NaN) point that breaks the line, as gnuplot draws them.

The curves (smooth_curve) are sampled at set samples points: the natural cubic spline (csplines), the smoothing spline of Reinsch (acsplines, weights from a third column), the Bezier curve of the points (bezier, in the file order; sbezier sorted and merged), the Gaussian kernel density estimate (kdensity) and the monotone cubic spline of Fritsch and Carlson (mcsplines, at the points and between them), as gnuplot 6.0.

The bins (bin_values, gnuplot's bins filter) are the sums, or the means, of y over equal-width intervals of x.

Source: src/lib/foresight_smooth.F90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
SMOOTH_MODEScharacter(len=*)parameterFilters of smooth.
CURVE_MODEScharacter(len=*)parameterFilters of smooth_curve.

Subroutines ​

bin_values ​

Bin the series (x, y) as gnuplot's bins filter: nbins bins of equal width over [lo, hi] (the data's x extremes if lo equals hi), lo and hi the centres of the first and last bins; with a width > 0 instead, the fewest bins of that width that span the range, centred on it. A point falls in bin floor(n (x - xmin) / (xmax - xmin)), xmin and xmax the outer edges: on a boundary, in the upper bin; beyond them, in none. Each bin is one point at its centre: the sum of its y (average: their mean, for two or more). Points not placeable (NaN, or not positive on a log axis) are skipped. edges are xmin and xmax, which the x autoscale includes; message is empty on success.

Attributes: pure

fortran
subroutine bin_values(x, y, nbins, lo, hi, width, average, xlog, ylog, xs, ys, edges, message)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inAbscissae.
yreal(kind=R8P)inOrdinates, the value each point adds to its bin.
nbinsinteger(kind=I4P)inNumber of bins, if width is not positive.
loreal(kind=R8P)inCentre of the first bin (equal to hi: from the data).
hireal(kind=R8P)inCentre of the last bin.
widthreal(kind=R8P)inBin width, if positive.
averagelogicalinThe mean of y per bin, not the sum.
xloglogicalinLog x axis.
yloglogicalinLog y axis.
xsreal(kind=R8P)outallocatableBin centres.
ysreal(kind=R8P)outallocatableBin values.
edgesreal(kind=R8P)outOuter edges of the bins.
messagecharacter(len=:)outallocatableProblem, empty if none.

Call graph

smooth ​

Filter the series (x, y) with the smooth mode (one of SMOOTH_MODES) into (xs, ys); xlog, ylog tell the log axes, on which non-positive values are not placeable.

fortran
subroutine smooth(mode, x, y, xlog, ylog, xs, ys)

Arguments

NameTypeIntentAttributesDescription
modecharacter(len=*)inFilter.
xreal(kind=R8P)inAbscissae.
yreal(kind=R8P)inOrdinates.
xloglogicalinLog x axis.
yloglogicalinLog y axis.
xsreal(kind=R8P)outallocatableFiltered abscissae.
ysreal(kind=R8P)outallocatableFiltered ordinates.

Call graph

smooth_curve ​

Smooth the series (x, y) with the mode of CURVE_MODES, samples points per run, as gnuplot:

  • csplines: the natural cubic spline through the points sorted by x, those of equal x merged into their mean;
  • acsplines: the smoothing (approximation) spline of Reinsch, the weights w (larger: closer to the points);
  • bezier: the Bezier curve with the points as control points, in the file order; sbezier after sorting and merging them;
  • kdensity: the Gaussian kernel density estimate of the x values weighted by y, over [lo, hi], of bandwidth (gnuplot's default, (4/3n)^(1/5) times the standard deviation of x, if not positive);
  • mcsplines: the monotone cubic spline of Fritsch and Carlson through the points sorted and merged, of the first run only (gnuplot 6.0 drops the others), sampled at the points and at max(samples, 2 n) points within [lo, hi] (see mcs_samples).

The splines are sampled over the run, within [lo, hi]; runs are joined by an undefined point. message is empty on success.

fortran
subroutine smooth_curve(mode, x, y, w, samples, lo, hi, bandwidth, xlog, ylog, xs, ys, message)

Arguments

NameTypeIntentAttributesDescription
modecharacter(len=*)inFilter.
xreal(kind=R8P)inAbscissae.
yreal(kind=R8P)inOrdinates.
wreal(kind=R8P)inWeights (acsplines).
samplesinteger(kind=I4P)inPoints per run.
loreal(kind=R8P)inSmallest abscissa sampled.
hireal(kind=R8P)inLargest abscissa sampled.
bandwidthreal(kind=R8P)inkdensity bandwidth, default if not positive.
xloglogicalinLog x axis.
yloglogicalinLog y axis.
xsreal(kind=R8P)outallocatableSmoothed abscissae.
ysreal(kind=R8P)outallocatableSmoothed ordinates.
messagecharacter(len=:)outallocatableProblem, empty if none.

Call graph

merge_equal ​

Sort the points by x, stably, and merge those of equal x into one, the mean of their y and weights (gnuplot's preparation of the splines and of sbezier).

Attributes: pure

fortran
subroutine merge_equal(x, y, w)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inoutallocatableAbscissae.
yreal(kind=R8P)inoutallocatableOrdinates.
wreal(kind=R8P)inoutallocatableWeights.

Call graph

path_spline ​

gnuplot 6.0's smooth path (filters.c gen_2d_path_splines): each set of points (apart at undefined ones) a natural cubic spline of x and of y against the path length (scaled by xrange, yrange, normalized to 0..1), sampled samples times over the whole path and kept along the points, in their order; a set whose ends meet is closed (the spline wraps around), and closed (filledcurves closed) closes every set. Undefined points and repeated ones are dropped, a set of fewer than 3 points too; the sets apart at undefined points in xs, ys.

Attributes: pure

fortran
subroutine path_spline(x, y, samples, xrange, yrange, closed, xs, ys)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inAbscissae.
yreal(kind=R8P)inOrdinates.
samplesinteger(kind=I4P)inSamples of a whole path.
xrangereal(kind=R8P)inx scale of the path length.
yrangereal(kind=R8P)iny scale of the path length.
closedlogicalinClose every set.
xsreal(kind=R8P)outallocatableCurve abscissae.
ysreal(kind=R8P)outallocatableCurve ordinates.

Call graph

spline_curve3d ​

A 3D curve smoothed as gnuplot 6.0's do_3d_cubic (smooth csplines|acsplines of splot): its unusable points (NaN) and repeated ones dropped; with more than 3 left, a curve in a plane of constant x is z of y (samples points from its first y to its last), of constant y z of x, of constant z y of x; else x, y and z each a spline of the path length (the steps over the axis ranges, normalized to 1). csplines natural cubic splines, acsplines the smoothing splines weighted by w. With 3 points or fewer the curve is kept as it is.

Attributes: pure

fortran
subroutine spline_curve3d(mode, x, y, z, w, samples, ranges, xs, ys, zs)

Arguments

NameTypeIntentAttributesDescription
modecharacter(len=*)incsplines or acsplines.
xreal(kind=R8P)inAbscissae.
yreal(kind=R8P)inOrdinates.
zreal(kind=R8P)inHeights.
wreal(kind=R8P)inWeights (acsplines).
samplesinteger(kind=I4P)inPoints of the smoothed curve.
rangesreal(kind=R8P)inx, y and z axis lengths (the path's scale).
xsreal(kind=R8P)outallocatableSmoothed abscissae.
ysreal(kind=R8P)outallocatableSmoothed ordinates.
zsreal(kind=R8P)outallocatableSmoothed heights.

Call graph

fill_coefficients ​

The first and third order coefficients of a cubic spline from its knot values v and half second derivatives c(2, 😃: c(1, i) the slope, c(3, i) a third of the change of c(2, 😃 per unit, on each interval.

Attributes: pure

fortran
subroutine fill_coefficients(x, v, c)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inKnots.
vreal(kind=R8P)inKnot values.
creal(kind=R8P)inoutCoefficients.

Call graph

Functions ​

natural_spline ​

Coefficients c(0:3, i) of the natural cubic spline through (x, y) (x increasing, at least 3 points) on each interval i, in powers of x - x(i): second derivative zero at both ends.

Attributes: pure

Returns: real(kind=R8P)

fortran
function natural_spline(x, y) result(c)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inKnots.
yreal(kind=R8P)inValues.

Call graph

approximation_spline ​

Coefficients c(0:3, i) of the smoothing spline of Reinsch through (x, y) with weights w (x increasing, at least 4 points), as gnuplot's acsplines: natural, its values at the knots c(0, i) drawn towards y(i) by w(i).

Attributes: pure

Returns: real(kind=R8P)

fortran
function approximation_spline(x, y, w) result(c)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inKnots.
yreal(kind=R8P)inValues.
wreal(kind=R8P)inWeights, positive.

Call graph

placeable ​

Whether v is placeable on an axis: finite, and positive on a log axis (as foresight_axis%accepts).

Attributes: elemental

Returns: logical

fortran
function placeable(v, log) result(ok)

Arguments

NameTypeIntentAttributesDescription
vreal(kind=R8P)inValue.
loglogicalinLog axis.

Call graph

sorted ​

Permutation sorting keys ascending, stable (equal keys keep their order): bottom-up merge sort.

Attributes: pure

Returns: integer(kind=I4P)

fortran
function sorted(keys) result(order)

Arguments

NameTypeIntentAttributesDescription
keysreal(kind=R8P)inKeys, no NaN.

Call graph

Released under the GPL v3, BSD 2-Clause, BSD 3-Clause or MIT License.