fitpack
Modern Fortran library for curve and surface fitting with splines
Loading...
Searching...
No Matches
fitpack_gridded_splines Module Reference

Generic N-dimensional gridded smoothing-spline fitter. More...

Data Types

type  fitpack_gridded_spline
 Tensor-product gridded smoothing-spline fitter for any domain dimension. More...
 

Functions/Subroutines

elemental subroutine grid_destroy (this)
 Release all allocated storage and reset the fit state.
 
subroutine grid_new_points (this, xg, z, m, row_major, order)
 Load new gridded data. z is assumed-rank: a rank-d array (2 <= d <= MAX_IDIM) whose shape gives the per-axis point counts, or a flat rank-1 array with explicit m.
 
integer(fp_flag) function grid_new_fit (this, xg, z, m, row_major, order, smoothing)
 Load new gridded data and perform a fit in one call.
 
integer(fp_flag) function grid_fit_automatic_knots (this, smoothing, order)
 Fit a smoothing spline with automatic knot placement (delegates to regrid).
 
integer(fp_flag) function grid_fit_least_squares (this, smoothing, reset_knots)
 Least-squares fit on the current knots (optionally recomputing them first).
 
integer(fp_flag) function grid_fit_interpolating (this)
 Interpolating fit (s = 0).
 
real(fp_real) function, dimension(product(m)) grid_eval_ongrid (this, xg, m, ierr)
 Evaluate the fitted spline on a rectangular grid (delegates to ndspev).
 
real(fp_real) function, dimension(size(xp, 2)) grid_eval_many (this, xp, ierr)
 Evaluate the fitted spline at scattered points (delegates to ndspeu).
 
real(fp_real) function grid_eval_one (this, x, ierr)
 Evaluate the fitted spline at a single point x(1:dims).
 
real(fp_real) function, dimension(product(m)) grid_derivatives_gridded (this, xg, m, nu, ierr)
 Evaluate partial derivatives of order nu(:) on a rectangular grid (delegates to parder).
 
real(fp_real) function, dimension(size(xp, 2)) grid_derivatives_many (this, xp, nu, ierr)
 Evaluate partial derivatives of order nu(:) at scattered points (delegates to pardeu).
 
real(fp_real) function grid_derivatives_one (this, x, nu, ierr)
 Evaluate a partial derivative of order nu(:) at a single point x(1:dims).
 
real(fp_real) function grid_integral (this, lower, upper)
 Integral of the fitted spline over the box [lower(d),upper(d)] (delegates to dblint).
 
type(fitpack_gridded_spline) function grid_cross_section (this, ax, u, ierr)
 Cross-section: fix axis ax at value u, returning the (dims-1)-D spline \( s|_{x_{ax}=u} \).
 
type(fitpack_gridded_spline) function grid_derivative_spline (this, nu, ierr)
 Partial-derivative spline of order nu(:): a new gridded spline of per-axis degrees order-nu on trimmed knots (delegates to pardtc). Eval-only, like cross_section.
 
subroutine grid_prepare_workspace (this)
 (Re)size the persistent workspace, maximally, so it is allocated only once, at spline construction. Covers both regrid's fit requirement (mirroring its internal lwest/kwest) and the peripheral evaluations (ndspev/parder/pardeu on grids up to the data-grid size), which carve their scratch past regrid's persistent iopt=1 state in wrk(1:2+dims)/ iwrk(1:1+dims). Grows the arrays only when needed so a continuation keeps that state.
 
subroutine grid_ensure_eval_workspace (this, maxm)
 Ensure the persistent workspace covers a peripheral evaluation with per-axis grids of up to maxm points. grid_prepare_workspace already sized it for grids up to the data grid, so this only grows the arrays for finer evaluation grids; contents are preserved so regrid's iopt=1 state in wrk(1:2+dims)/iwrk(1:1+dims) survives the growth.
 
pure subroutine ranked_sizes (shp, row_major, dims, m)
 Map a rank-d array shape to per-axis domain sizes, honouring the row_major flag. row_major=.true.: axes are reversed (z(m_d,...,m_1)); .false.: natural (z(m_1,...,m_d)).
 
pure real(fp_real) function, dimension(size(zc)) flat_row_major (zc, shp, row_major)
 Return the flat row-major (axis-1-slowest) value buffer from a column-major flatten. row_major=.true.: the input already IS row-major, copy as-is. row_major=.false.: the input is a natural Fortran grid z(m_1,...,m_d); permute (reverse axes) into row-major.
 
