|
fitpack
Modern Fortran library for curve and surface fitting with splines
|
Univariate spline curve fitting module. More...
Data Types | |
| interface | fitpack_curve |
| Univariate spline curve \( y = s(x) \). More... | |
| type | fitpack_periodic_curve |
| Derived type describing a periodic curve. No changes are made to the storage, but the appropriate package functions will be called depending on the type. More... | |
Functions/Subroutines | |
| type(fitpack_curve) function | new_from_points (x, y, w, ierr) |
| Construct a fitpack_curve from data points and perform a default fit. | |
| integer(fp_flag) function | new_fit (this, x, y, w, smoothing, order) |
| Load new data points and perform a fresh fit. | |
| elemental subroutine | destroy (this) |
| Destroy a curve object and release all allocated memory. | |
| subroutine | new_points (this, x, y, w) |
| Load new data points into the curve, resetting all internal state. | |
| real(fp_real) function | curve_eval_one (this, x, ierr) |
| Evaluate the spline at a single point (with error flag). | |
| pure real(fp_real) function | curve_eval_one_noerr (this, x) |
| Evaluate the spline at a single point (pure, returns NaN on error). | |
| real(fp_real) function, dimension(size(x)) | curve_eval_many (this, x, ierr) |
| Evaluate the spline at multiple points (with error flag). | |
| pure real(fp_real) function, dimension(size(x)) | curve_eval_many_pure (this, x) |
| Evaluate the spline at multiple points (pure, returns NaN on error). | |
| integer(fp_flag) function | interpolating_curve (this, order, reset_knots) |
| Fit an interpolating spline ( \( s = 0 \)) through the data points. | |
| integer(fp_flag) function | curve_fit_least_squares (this, smoothing, reset_knots) |
| Fit a least-squares spline with fixed knots. | |
| integer(fp_flag) function | curve_fit_automatic_knots (this, smoothing, order, keep_knots) |
| Fit a smoothing spline with automatic knot placement (curfit / percur). | |
| real(fp_real) function, dimension(size(x)) | curve_derivatives (this, x, order, ierr) |
| Evaluate the k-th derivative at multiple points (with error flag). | |
| real(fp_real) function, dimension(this%order+1) | curve_all_derivatives (this, x, ierr) |
| Evaluate all derivatives \( s^{(j)}(x) \) for \( j = 0, \ldots, k \) (with error flag). | |
| real(fp_real) function, dimension(this%order+1) | curve_all_derivatives_pure (this, x) |
| Evaluate all derivatives \( s^{(j)}(x) \) for \( j = 0, \ldots, k \) (pure, NaN on error). | |
| real(fp_real) function | curve_derivative (this, x, order, ierr) |
| Evaluate the k-th derivative at a single point (with optional error flag). | |
| real(fp_real) function | integral (this, from, to) |
| Compute the definite integral \( \int_a^b s(x)\,dx \) via splint. | |
| subroutine | fourier_coefficients (this, alpha, a, b, ierr) |
| Compute Fourier sine and cosine coefficients of the spline. | |
| real(fp_real) function, dimension(:), allocatable | zeros (this, ierr) |
| Find all real zeros of a cubic spline \( s(x) = 0 \). | |
| subroutine | grow_knot_storage (this) |
| Grow the knot and coefficient arrays when storage is insufficient. | |
| subroutine | curve_insert_knot_one (this, x, ierr) |
| Insert a single knot into the B-spline representation. | |
| subroutine | curve_insert_knot_many (this, x, ierr) |
| Insert multiple knots into the B-spline representation. | |
| elemental integer(fp_size) function | curve_comm_size (this) |
| Return the communication buffer size (number of FP_COMM elements). | |
| pure subroutine | curve_comm_pack (this, buffer) |
| Pack curve data into a communication buffer for parallel transfer. | |
| pure subroutine | curve_comm_expand (this, buffer) |
| Expand curve data from a communication buffer. | |
Variables | |
| integer, parameter | max_k = 5 |
Univariate spline curve fitting module.
Provides fitpack_curve for fitting and evaluating a spline \( y = s(x) \) to data, and fitpack_periodic_curve for periodic splines. Wraps curfit / percur for fitting, splev for evaluation, splder / spalde for derivatives, splint for integration, sproot for zero-finding, and fourco for Fourier coefficients.
|
private |
Evaluate all derivatives \( s^{(j)}(x) \) for \( j = 0, \ldots, k \) (with error flag).
| [in,out] | this | The fitted curve object. |
| [in] | x | Scalar evaluation point. |
| [out] | ierr | Error flag. |
|
private |
Evaluate all derivatives \( s^{(j)}(x) \) for \( j = 0, \ldots, k \) (pure, NaN on error).
| [in] | this | The fitted curve object. |
| [in] | x | Scalar evaluation point. |
|
private |
Expand curve data from a communication buffer.
|
private |
Pack curve data into a communication buffer for parallel transfer.
|
private |
Return the communication buffer size (number of FP_COMM elements).

|
private |
Evaluate the k-th derivative at a single point (with optional error flag).
| [in,out] | this | The fitted curve object. |
| [in] | x | Scalar evaluation point. |
| [in] | order | Derivative order ( \( 0 \leq \text{order} \leq k \)). |
| [out] | ierr | Optional error flag. |

|
private |
Evaluate the k-th derivative at multiple points (with error flag).
| [in,out] | this | The fitted curve object. |
| [in] | x | Array of evaluation points. |
| [in] | order | Derivative order ( \( 0 \leq \text{order} \leq k \)). |
| [out] | ierr | Optional error flag. |
|
private |
Evaluate the spline at multiple points (with error flag).
|
private |
Evaluate the spline at multiple points (pure, returns NaN on error).
|
private |
Evaluate the spline at a single point (with error flag).
| [in,out] | this | The fitted curve object. |
| [in] | x | Evaluation point. |
| [out] | ierr | Error flag. |

|
private |
Evaluate the spline at a single point (pure, returns NaN on error).
| [in] | this | The fitted curve object. |
| [in] | x | Evaluation point. |

|
private |
Fit a smoothing spline with automatic knot placement (curfit / percur).
Get smoothing trajectory
Ensure we start with new knots (unless caller wants to keep them)
Set/update order
|
private |
Fit a least-squares spline with fixed knots.
|
private |
Insert multiple knots into the B-spline representation.
| [in,out] | this | The fitted curve. |
| [in] | x | Array of knot positions to insert. |
| [out] | ierr | Optional error flag. |
|
private |
Insert a single knot into the B-spline representation.
The spline value is unchanged; only the knot vector and coefficients are updated. Workspace state is reset after insertion.
| [in,out] | this | The fitted curve. |
| [in] | x | Knot position to insert. |
| [out] | ierr | Optional error flag. |

|
private |
Destroy a curve object and release all allocated memory.
|
private |
Compute Fourier sine and cosine coefficients of the spline.
Computes integrals over the interior knot range \( [t_4, t_{n-3}] \):
\[ A_i = \int_{t_4}^{t_{n-3}} s(x) \sin(\alpha_i x) \, dx, \quad B_i = \int_{t_4}^{t_{n-3}} s(x) \cos(\alpha_i x) \, dx \]
Requires at least 10 knots.
| [in,out] | this | The fitted curve (must have \( \geq 10 \) knots). |
| [in] | alpha | Array of frequency values \( \alpha_i \). |
| [out] | A | Sine coefficients, same size as alpha. |
| [out] | B | Cosine coefficients, same size as alpha. |
| [out] | ierr | Optional error flag. |
|
private |
Grow the knot and coefficient arrays when storage is insufficient.
|
private |
Compute the definite integral \( \int_a^b s(x)\,dx \) via splint.

|
private |
Fit an interpolating spline ( \( s = 0 \)) through the data points.

|
private |
Load new data points and perform a fresh fit.

|
private |
Construct a fitpack_curve from data points and perform a default fit.
| [in] | x | Independent variable values (must be sortable). |
| [in] | y | Dependent variable values, same size as x. |
| [in] | w | Optional weights (positive), same size as x. |
| [out] | ierr | Optional error flag. |
|
private |
Load new data points into the curve, resetting all internal state.
Sorts data by x, allocates knot/coefficient storage, and prepares workspaces. A subsequent call to fit, interpolate, or least_squares is required to compute the spline representation.
| [in,out] | this | The curve object (destroyed and reinitialized). |
| [in] | x | Independent variable values (unsorted OK; will be sorted internally). |
| [in] | y | Dependent variable values, same size as x. |
| [in] | w | Optional positive weights, same size as x. Default: uniform. |
|
private |
Find all real zeros of a cubic spline \( s(x) = 0 \).
Only valid for cubic splines ( \( k = 3 \)). Iteratively grows storage until all zeros are found.
| [in] | this | The fitted cubic curve. |
| [out] | ierr | Optional error flag. |
Always return an allocated array

|
private |