elemental integer(fp_size) function grid_comm_size (this)
 Communication buffer size: base fields + fixed metadata (1 + 6*MAX_IDIM) + bulk arrays.
 
pure subroutine grid_comm_pack (this, buffer)
 Pack the fitter into a communication buffer.
 
pure subroutine grid_comm_expand (this, buffer)
 Expand the fitter from a communication buffer.
 

Detailed Description

Generic N-dimensional gridded smoothing-spline fitter.

fitpack_gridded_spline fits a tensor-product B-spline \( s(x_1,\ldots,x_d) \) to data on a rectangular grid of arbitrary domain dimension dims (the 3D+ analogue of the concrete 2-D fitpack_grid_surface). One runtime-dims type holds a fit of any dimensionality up to MAX_IDIM; the guts marshal onto the dimension-generic core routines regrid (fit) and ndspev (grid evaluation).

CANONICAL DATA LAYOUT. Internally the function values live in a flat, row-major buffer with domain axis 1 the slowest-varying and axis dims the fastest — exactly the contract of regrid. The rank-natural entry points accept an assumed-rank array and an optional row_major flag:

  • row_major = .true. (default): the array's Fortran (column-major) storage already equals the internal buffer, so it is copied as-is. For a rank-d array that means passing the axes in reverse, z(m_d, ..., m_1) — the direct generalization of the 2-D z(iy,ix) convention.
  • row_major = .false.: the array is a natural Fortran grid z(m_1, ..., m_d) (dimension k is domain axis k); it is permuted into the row-major buffer on ingest (a one-time copy). A flat rank-1 z(:) plus explicit m(:) is always accepted (row-major, unambiguous).
See also
fitpack_grid_surface — concrete 2-D face; regrid, ndspev — N-D core routines

Function/Subroutine Documentation

◆ flat_row_major()

pure real(fp_real) function, dimension(size(zc)) fitpack_gridded_splines::flat_row_major ( real(fp_real), dimension(:), intent(in) zc,
integer(fp_size), dimension(:), intent(in) shp,
logical(fp_bool), intent(in) row_major )
private

Return the flat row-major (axis-1-slowest) value buffer from a column-major flatten. row_major=.true.: the input already IS row-major, copy as-is. row_major=.false.: the input is a natural Fortran grid z(m_1,...,m_d); permute (reverse axes) into row-major.

◆ grid_comm_expand()

pure subroutine fitpack_gridded_splines::grid_comm_expand ( class(fitpack_gridded_spline), intent(inout) this,
real(fp_comm), dimension(:), intent(in) buffer )
private

Expand the fitter from a communication buffer.

◆ grid_comm_pack()

pure subroutine fitpack_gridded_splines::grid_comm_pack ( class(fitpack_gridded_spline), intent(in) this,
real(fp_comm), dimension(:), intent(out) buffer )
private

Pack the fitter into a communication buffer.

◆ grid_comm_size()

elemental integer(fp_size) function fitpack_gridded_splines::grid_comm_size ( class(fitpack_gridded_spline), intent(in) this)
private

Communication buffer size: base fields + fixed metadata (1 + 6*MAX_IDIM) + bulk arrays.

Here is the call graph for this function:

◆ grid_cross_section()

type(fitpack_gridded_spline) function fitpack_gridded_splines::grid_cross_section ( class(fitpack_gridded_spline), intent(in) this,
integer(fp_dim), intent(in) ax,
real(fp_real), intent(in) u,
integer(fp_flag), intent(out), optional ierr )
private

Cross-section: fix axis ax at value u, returning the (dims-1)-D spline \( s|_{x_{ax}=u} \).

The result is a fully-formed, evaluable fitpack_gridded_spline over the surviving axes (in their original relative order). Like the 2-D cross_section it carries only the spline (knots/degrees/ coefficients/bounds), not a data grid, so it is eval-only.

Parameters
[in]axAxis to fix, 1 <= ax <= dims (requires dims >= 2).
[in]uValue at which axis ax is fixed.
[out]ierrOptional error flag.
Here is the call graph for this function:

◆ grid_derivative_spline()

type(fitpack_gridded_spline) function fitpack_gridded_splines::grid_derivative_spline ( class(fitpack_gridded_spline), intent(in) this,
integer(fp_size), dimension(:), intent(in) nu,
integer(fp_flag), intent(out), optional ierr )
private

Partial-derivative spline of order nu(:): a new gridded spline of per-axis degrees order-nu on trimmed knots (delegates to pardtc). Eval-only, like cross_section.

Here is the call graph for this function:

◆ grid_derivatives_gridded()

real(fp_real) function, dimension(product(m)) fitpack_gridded_splines::grid_derivatives_gridded ( class(fitpack_gridded_spline), intent(inout) this,
real(fp_real), dimension(:,:), intent(in) xg,
integer(fp_size), dimension(:), intent(in) m,
integer(fp_size), dimension(:), intent(in) nu,
integer(fp_flag), intent(out), optional ierr )
private

Evaluate partial derivatives of order nu(:) on a rectangular grid (delegates to parder).

Parameters
[in]xgPer-axis evaluation grids, xg(1:m(d),d) strictly increasing.
[in]mPer-axis grid sizes.
[in]nuPer-axis derivative orders, 0 <= nu(d) < order(d).
[out]ierrOptional error flag.
Returns
f Flat row-major derivative values, length product(m).
Here is the call graph for this function:

◆ grid_derivatives_many()

real(fp_real) function, dimension(size(xp,2)) fitpack_gridded_splines::grid_derivatives_many ( class(fitpack_gridded_spline), intent(inout) this,
real(fp_real), dimension(:,:), intent(in), contiguous xp,
integer(fp_size), dimension(:), intent(in) nu,
integer(fp_flag), intent(out), optional ierr )
private

Evaluate partial derivatives of order nu(:) at scattered points (delegates to pardeu).

Parameters
[in]xpPoint coordinates, xp(d,i) = axis-d coordinate of point i (shape (dims,m), point i = contiguous column xp(:,i)).
Here is the call graph for this function:

◆ grid_derivatives_one()

real(fp_real) function fitpack_gridded_splines::grid_derivatives_one ( class(fitpack_gridded_spline), intent(inout) this,
real(fp_real), dimension(:), intent(in) x,
integer(fp_size), dimension(:), intent(in) nu,
integer(fp_flag), intent(out), optional ierr )
private

Evaluate a partial derivative of order nu(:) at a single point x(1:dims).

Here is the call graph for this function:

◆ grid_destroy()

elemental subroutine fitpack_gridded_splines::grid_destroy ( class(fitpack_gridded_spline), intent(inout) this)

Release all allocated storage and reset the fit state.

◆ grid_ensure_eval_workspace()

subroutine fitpack_gridded_splines::grid_ensure_eval_workspace ( class(fitpack_gridded_spline), intent(inout) this,
integer(fp_size), intent(in) maxm )
private

Ensure the persistent workspace covers a peripheral evaluation with per-axis grids of up to maxm points. grid_prepare_workspace already sized it for grids up to the data grid, so this only grows the arrays for finer evaluation grids; contents are preserved so regrid's iopt=1 state in wrk(1:2+dims)/iwrk(1:1+dims) survives the growth.

◆ grid_eval_many()

real(fp_real) function, dimension(size(xp,2)) fitpack_gridded_splines::grid_eval_many ( class(fitpack_gridded_spline), intent(in) this,
real(fp_real), dimension(:,:), intent(in), contiguous xp,
integer(fp_flag), intent(out), optional ierr )
private

Evaluate the fitted spline at scattered points (delegates to ndspeu).

Parameters
[in]xpPoint coordinates, xp(d,i) = axis-d coordinate of point i (shape (dims,m), point i = contiguous column xp(:,i); matches curev/parcur layout).
[out]ierrOptional error flag.
Returns
f Spline values at the m points.
Here is the call graph for this function:

◆ grid_eval_one()

real(fp_real) function fitpack_gridded_splines::grid_eval_one ( class(fitpack_gridded_spline), intent(in) this,
real(fp_real), dimension(:), intent(in) x,
integer(fp_flag), intent(out), optional ierr )
private

Evaluate the fitted spline at a single point x(1:dims).

Here is the call graph for this function:

◆ grid_eval_ongrid()

real(fp_real) function, dimension(product(m)) fitpack_gridded_splines::grid_eval_ongrid ( class(fitpack_gridded_spline), intent(inout) this,
real(fp_real), dimension(:,:), intent(in) xg,
integer(fp_size), dimension(:), intent(in) m,
integer(fp_flag), intent(out), optional ierr )
private

Evaluate the fitted spline on a rectangular grid (delegates to ndspev).

Parameters
[in]xgEvaluation coordinates, xg(1:m(d),d) strictly increasing on axis d.
[in]mPer-axis evaluation-grid sizes.
[out]ierrOptional error flag.
Returns
zeval Flat, row-major (axis 1 slowest) evaluated values, length product(m).
Here is the call graph for this function:

◆ grid_fit_automatic_knots()

integer(fp_flag) function fitpack_gridded_splines::grid_fit_automatic_knots ( class(fitpack_gridded_spline), intent(inout) this,
real(fp_real), intent(in), optional smoothing,
integer(fp_size), intent(in), optional order )
private

Fit a smoothing spline with automatic knot placement (delegates to regrid).

Here is the call graph for this function:

◆ grid_fit_interpolating()

integer(fp_flag) function fitpack_gridded_splines::grid_fit_interpolating ( class(fitpack_gridded_spline), intent(inout) this)
private

Interpolating fit (s = 0).

◆ grid_fit_least_squares()

integer(fp_flag) function fitpack_gridded_splines::grid_fit_least_squares ( class(fitpack_gridded_spline), intent(inout) this,
real(fp_real), intent(in), optional smoothing,
logical, intent(in), optional reset_knots )
private

Least-squares fit on the current knots (optionally recomputing them first).

Here is the call graph for this function:

◆ grid_integral()

real(fp_real) function fitpack_gridded_splines::grid_integral ( class(fitpack_gridded_spline), intent(in) this,
real(fp_real), dimension(:), intent(in) lower,
real(fp_real), dimension(:), intent(in) upper )
private

Integral of the fitted spline over the box [lower(d),upper(d)] (delegates to dblint).

◆ grid_new_fit()

integer(fp_flag) function fitpack_gridded_splines::grid_new_fit ( class(fitpack_gridded_spline), intent(inout) this,
real(fp_real), dimension(:,:), intent(in) xg,
real(fp_real), dimension(..), intent(in) z,
integer(fp_size), dimension(:), intent(in), optional m,
logical(fp_bool), intent(in), optional row_major,
integer(fp_size), intent(in), optional order,
real(fp_real), intent(in), optional smoothing )
private

Load new gridded data and perform a fit in one call.

◆ grid_new_points()

subroutine fitpack_gridded_splines::grid_new_points ( class(fitpack_gridded_spline), intent(inout) this,
real(fp_real), dimension(:,:), intent(in) xg,
real(fp_real), dimension(..), intent(in) z,
integer(fp_size), dimension(:), intent(in), optional m,
logical(fp_bool), intent(in), optional row_major,
integer(fp_size), intent(in), optional order )
private

Load new gridded data. z is assumed-rank: a rank-d array (2 <= d <= MAX_IDIM) whose shape gives the per-axis point counts, or a flat rank-1 array with explicit m.

Parameters
[in]xgGrid coordinates, xg(1:m(d),d) strictly increasing on axis d.
[in]zFunction values (see the module header for the layout conventions).
[in]mPer-axis point counts; REQUIRED when z is rank-1, ignored otherwise.
[in]row_majorLayout of a rank-d z (default .true.); see the module header.
[in]orderOptional per-axis spline degree (scalar, applied to all axes).
Here is the call graph for this function:

◆ grid_prepare_workspace()

subroutine fitpack_gridded_splines::grid_prepare_workspace ( class(fitpack_gridded_spline), intent(inout) this)
private

(Re)size the persistent workspace, maximally, so it is allocated only once, at spline construction. Covers both regrid's fit requirement (mirroring its internal lwest/kwest) and the peripheral evaluations (ndspev/parder/pardeu on grids up to the data-grid size), which carve their scratch past regrid's persistent iopt=1 state in wrk(1:2+dims)/ iwrk(1:1+dims). Grows the arrays only when needed so a continuation keeps that state.

◆ ranked_sizes()

pure subroutine fitpack_gridded_splines::ranked_sizes ( integer(fp_size), dimension(:), intent(in) shp,
logical(fp_bool), intent(in) row_major,
integer(fp_dim), intent(out) dims,
integer(fp_size), dimension(max_idim), intent(out) m )
private

Map a rank-d array shape to per-axis domain sizes, honouring the row_major flag. row_major=.true.: axes are reversed (z(m_d,...,m_1)); .false.: natural (z(m_1,...,m_d)).