|
fitpack
Modern Fortran library for curve and surface fitting with splines
|
Data Types | |
| interface | fitpack_polar_boundary |
| interface | fitpack_swap |
| interface | fp_comm_expand |
| Expand communication buffer into allocatable arrays. More... | |
| interface | fp_comm_pack |
| Pack allocatable arrays into communication buffer. More... | |
| interface | fp_comm_size |
| Communication size for allocatable 1D arrays. More... | |
Functions/Subroutines | |
| subroutine, public | fitpack_error_handling (ierr, ierr_out, whereat) |
| Dispatch an error code: return it to caller or halt with a message. | |
| pure character(len=:) function, allocatable, public | fitpack_message (ierr) |
| Convert an integer error flag to a human-readable message string. | |
| subroutine, public | get_smoothing (old_smoothing, user_smoothing, nit, smooth_now) |
| Choose the smoothing parameter(s) for an iterative fit. | |
| pure character(len=:) function, allocatable, public | iopt_message (iopt) |
Convert an iopt computation-mode flag to a human-readable string. | |
| elemental logical(fp_bool) function, public | fitpack_success (ierr) |
| Test whether a FITPACK error flag indicates success. | |
| pure subroutine, public | bispeu (tx, nx, ty, ny, c, kx, ky, x, y, z, m, wrk, lwrk, ier) |
| Evaluate a bivariate spline at scattered points \( (x_i, y_i) \). | |
| pure subroutine, public | bispev (tx, nx, ty, ny, c, kx, ky, x, mx, y, my, z, wrk, lwrk, iwrk, kwrk, ier) |
| Evaluate a bivariate spline on a rectangular grid. | |
| pure subroutine, public | clocur (iopt, ipar, idim, m, u, mx, x, w, k, s, nest, n, t, nc, c, fp, wrk, lwrk, iwrk, ier) |
| Determine a smooth closed parametric spline curve approximation. | |
| pure subroutine, public | cocosp (m, x, y, w, n, t, e, maxtr, maxbin, c, sq, sx, bind, wrk, lwrk, iwrk, kwrk, ier) |
| Fit a cubic spline with convexity/concavity constraints and user-specified knots. | |
| pure subroutine, public | concon (iopt, m, x, y, w, v, s, nest, maxtr, maxbin, n, t, c, sq, sx, bind, wrk, lwrk, iwrk, kwrk, ier) |
| Fit a cubic spline with convexity/concavity constraints and automatic knot placement. | |
| pure subroutine, public | concur (iopt, idim, m, u, mx, x, xx, w, ib, db, nb, ie, de, ne, k, s, nest, n, t, nc, c, np, cp, fp, wrk, lwrk, iwrk, ier) |
| Determine a smooth parametric spline curve with derivative constraints at endpoints. | |
| pure subroutine, public | cualde (idim, t, n, c, nc, k1, u, d, nd, ier) |
| Evaluate all derivatives of a parametric spline curve at a single point. | |
| pure subroutine, public | curev (idim, t, n, c, nc, k, u, m, x, mx, ier) |
| Evaluate a parametric spline curve at a set of parameter values. | |
| pure subroutine, public | curfit (iopt, m, x, y, w, xb, xe, k, s, nest, n, t, c, fp, wrk, lwrk, iwrk, ier) |
| Determine a smooth spline approximation of degree \( k \) to a set of data points. | |
| real(fp_real) function, public | dblint (tx, nx, ty, ny, c, kx, ky, xb, xe, yb, ye, wrk) |
| Compute the double integral of a bivariate spline over a rectangle. | |
| pure real(fp_real) function, public | evapol (tu, nu, tv, nv, c, rad, x, y) |
| Evaluate a polar spline \( f(x,y) = s(u,v) \) at a Cartesian point. | |
| pure subroutine, public | fourco (t, n, c, alfa, m, ress, resc, wrk1, wrk2, ier) |
| Compute Fourier coefficients of a cubic spline. | |
| pure subroutine | fpader (t, n, c, k1, x, l, d) |
| Evaluate all derivatives of a spline at a single point. | |
| pure subroutine | fpadno (maxtr, up, left, right, info, count, merk, jbind, n1, ier) |
| Add a branch to the constraint-set binary tree. | |
| pure subroutine | fpadpo (idim, t, n, c, nc, k, cp, np, cc, t1, t2) |
| Add a polynomial curve to a spline curve in B-spline representation. | |
| pure real(fp_real) function, dimension(n) | fpback (a, z, n, k, nest) |
| Solve an upper triangular banded system by back-substitution. | |
| pure real(fp_real) function, dimension(n) | fpbacp (a, b, z, n, k, k1, nest) |
| Solve a bordered upper triangular system by back-substitution. | |
| pure subroutine | fpbfou (t, n, par, ress, resc) |
| Compute Fourier coefficients of cubic B-splines. | |
| pure subroutine | fpbisp (tx, nx, ty, ny, c, kx, ky, x, mx, y, my, z, wx, wy, lx, ly) |
| Evaluate a tensor product spline on a grid. | |
| pure real(fp_real) function, dimension(max_order+1) | fpbspl (t, n, k, x, l) |
| Evaluate the non-zero B-splines at a given point. | |
| pure integer(fp_size) function | fp_knot_interval (t, x, l_start, l_max) |
| Find knot interval index l such that t(l) <= x < t(l+1). Uses hybrid search: linear for small ranges, binary for large. This replaces the repeated pattern: do while (x >= t(l+1) .and. l /= l_max) l = l + 1 end do. | |
| pure integer(fp_flag) function | fpchec (x, m, t, n, k) |
| Verify knot positions against data points (Schoenberg-Whitney check). | |
| pure integer function | fpched (x, m, t, n, k, ib, ie) |
| Verify knot positions for a constrained spline (Schoenberg-Whitney check). | |
| pure integer(fp_flag) function | fpchep (x, m, t, n, k) |
| Verify knot positions for a periodic spline (Schoenberg-Whitney check). | |
| pure subroutine | fpclos (iopt, idim, m, u, mx, x, w, k, s, nest, tol, maxit, k1, k2, n, t, nc, c, fp, fpint, z, a1, a2, b, g1, g2, q, nrdata, ier) |
| Core algorithm for closed (periodic) parametric curve fitting. | |
| pure subroutine | fpclos_reset_interp (idim, k, m, mx, n, nc, nest, kk, kk1, u, x, t, c, fp, per, fp0, s, fpint, nrdata, done) |
| Set up the initial knot configuration for closed-curve interpolation. | |
| pure subroutine | fpcoco (iopt, m, x, y, w, v, s, nest, maxtr, maxbin, n, t, c, sq, sx, bind, e, wrk, lwrk, iwrk, kwrk, ier) |
| Fit a convexity-constrained cubic smoothing spline. | |
| pure subroutine | fpcons (iopt, idim, m, u, mx, x, w, ib, ie, k, s, nest, tol, maxit, k1, k2, n, t, nc, c, fp, fpint, z, a, b, g, q, nrdata, ier) |
| Core algorithm for constrained parametric curve fitting. | |
| pure subroutine | fpcosp (m, x, y, w, n, t, e, maxtr, maxbin, c, sq, sx, bind, nm, mb, a, b, const, z, zz, u, q, info, up, left, right, jbind, ibind, ier) |
| Core algorithm for convexity-constrained cubic spline fitting. | |
| pure elemental subroutine | fpcsin (a, b, par, sia, coa, sib, cob, ress, resc) |
| Compute weighted Fourier integrals of a cubic polynomial. | |
| pure subroutine | fpcurf (iopt, x, y, w, m, xb, xe, k, s, nest, tol, maxit, k1, k2, n, t, c, fp, fpint, z, a, b, g, q, nrdata, ier) |
| Core algorithm for univariate spline curve fitting. | |
| pure subroutine | fpcuro (a, b, c, d, x, n) |
| Find the real zeros of a cubic polynomial. | |
| pure subroutine | fpcyt1 (a, n, nn) |
| LU-decompose a cyclic tridiagonal matrix. | |
| pure subroutine | fpcyt2 (a, n, b, c, nn) |
| Solve a cyclic tridiagonal system using LU factors from fpcyt1. | |
| pure subroutine | fpdeno (maxtr, up, left, right, nbind, merk) |
| Prune short branches from the constraint-set binary tree. | |
| pure subroutine | fpdisc (t, n, k2, b, nest) |
| Compute the discontinuity jumps of the B-spline derivatives. | |
| pure subroutine | fpfrno (maxtr, up, left, right, info, point, merk, n1, count, ier) |
| Collect free nodes from the constraint-set binary tree. | |
| elemental subroutine | fpgivs (piv, ww, cos, sin) |
| Compute parameters of a Givens plane rotation. | |
| pure subroutine | fp_rotate_row (h, band, a, yi, z, j_start) |
| Rotate an observation row into the upper triangular band matrix. | |
| pure subroutine | fp_rotate_row_vec (h, band, a, nest, xi, z, j_start, n, idim) |
| Rotate an observation row into a band matrix with vector RHS. | |
| pure subroutine | fp_rotate_shifted (h, band, a, nest, yi, z, j_start, j_end) |
| Rotate a smoothing-matrix row into a band matrix using shifted pivots. | |
| pure subroutine | fp_rotate_shifted_vec (h, band, a, nest, xi, z, j_start, j_end, n, idim) |
| Rotate a smoothing-matrix row into a band matrix with vector RHS. | |
| pure subroutine | fp_rotate_row_2mat_vec (h1, band1, h2, band2, a1, a2, nest, xi, z, j1_start, j1_end, n, idim) |
| Rotate a split observation row into the block-triangular periodic system with vector RHS. | |
| pure subroutine | fp_rotate_row_2mat (h1, band1, h2, band2, a1, a2, nest, yi, z, j1_start, j1_end) |
| Rotate a split observation row into the block-triangular periodic system with scalar RHS. | |
| pure subroutine | fp_rotate_row_block (h, band, a, na, right, q, nrhs, irot_start) |
| Rotate a row into a band matrix with contiguous-block RHS. | |
| pure subroutine | fp_rotate_row_stride (h, band, a, na, right, c, ldc, nrhs, irot_start) |
| Rotate a row into a band matrix with stride (row-access) RHS. | |
| pure subroutine | fp_rotate_2mat_stride (h1, band1, h2, band2, a1, a2, na, right, c, ldc, nrhs, j1_start, j1_end) |
| Rotate a split row into the block-triangular periodic system with stride RHS. | |
| pure subroutine | fpgrdi (ifsu, ifsv, ifbu, ifbv, lback, u, mu, v, mv, z, mz, dz, iop0, iop1, tu, nu, tv, nv, p, c, nc, sq, fp, fpu, fpv, mm, mvnu, spu, spv, right, q, au, av1, av2, bu, bv, aa, bb, cc, cosi, nru, nrv) |
| Compute spline coefficients on a polar/spherical grid via Kronecker product. | |
| pure subroutine | fpgrpa (ifsu, ifsv, ifbu, ifbv, idim, ipar, u, mu, v, mv, z, mz, tu, nu, tv, nv, p, c, nc, fp, fpu, fpv, mm, mvnu, spu, spv, right, q, au, au1, av, av1, bu, bv, nru, nrv) |
| Compute parametric surface spline coefficients on a grid. | |
| pure subroutine | fpgrre (ifsx, ifsy, ifbx, ifby, x, mx, y, my, z, mz, kx, ky, tx, nx, ty, ny, p, c, nc, fp, fpx, fpy, mm, mynx, kx1, kx2, ky1, ky2, spx, spy, right, q, ax, ay, bx, by, nrx, nry) |
| Compute grid-based spline coefficients via Kronecker product decomposition. | |
| pure subroutine | fpgrsp (ifsu, ifsv, ifbu, ifbv, lback, u, mu, v, mv, r, mr, dr, iop0, iop1, tu, nu, tv, nv, p, c, nc, sq, fp, fpu, fpv, mm, mvnu, spu, spv, right, q, au, av1, av2, bu, bv, a0, a1, b0, b1, c0, c1, cosi, nru, nrv) |
| Compute spherical grid spline coefficients via Kronecker product. | |
| pure subroutine | fpinst (iopt, t, n, c, k, x, l, tt, nn, cc, nest) |
| Insert a single knot into a B-spline representation. | |
| pure subroutine | fpintb (t, n, bint, nk1, x, y) |
| Compute definite integrals of the normalized B-splines. | |
| pure subroutine | fpknot (x, m, t, n, fpint, nrdata, nrint, nest, istart) |
| Select and insert a new knot at the location of maximum residual. | |
| pure subroutine | fpopdi (ifsu, ifsv, ifbu, ifbv, u, mu, v, mv, z, mz, z0, dz, iopt, ider, tu, nu, tv, nv, nuest, nvest, p, step, c, nc, fp, fpu, fpv, nru, nrv, wrk, lwrk) |
| Compute smoothing spline on a polar grid with origin constraints. | |
| pure subroutine | fpopsp (ifsu, ifsv, ifbu, ifbv, u, mu, v, mv, r, mr, r0, r1, dr, iopt, ider, tu, nu, tv, nv, nuest, nvest, p, step, c, nc, fp, fpu, fpv, nru, nrv, wrk, lwrk) |
| Compute smoothing spline on a spherical grid with pole constraints. | |
| pure subroutine | fporde (x, y, m, kx, ky, tx, nx, ty, ny, nummer, index, nreg) |
| Sort scattered data points into rectangular panels. | |
| pure subroutine | fppara (iopt, idim, m, u, mx, x, w, ub, ue, k, s, nest, tol, maxit, k1, k2, n, t, nc, c, fp, fpint, z, a, b, g, q, nrdata, ier) |
| Core algorithm for open parametric curve fitting. | |
| pure subroutine | fppasu (iopt, ipar, idim, u, mu, v, mv, z, mz, s, nuest, nvest, tol, maxit, nc, nu, tu, nv, tv, c, fp, fp0, fpold, reducu, reducv, fpintu, fpintv, lastdi, nplusu, nplusv, nru, nrv, nrdatu, nrdatv, wrk, lwrk, ier) |
| Core algorithm for parametric surface fitting on a grid. | |
| pure subroutine | fpperi (iopt, x, y, w, m, k, s, nest, tol, maxit, k1, k2, n, t, c, fp, fpint, z, a1, a2, b, g1, g2, q, nrdata, ier) |
| Core algorithm for univariate periodic spline fitting. | |
| pure subroutine | fpperi_reset_interp (k, m, n, nest, kk, kk1, x, y, t, c, fp, per, fp0, s, fpint, nrdata, done) |
| Set up the initial knot configuration for periodic spline interpolation. | |
| pure subroutine | fppocu (idim, k, a, b, ib, db, nb, ie, de, ne, cp, np) |
| Construct a polynomial curve satisfying endpoint derivative constraints. | |
| pure subroutine | fppogr (iopt, ider, u, mu, v, mv, z, mz, z0, r, s, nuest, nvest, tol, maxit, nc, nu, tu, nv, tv, c, fp, fp0, fpold, reducu, reducv, fpintu, fpintv, dz, step, lastdi, nplusu, nplusv, lasttu, nru, nrv, nrdatu, nrdatv, wrk, lwrk, ier) |
| Driver for polar grid smoothing spline with knot selection. | |
| pure subroutine | fppola (iopt1, iopt2, iopt3, m, u, v, z, w, rad, s, nuest, nvest, eta, tol, maxit, ib1, ib3, nc, ncc, intest, nrest, nu, tu, nv, tv, c, fp, sup, fpint, coord, f, ff, row, cs, cosi, a, q, bu, bv, spu, spv, h, index, nummer, wrk, lwrk, ier) |
| Core algorithm for spline fitting on a polar domain. | |
| elemental subroutine | root_finding_iterate (p1, f1, p2, f2, p3, f3, p, fpms, acc, check1, check3, success) |
| Update the smoothing parameter \( p \) during iterative knot selection. | |
| pure subroutine | fprank (a, f, n, m, na, tol, c, sq, rank, aa, ff, h) |
| Compute the minimum-norm least-squares solution under rank deficiency. | |
| elemental subroutine | fprati (p1, f1, p2, f2, p3, f3, p) |
| Rational interpolation for the smoothing parameter search. | |
| pure subroutine | fpregr (iopt, x, mx, y, my, z, mz, xb, xe, yb, ye, kx, ky, s, nxest, nyest, tol, maxit, nc, nx, tx, ny, ty, c, fp, fp0, fpold, reducx, reducy, fpintx, fpinty, lastdi, nplusx, nplusy, nrx, nry, nrdatx, nrdaty, wrk, lwrk, ier) |
| Driver for rectangular grid smoothing surface with knot selection. | |
| elemental integer function | new_knot_dimension (n1, n1add, n1max, n2, n2add, n2max, last) |
| Choose which dimension receives the next knot during bivariate fitting. | |
| elemental subroutine | fprota (cos, sin, a, b) |
| Apply a Givens plane rotation to two scalars. | |
| pure subroutine | fprppo (nu, nv, if1, if2, cosi, ratio, c, f, ncoff) |
| Convert constrained polar spline coefficients to standard form. | |
| pure subroutine | fprpsp (nt, np, co, si, c, f, ncoff) |
| Convert constrained spherical spline coefficients to standard form. | |
| pure subroutine | fpseno (maxtr, up, left, right, info, merk, ibind, nbind) |
| Fetch and advance to the next branch in the constraint-set tree. | |
| pure subroutine | fpspgr (iopt, ider, u, mu, v, mv, r, mr, r0, r1, s, nuest, nvest, tol, maxit, nc, nu, tu, nv, tv, c, fp, fp0, fpold, reducu, reducv, fpintu, fpintv, dr, step, lastdi, nplusu, nplusv, lastu0, lastu1, nru, nrv, nrdatu, nrdatv, wrk, lwrk, ier) |
| Driver for spherical grid smoothing spline with knot selection. | |
| pure subroutine | fpsphe (iopt, m, teta, phi, r, w, s, ntest, npest, eta, tol, maxit, ib1, ib3, nc, ncc, intest, nrest, nt, tt, np, tp, c, fp, sup, fpint, coord, f, ff, row, coco, cosi, a, q, bt, bp, spt, spp, h, index, nummer, wrk, lwrk, ier) |
| Core algorithm for spline fitting on the sphere. | |
| pure subroutine | fpsuev (idim, tu, nu, tv, nv, c, u, mu, v, mv, f, wu, wv, lu, lv) |
| Evaluate a parametric bicubic tensor-product spline surface. | |
| pure subroutine | fpsurf (iopt, m, x, y, z, w, xb, xe, yb, ye, kxx, kyy, s, nxest, nyest, eta, tol, maxit, nmax, km1, km2, ib1, ib3, nc, intest, nrest, nx0, tx, ny0, ty, c, fp, fp0, fpint, coord, f, ff, a, q, bx, by, spx, spy, h, index, nummer, wrk, lwrk, ier) |
| Core algorithm for bivariate tensor-product spline surface fitting. | |
| pure subroutine | fpsysy (a, n, g) |
| Solve a small symmetric linear system by Cholesky factorization. | |
| pure subroutine | fptrnp (m, mm, idim, n, nr, sp, p, b, z, a, q, right) |
| Triangularize the tensor-product system for non-periodic grids. | |
| pure subroutine | fptrpe (m, mm, idim, n, nr, sp, p, b, z, a, aa, q, right) |
| Triangularize the tensor-product system for periodic grids. | |
| pure subroutine, public | insert (iopt, t, n, c, k, x, tt, nn, cc, nest, ier) |
| Insert a single knot into a spline, returning a new B-spline representation. | |
| pure subroutine, public | insert_inplace (iopt, t, n, c, k, x, nest, ier) |
| Insert a single knot into a spline in place (avoiding aliasing issues). | |
| pure subroutine, public | parcur (iopt, ipar, idim, m, u, mx, x, w, ub, ue, k, s, nest, n, t, nc, c, fp, wrk, lwrk, iwrk, ier) |
| Determine a smooth parametric spline curve approximation. | |
| pure subroutine, public | parder (tx, nx, ty, ny, c, kx, ky, nux, nuy, x, mx, y, my, z, wrk, lwrk, iwrk, kwrk, ier) |
| Evaluate a partial derivative of a bivariate spline on a rectangular grid. | |
| pure subroutine, public | pardeu (tx, nx, ty, ny, c, kx, ky, nux, nuy, x, y, z, m, wrk, lwrk, iwrk, kwrk, ier) |
| Evaluate a partial derivative of a bivariate spline at scattered points. | |
| pure subroutine, public | pardtc (tx, nx, ty, ny, c, kx, ky, nux, nuy, newc, ier) |
| Transform B-spline coefficients to obtain the partial derivative spline. | |
| pure subroutine, public | parsur (iopt, ipar, idim, mu, u, mv, v, f, s, nuest, nvest, nu, tu, nv, tv, c, fp, wrk, lwrk, iwrk, kwrk, ier) |
| Fit a smooth parametric surface to gridded data. | |
| pure subroutine, public | percur (iopt, m, x, y, w, k, s, nest, n, t, c, fp, wrk, lwrk, iwrk, ier) |
| Determine a smooth periodic spline approximation to data. | |
| subroutine, public | pogrid (iopt, ider, mu, u, mv, v, z, z0, r, s, nuest, nvest, nu, tu, nv, tv, c, fp, wrk, lwrk, iwrk, kwrk, ier) |
| Fit a smooth bivariate spline to gridded data on a polar (disc) domain. | |
| pure subroutine, public | polar (iopt, m, x, y, z, w, rad, s, nuest, nvest, eps, nu, tu, nv, tv, u, v, c, fp, wrk1, lwrk1, wrk2, lwrk2, iwrk, kwrk, ier) |
| Fit a smooth bivariate spline to scattered data on a polar domain. | |
| pure subroutine, public | profil (iopt, tx, nx, ty, ny, c, kx, ky, u, nu, cu, ier) |
| Extract a cross-section (profile) of a bivariate spline. | |
| pure subroutine, public | regrid (iopt, mx, x, my, y, z, xb, xe, yb, ye, kx, ky, s, nxest, nyest, nx, tx, ny, ty, c, fp, wrk, lwrk, iwrk, kwrk, ier) |
| Fit a smoothing bivariate spline to data on a rectangular grid. | |
| pure subroutine, public | spalde (t, n, c, k1, x, d, ier) |
| Evaluate all derivatives of a spline at a single point. | |
| pure subroutine, public | spgrid (iopt, ider, mu, u, mv, v, r, r0, r1, s, nuest, nvest, nu, tu, nv, tv, c, fp, wrk, lwrk, iwrk, kwrk, ier) |
| Fit a smooth bivariate spline to gridded data on a sphere (latitude-longitude grid). | |
| pure subroutine, public | sphere (iopt, m, teta, phi, r, w, s, ntest, npest, eps, nt, tt, np, tp, c, fp, wrk1, lwrk1, wrk2, lwrk2, iwrk, kwrk, ier) |
| Fit a smooth bicubic spherical spline to scattered data on a sphere. | |
| pure subroutine, public | splder (t, n, c, k, nu, x, y, m, e, wrk, ier) |
| Evaluate the \( \nu \)-th derivative of a spline \( s(x) \) at a set of points. | |
| pure subroutine, public | splev (t, n, c, k, x, y, m, e, ier) |
| Evaluate a spline \( s(x) \) of degree \( k \) at a set of points. | |
| real(fp_real) function, public | splint (t, n, c, k, a, b, wrk) |
| Compute the definite integral of a spline \( s(x) \) over \( [a, b] \). | |
| pure subroutine, public | sproot (t, n, c, zeros, mest, m, ier) |
| Find the zeros of a cubic spline \( s(x) \) given in B-spline representation. | |
| pure subroutine, public | surev (idim, tu, nu, tv, nv, c, u, mu, v, mv, f, mf, wrk, lwrk, iwrk, kwrk, ier) |
| Evaluate a parametric bicubic spline surface on a grid. | |
| pure subroutine, public | surfit (iopt, m, x, y, z, w, xb, xe, yb, ye, kx, ky, s, nxest, nyest, nmax, eps, nx, tx, ny, ty, c, fp, wrk1, lwrk1, wrk2, lwrk2, iwrk, kwrk, ier) |
| Fit a smoothing bivariate spline to scattered data. | |
| pure integer(fp_size) function, dimension(size(list)), public | fitpack_argsort (list) |
| Return the permutation indices that would sort an array. | |
| pure recursive subroutine | fitpack_quicksort (list, ilist, down) |
| In-place quicksort with optional index tracking. | |
| elemental subroutine | swap_data (a, b) |
| Swap two real values in place. | |
| elemental subroutine | swap_size (a, b) |
| Swap two integer values in place. | |
| elemental logical(fp_bool) function | is_before (a, b) |
| Test \( a < b \) (strict less-than). | |
| elemental logical(fp_bool) function | is_after (a, b) |
| Test \( a > b \) (strict greater-than). | |
| elemental logical(fp_bool) function | is_ge (a, b) |
| Test \( a \ge b \). | |
| elemental logical(fp_bool) function | is_le (a, b) |
| Test \( a \le b \). | |
| elemental logical(fp_bool) function, public | equal (a, b) |
| Test whether two reals are equal within machine precision. | |
| elemental logical(fp_bool) function | not_equal (a, b) |
| Test whether two reals differ beyond machine precision. | |
| elemental integer(fp_size) function, public | fp_rcomms_per_bits (nbits) |
| Number of FP_COMM elements required to store nbits of data. | |
| pure integer(fp_size) function | fp_real_comm_size_1d (array) |
| Calculate storage size for 1D real(FP_REAL) allocatable array Header: 1 FP_COMM storing bounds as 2 int32 (or NOT_ALLOC marker) Data: raw transfer of array contents. | |
| pure integer(fp_size) function | fp_real_comm_size_2d (array) |
| Calculate storage size for 2D real(FP_REAL) allocatable array. | |
| pure integer(fp_size) function | fp_real_comm_size_3d (array) |
| Calculate storage size for 3D real(FP_REAL) allocatable array. | |
| pure integer(fp_size) function | fp_size_comm_size_1d (array) |
| Calculate storage size for 1D integer(FP_SIZE) allocatable array. | |
| pure subroutine | fp_real_comm_pack_1d (array, buffer) |
| Pack 1D real(FP_REAL) allocatable array into communication buffer. | |
| pure subroutine | fp_real_comm_pack_2d (array, buffer) |
| Pack 2D real(FP_REAL) allocatable array into communication buffer. | |
| pure subroutine | fp_real_comm_pack_3d (array, buffer) |
| Pack 3D real(FP_REAL) allocatable array into communication buffer. | |
| pure subroutine | fp_size_comm_pack_1d (array, buffer) |
| Pack 1D integer(FP_SIZE) allocatable array into communication buffer. | |
| pure subroutine | fp_real_comm_expand_1d (array, buffer) |
| Expand communication buffer into 1D real(FP_REAL) allocatable array. | |
| pure subroutine | fp_real_comm_expand_2d (array, buffer) |
| Expand communication buffer into 2D real(FP_REAL) allocatable array. | |
| pure subroutine | fp_real_comm_expand_3d (array, buffer) |
| Expand communication buffer into 3D real(FP_REAL) allocatable array. | |
| pure subroutine | fp_size_comm_expand_1d (array, buffer) |
| Expand communication buffer into 1D integer(FP_SIZE) allocatable array. | |
| pure integer(fp_size) function | fp_bool_comm_size_1d (array) |
| Calculate storage size for 1D logical(FP_BOOL) allocatable array. | |
| pure subroutine | fp_bool_comm_pack_1d (array, buffer) |
| Pack 1D logical(FP_BOOL) allocatable array into communication buffer. | |
| pure subroutine | fp_bool_comm_expand_1d (array, buffer) |
| Expand communication buffer into 1D logical(FP_BOOL) allocatable array. | |
Variables | |
| integer, parameter, public | fp_real = c_double |
| integer, parameter, public | fp_size = c_int32_t |
| integer, parameter, public | fp_flag = c_int32_t |
| integer, parameter, public | fp_bool = c_bool |
| integer, parameter, public | fp_comm = c_double |
| integer(fp_size), parameter | fp_not_alloc = -99999999_FP_SIZE |
| Marker for unallocated arrays in communication buffers. | |
| integer(fp_flag), parameter, public | outside_extrapolate = 0 |
| integer(fp_flag), parameter, public | outside_zero = 1 |
| integer(fp_flag), parameter, public | outside_not_allowed = 2 |
| integer(fp_flag), parameter, public | outside_nearest_bnd = 3 |
| integer(fp_flag), parameter, public | iopt_new_leastsquares = -1 |
| integer(fp_flag), parameter, public | iopt_new_smoothing = 0 |
| integer(fp_flag), parameter, public | iopt_old_fit = 1 |
| integer(fp_size), parameter, public | max_idim = 10 |
| integer(fp_flag), parameter, public | knot_dim_none = 0 |
| integer(fp_flag), parameter, public | knot_dim_2 = 1 |
| integer(fp_flag), parameter, public | knot_dim_1 = -1 |
| integer(fp_size), parameter, public | max_order = 19 |
| integer(fp_size), parameter, public | degree_3 = 3 |
| integer(fp_size), parameter, public | degree_4 = 4 |
| integer(fp_size), parameter, public | degree_5 = 5 |
| integer(fp_flag), parameter, public | fitpack_ok = 0 |
| integer(fp_flag), parameter, public | fitpack_interpolating_ok = -1 |
| integer(fp_flag), parameter, public | fitpack_leastsquares_ok = -2 |
| integer(fp_flag), parameter, public | fitpack_insufficient_storage = 1 |
| integer(fp_flag), parameter, public | fitpack_s_too_small = 2 |
| integer(fp_flag), parameter, public | fitpack_maxit = 3 |
| integer(fp_flag), parameter, public | fitpack_too_many_knots = 4 |
| integer(fp_flag), parameter, public | fitpack_overlapping_knots = 5 |
| integer(fp_flag), parameter, public | fitpack_invalid_range = 6 |
| integer(fp_flag), parameter, public | fitpack_input_error = 10 |
| integer(fp_flag), parameter, public | fitpack_test_error = 11 |
| integer(fp_flag), parameter, public | fitpack_invalid_constraint = 12 |
| integer(fp_flag), parameter, public | fitpack_insufficient_knots = 13 |
| integer(fp_flag), parameter, public | concon_maxbin = 14 |
| integer(fp_flag), parameter, public | concon_maxtr = 15 |
| integer(fp_flag), parameter, public | concon_qp_fail = 16 |
| logical(fp_bool), parameter, public | fp_true = .true._FP_BOOL |
| logical(fp_bool), parameter, public | fp_false = .false._FP_BOOL |
| integer(fp_size), parameter | izero = 0_FP_SIZE |
| integer(fp_size), parameter | ione = 1_FP_SIZE |
| integer(fp_size), parameter | itwo = 2_FP_SIZE |
| integer(fp_size), parameter | ithree = 3_FP_SIZE |
| integer(fp_size), parameter | ifour = 4_FP_SIZE |
| integer(fp_size), parameter | ifive = 5_FP_SIZE |
| real(fp_real), parameter, public | one = 1.0_FP_REAL |
| real(fp_real), parameter, public | zero = 0.0_FP_REAL |
| real(fp_real), parameter, public | half = 0.5_FP_REAL |
| real(fp_real), parameter, public | onep5 = 1.5_FP_REAL |
| real(fp_real), parameter, public | third = one/3.0_FP_REAL |
| real(fp_real), parameter, public | fourth = 0.25_FP_REAL |
| real(fp_real), parameter, public | two = 2.0_FP_REAL |
| real(fp_real), parameter, public | three = 3.0_FP_REAL |
| real(fp_real), parameter, public | four = 4.0_FP_REAL |
| real(fp_real), parameter, public | five = 5.0_FP_REAL |
| real(fp_real), parameter, public | six = 6.0_FP_REAL |
| real(fp_real), parameter, public | ten = 10.0_FP_REAL |
| real(fp_real), parameter, public | pi = atan2(zero, -one) |
| real(fp_real), parameter, public | pi2 = 2*pi |
| real(fp_real), parameter, public | pi4 = 4*pi |
| real(fp_real), parameter, public | pio2 = half*pi |
| real(fp_real), parameter, public | pio4 = fourth*pi |
| real(fp_real), parameter, public | pio8 = 0.125_FP_REAL*pi |
| real(fp_real), parameter, public | deg2rad = pi/180.0_FP_REAL |
| real(fp_real), parameter, public | smallnum03 = 1.0e-03_FP_REAL |
| real(fp_real), parameter, public | smallnum06 = 1.0e-06_FP_REAL |
| real(fp_real), parameter, public | smallnum08 = 1.0e-08_FP_REAL |
| real(fp_real), parameter, public | smallnum10 = 1.0e-10_FP_REAL |
| pure subroutine, public fitpack_core::bispeu | ( | real(fp_real), dimension(nx), intent(in) | tx, |
| integer(fp_size), intent(in) | nx, | ||
| real(fp_real), dimension(ny), intent(in) | ty, | ||
| integer(fp_size), intent(in) | ny, | ||
| real(fp_real), dimension((nx-kx-1)*(ny-ky-1)), intent(in) | c, | ||
| integer(fp_size), intent(in) | kx, | ||
| integer(fp_size), intent(in) | ky, | ||
| real(fp_real), dimension(m), intent(in) | x, | ||
| real(fp_real), dimension(m), intent(in) | y, | ||
| real(fp_real), dimension(m), intent(out) | z, | ||
| integer(fp_size), intent(in) | m, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Evaluate a bivariate spline at scattered points \( (x_i, y_i) \).
Given a bivariate spline \( s(x,y) \) of degrees \( k_x \) and \( k_y \) in tensor-product B-spline representation, evaluates \( s(x_i, y_i) \) for \( i = 1,\ldots,m \) at arbitrary (scattered) points.
| [in] | tx | Knot positions in \( x \)-direction (length \( n_x \)). |
| [in] | nx | Total number of knots in \( x \). |
| [in] | ty | Knot positions in \( y \)-direction (length \( n_y \)). |
| [in] | ny | Total number of knots in \( y \). |
| [in] | c | B-spline coefficients, length \( (n_x{-}k_x{-}1)(n_y{-}k_y{-}1) \). |
| [in] | kx | Degree in \( x \). |
| [in] | ky | Degree in \( y \). |
| [in] | x | \( x \)-coordinates of evaluation points (length \( m \)). |
| [in] | y | \( y \)-coordinates of evaluation points (length \( m \)). |
| [out] | z | Spline values \( s(x_i, y_i) \) (length \( m \)). |
| [in] | m | Number of evaluation points, \( m \ge 1 \). |
| [in,out] | wrk | Real workspace, length \( \ge k_x + k_y + 2 \). |
| [in] | lwrk | Declared dimension of wrk. |
| [out] | ier | Error flag: 0 = normal return; 10 = invalid input. |

| pure subroutine, public fitpack_core::bispev | ( | real(fp_real), dimension(nx), intent(in) | tx, |
| integer(fp_size), intent(in) | nx, | ||
| real(fp_real), dimension(ny), intent(in) | ty, | ||
| integer(fp_size), intent(in) | ny, | ||
| real(fp_real), dimension((nx-kx-1)*(ny-ky-1)), intent(in) | c, | ||
| integer(fp_size), intent(in) | kx, | ||
| integer(fp_size), intent(in) | ky, | ||
| real(fp_real), dimension(mx), intent(in) | x, | ||
| integer(fp_size), intent(in) | mx, | ||
| real(fp_real), dimension(my), intent(in) | y, | ||
| integer(fp_size), intent(in) | my, | ||
| real(fp_real), dimension(mx*my), intent(out) | z, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(kwrk), intent(inout) | iwrk, | ||
| integer(fp_size), intent(in) | kwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Evaluate a bivariate spline on a rectangular grid.
Given a bivariate spline \( s(x,y) \) of degrees \( k_x \) and \( k_y \) in tensor-product B-spline representation, evaluates \( s(x_i, y_j) \) on the grid \( i = 1,\ldots,m_x;\ j = 1,\ldots,m_y \).

| pure subroutine, public fitpack_core::clocur | ( | integer(fp_size), intent(in) | iopt, |
| integer(fp_size), intent(in) | ipar, | ||
| integer(fp_size), intent(in) | idim, | ||
| integer(fp_size), intent(in) | m, | ||
| real(fp_real), dimension(m), intent(inout) | u, | ||
| integer(fp_size), intent(in) | mx, | ||
| real(fp_real), dimension(mx), intent(in) | x, | ||
| real(fp_real), dimension(m), intent(in) | w, | ||
| integer(fp_size), intent(in) | k, | ||
| real(fp_real), intent(in) | s, | ||
| integer(fp_size), intent(in) | nest, | ||
| integer(fp_size), intent(inout) | n, | ||
| real(fp_real), dimension(nest), intent(inout) | t, | ||
| integer(fp_size), intent(in) | nc, | ||
| real(fp_real), dimension(nc), intent(inout) | c, | ||
| real(fp_real), intent(inout) | fp, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(nest), intent(inout) | iwrk, | ||
| integer(fp_flag), intent(inout) | ier ) |
Determine a smooth closed parametric spline curve approximation.
Given \( m \) data points \( \mathbf{x}_i \in \mathbb{R}^{\text{idim}} \) with \( \mathbf{x}_1 = \mathbf{x}_m \) (closure condition) and weights \( w_i > 0 \), computes an idim-dimensional periodic spline curve \( \mathbf{s}(u) = (s_1(u),\ldots,s_{\text{idim}}(u)) \) of degree \( k \).
Parameter values \( u_i \) can be supplied by the user (ipar=1) or computed automatically from cumulative chord lengths (ipar=0).
| [in] | iopt | Computation mode: -1 (LSQ), 0 (new smoothing), 1 (continue). |
| [in] | ipar | Parameter mode: 0 = automatic (chord-length), 1 = user-supplied. |
| [in] | idim | Dimension of the curve, \( 1 \le \text{idim} \le 10 \). |
| [in] | m | Number of data points, \( m > 1 \). |
| [in,out] | u | Parameter values (length \( m \)). Output when ipar=0. |
| [in] | mx | Declared dimension of x, \( \text{mx} \ge \text{idim} \times m \). |
| [in] | x | Data coordinates: x(idim*(i-1)+j) is the \( j \)-th coordinate of point \( i \). First and last points must coincide. |
| [in] | w | Weights (length \( m \)). \( w_m \) not used. |
| [in] | k | Spline degree, \( 1 \le k \le 5 \). Cubic recommended. |
| [in] | s | Smoothing factor \( S \ge 0 \). |
| [in] | nest | Over-estimate of total knots. nest=m+2*k always suffices. |
| [in,out] | n | Total number of knots. |
| [in,out] | t | Knot positions (length nest). |
| [in] | nc | Declared dimension of c, \( \text{nc} \ge \text{nest} \times \text{idim} \). |
| [in,out] | c | B-spline coefficients (length nc). |
| [in,out] | fp | Weighted sum of squared residuals. |
| [in,out] | wrk | Real workspace, length \( \ge m(k+1) + \text{nest}(7+\text{idim}+5k) \). |
| [in] | lwrk | Declared dimension of wrk. |
| [in,out] | iwrk | Integer workspace (length nest). |
| [in,out] | ier | Error flag (same codes as curfit). |

| pure subroutine, public fitpack_core::cocosp | ( | integer(fp_size), intent(in) | m, |
| real(fp_real), dimension(m), intent(in) | x, | ||
| real(fp_real), dimension(m), intent(in) | y, | ||
| real(fp_real), dimension(m), intent(in) | w, | ||
| integer(fp_size), intent(in) | n, | ||
| real(fp_real), dimension(n), intent(in) | t, | ||
| real(fp_real), dimension(n), intent(inout) | e, | ||
| integer(fp_size), intent(in) | maxtr, | ||
| integer(fp_size), intent(in) | maxbin, | ||
| real(fp_real), dimension(n), intent(out) | c, | ||
| real(fp_real), intent(out) | sq, | ||
| real(fp_real), dimension(m), intent(out) | sx, | ||
| logical(fp_bool), dimension(n), intent(out) | bind, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(kwrk), intent(inout) | iwrk, | ||
| integer(fp_size), intent(in) | kwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Fit a cubic spline with convexity/concavity constraints and user-specified knots.
Given data points \( (x_i, y_i) \) with weights \( w_i > 0 \) and a fixed set of knots \( t_j \), computes the weighted least-squares cubic spline \( s(x) \) subject to local convexity/concavity constraints specified by the array e:
The constrained fitting uses a quadratic programming approach with a binary tree structure for managing active constraints.
| [in] | m | Number of data points, \( m > 3 \). |
| [in] | x | Abscissae (strictly ascending). |
| [in] | y | Ordinates. |
| [in] | w | Weights, \( w_i > 0 \). |
| [in] | n | Total number of knots, \( 8 \le n \le m + 4 \). |
| [in] | t | Knot positions (length \( n \)), user-specified. |
| [in,out] | e | Convexity indicators (length \( n \)). Only e(1:n-6) used. |
| [in] | maxtr | Over-estimate of tree records. maxtr=100 usually sufficient. |
| [in] | maxbin | Over-estimate of inflection knots. maxbin=10 usually sufficient. |
| [out] | c | B-spline coefficients (length \( n \)). |
| [out] | sq | Weighted sum of squared residuals. |
| [out] | sx | Spline values at data points (length \( m \)). |
| [out] | bind | Active constraint flags (length \( n \)): .true. where \( s''=0 \). |
| [in,out] | wrk | Real workspace, length \( \ge 4m + 7n + \text{maxbin}(\text{maxbin}+n+1) \). |
| [in] | lwrk | Declared dimension of wrk. |
| [in,out] | iwrk | Integer workspace, length \( \ge 4 \times \text{maxtr} + 2(\text{maxbin}+1) \). |
| [in] | kwrk | Declared dimension of iwrk. |
| [out] | ier | Error flag: 0 = success; 1 = maxbin exceeded; 2 = maxtr exceeded; 3 = QP solver failed; 10 = invalid input. |

| pure subroutine, public fitpack_core::concon | ( | integer(fp_size), intent(in) | iopt, |
| integer(fp_size), intent(in) | m, | ||
| real(fp_real), dimension(m), intent(in) | x, | ||
| real(fp_real), dimension(m), intent(in) | y, | ||
| real(fp_real), dimension(m), intent(in) | w, | ||
| real(fp_real), dimension(m), intent(inout) | v, | ||
| real(fp_real), intent(in) | s, | ||
| integer(fp_size), intent(in) | nest, | ||
| integer(fp_size), intent(in) | maxtr, | ||
| integer(fp_size), intent(in) | maxbin, | ||
| integer(fp_size), intent(inout) | n, | ||
| real(fp_real), dimension(nest), intent(inout) | t, | ||
| real(fp_real), dimension(nest), intent(inout) | c, | ||
| real(fp_real), intent(out) | sq, | ||
| real(fp_real), dimension(m), intent(inout) | sx, | ||
| logical(fp_bool), dimension(nest), intent(inout) | bind, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(kwrk), intent(inout) | iwrk, | ||
| integer(fp_size), intent(in) | kwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Fit a cubic spline with convexity/concavity constraints and automatic knot placement.
Given data points \( (x_i, y_i) \) with weights \( w_i > 0 \) and local convexity/concavity requirements \( v_i \in \{-1, 0, +1\} \) at the data points, determines a cubic spline \( s(x) \) satisfying the constraints with weighted residual sum \( \text{sq} \le S \).
Unlike cocosp (which takes fixed knots), concon automatically selects the number and position of knots, starting from a minimal set and adding knots progressively.
| [in] | iopt | Computation mode: 0 = start with minimal knots; 1 = continue. |
| [in] | m | Number of data points, \( m > 3 \). |
| [in] | x | Abscissae (strictly ascending). |
| [in] | y | Ordinates. |
| [in] | w | Weights, \( w_i > 0 \). |
| [in,out] | v | Convexity indicators at data points: +1 (concave), -1 (convex), 0 (free). |
| [in] | s | Smoothing factor \( S \ge 0 \) (target upper bound for sq). |
| [in] | nest | Over-estimate of total knots, \( \ge 8 \). nest=m+4 always suffices. |
| [in] | maxtr | Over-estimate of tree records. maxtr=100 usually sufficient. |
| [in] | maxbin | Over-estimate of inflection knots. maxbin=10 usually sufficient. |
| [in,out] | n | Total number of knots. |
| [in,out] | t | Knot positions (length nest). |
| [in,out] | c | B-spline coefficients (length nest). |
| [out] | sq | Weighted sum of squared residuals. |
| [in,out] | sx | Spline values at data points (length \( m \)). |
| [in,out] | bind | Active constraint flags (length nest). |
| [in,out] | wrk | Real workspace, length \( \ge 4m + 8\,\text{nest} + \text{maxbin}(\text{maxbin}+\text{nest}+1) \). |
| [in] | lwrk | Declared dimension of wrk. |
| [in,out] | iwrk | Integer workspace, length \( \ge 4\,\text{maxtr} + 2(\text{maxbin}+1) \). |
| [in] | kwrk | Declared dimension of iwrk. |
| [out] | ier | Error flag:
|

| pure subroutine, public fitpack_core::concur | ( | integer(fp_size), intent(in) | iopt, |
| integer(fp_size), intent(in) | idim, | ||
| integer(fp_size), intent(in) | m, | ||
| real(fp_real), dimension(m), intent(in) | u, | ||
| integer(fp_size), intent(in) | mx, | ||
| real(fp_real), dimension(mx), intent(in) | x, | ||
| real(fp_real), dimension(mx), intent(inout) | xx, | ||
| real(fp_real), dimension(m), intent(in) | w, | ||
| integer(fp_size), intent(in) | ib, | ||
| real(fp_real), dimension(nb), intent(in) | db, | ||
| integer(fp_size), intent(in) | nb, | ||
| integer(fp_size), intent(in) | ie, | ||
| real(fp_real), dimension(ne), intent(in) | de, | ||
| integer(fp_size), intent(in) | ne, | ||
| integer(fp_size), intent(in) | k, | ||
| real(fp_real), intent(in) | s, | ||
| integer(fp_size), intent(in) | nest, | ||
| integer(fp_size), intent(inout) | n, | ||
| real(fp_real), dimension(nest), intent(inout) | t, | ||
| integer(fp_size), intent(in) | nc, | ||
| real(fp_real), dimension(nc), intent(inout) | c, | ||
| integer(fp_size), intent(in) | np, | ||
| real(fp_real), dimension(np), intent(inout) | cp, | ||
| real(fp_real), intent(inout) | fp, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(nest), intent(inout) | iwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Determine a smooth parametric spline curve with derivative constraints at endpoints.
Given \( m \) ordered points \( \mathbf{x}_i \in \mathbb{R}^{\text{idim}} \) with parameter values \( u_i \) and weights \( w_i > 0 \), computes a parametric spline curve \( \mathbf{s}(u) \) of degree \( k \) that satisfies derivative constraints at the endpoints:
\[ s_j^{(l)}(u_1) = d_b(\text{idim} \cdot l + j), \quad l = 0,\ldots,i_b{-}1 \]
\[ s_j^{(l)}(u_m) = d_e(\text{idim} \cdot l + j), \quad l = 0,\ldots,i_e{-}1 \]
| [in] | iopt | Computation mode: -1 (LSQ), 0 (new smoothing), 1 (continue). |
| [in] | idim | Dimension of the curve, \( 1 \le \text{idim} \le 10 \). |
| [in] | m | Number of data points. |
| [in] | u | Parameter values (strictly ascending). |
| [in] | mx | Declared dimension of x and xx. |
| [in] | x | Data coordinates (length mx). |
| [in,out] | xx | Workspace (length mx). Modified data for constrained fitting. |
| [in] | w | Weights (length \( m \)), strictly positive. |
| [in] | ib | Number of derivative constraints at \( u_1 \), \( 0 \le i_b \le (k+1)/2 \). |
| [in] | db | Begin-point derivatives (length nb). |
| [in] | nb | Dimension of db, \( \ge \max(1, \text{idim} \times i_b) \). |
| [in] | ie | Number of derivative constraints at \( u_m \), \( 0 \le i_e \le (k+1)/2 \). |
| [in] | de | End-point derivatives (length ne). |
| [in] | ne | Dimension of de, \( \ge \max(1, \text{idim} \times i_e) \). |
| [in] | k | Spline degree: 1, 3, or 5. |
| [in] | s | Smoothing factor \( S \ge 0 \). |
| [in] | nest | Over-estimate of total knots. |
| [in,out] | n | Total number of knots. |
| [in,out] | t | Knot positions (length nest). |
| [in] | nc | Declared dimension of c. |
| [in,out] | c | B-spline coefficients (length nc). |
| [in] | np | Declared dimension of cp, \( \ge 2(k+1) \times \text{idim} \). |
| [in,out] | cp | Constraint polynomial coefficients (length np). |
| [in,out] | fp | Weighted sum of squared residuals. |
| [in,out] | wrk | Real workspace. |
| [in] | lwrk | Declared dimension of wrk. |
| [in,out] | iwrk | Integer workspace (length nest). |
| [out] | ier | Error flag (same codes as curfit). |

| pure subroutine, public fitpack_core::cualde | ( | integer(fp_size), intent(in) | idim, |
| real(fp_real), dimension(n), intent(in) | t, | ||
| integer(fp_size), intent(in) | n, | ||
| real(fp_real), dimension(nc), intent(in) | c, | ||
| integer(fp_size), intent(in) | nc, | ||
| integer(fp_size), intent(in) | k1, | ||
| real(fp_real), intent(in) | u, | ||
| real(fp_real), dimension(nd), intent(out) | d, | ||
| integer(fp_size), intent(in) | nd, | ||
| integer(fp_flag), intent(out) | ier ) |
Evaluate all derivatives of a parametric spline curve at a single point.
Given an idim-dimensional spline curve \( \mathbf{s}(u) = (s_1(u),\ldots,s_{\text{idim}}(u)) \) of order \( k_1 = k + 1 \) with common knots, evaluates all derivatives up to order \( k \) at the point \( u \). Uses the stable recurrence scheme of de Boor for each coordinate component.
| [in] | idim | Dimension of the curve. |
| [in] | t | Knot positions (length \( n \)), common to all components. |
| [in] | n | Total number of knots. |
| [in] | c | B-spline coefficients (length nc), stored as \( n \) coefficients for each of the idim components consecutively. |
| [in] | nc | Total number of coefficients ( \( \ge n \times \text{idim} \)). |
| [in] | k1 | Order of the spline ( \( k_1 = k + 1 \)). |
| [in] | u | Parameter value where derivatives are evaluated. Must satisfy \( t_{k_1} \le u \le t_{n-k_1+1} \). |
| [out] | d | Derivative values (length nd): d(idim*l+j) contains the \( j \)-th coordinate of the \( l \)-th derivative. |
| [in] | nd | Dimension of d. Must satisfy \( \text{nd} \ge k_1 \times \text{idim} \). |
| [out] | ier | Error flag: 0 = normal return; 10 = invalid input. |

| pure subroutine, public fitpack_core::curev | ( | integer(fp_size), intent(in) | idim, |
| real(fp_real), dimension(n), intent(in) | t, | ||
| integer(fp_size), intent(in) | n, | ||
| real(fp_real), dimension(nc), intent(in) | c, | ||
| integer(fp_size), intent(in) | nc, | ||
| integer(fp_size), intent(in) | k, | ||
| real(fp_real), dimension(m), intent(in) | u, | ||
| integer(fp_size), intent(in) | m, | ||
| real(fp_real), dimension(idim,m), intent(out) | x, | ||
| integer(fp_size), intent(in) | mx, | ||
| integer(fp_flag), intent(out) | ier ) |
Evaluate a parametric spline curve at a set of parameter values.
Given an idim-dimensional spline curve \( \mathbf{s}(u) = (s_1(u),\ldots,s_{\text{idim}}(u)) \) of degree \( k \) in B-spline representation with common knots, evaluates \( \mathbf{s}(u_i) \) for \( i = 1,\ldots,m \).
| [in] | idim | Dimension of the curve ( \( 1 \le \text{idim} \le 10 \)). |
| [in] | t | Knot positions (length \( n \)). |
| [in] | n | Total number of knots. |
| [in] | c | B-spline coefficients (length nc), stored consecutively for each dimension. |
| [in] | nc | Total number of coefficients. |
| [in] | k | Degree of the spline. |
| [in] | u | Parameter values (length \( m \)), must be non-decreasing and within \( [t_{k+1}, t_{n-k}] \). |
| [in] | m | Number of evaluation points, \( m \ge 1 \). |
| [out] | x | Curve values (length mx): x(idim*(i-1)+j) is the \( j \)-th coordinate at the \( i \)-th point. |
| [in] | mx | Dimension of x. Must satisfy \( \text{mx} \ge m \times \text{idim} \). |
| [out] | ier | Error flag: 0 = normal return; 10 = invalid input. |

| pure subroutine, public fitpack_core::curfit | ( | integer(fp_size), intent(in) | iopt, |
| integer(fp_size), intent(in) | m, | ||
| real(fp_real), dimension(m), intent(in) | x, | ||
| real(fp_real), dimension(m), intent(in) | y, | ||
| real(fp_real), dimension(m), intent(in) | w, | ||
| real(fp_real), intent(in) | xb, | ||
| real(fp_real), intent(in) | xe, | ||
| integer(fp_size), intent(in) | k, | ||
| real(fp_real), intent(in) | s, | ||
| integer(fp_size), intent(in) | nest, | ||
| integer(fp_size), intent(inout) | n, | ||
| real(fp_real), dimension(nest), intent(inout) | t, | ||
| real(fp_real), dimension(nest), intent(inout) | c, | ||
| real(fp_real), intent(inout) | fp, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(nest), intent(inout) | iwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Determine a smooth spline approximation of degree \( k \) to a set of data points.
Given data points \( (x_i, y_i) \) with positive weights \( w_i \), \( i=1,\ldots,m \), computes a spline \( s(x) \) of degree \( k \) on the interval \( [x_b, x_e] \).
iopt=-1: computes the weighted least-squares spline for a given set of knots.iopt>=0: the number and position of knots is chosen automatically. Smoothness is achieved by minimizing discontinuity jumps of the \( k \)-th derivative at interior knots, subject to the constraint \[ F(p) = \sum_{i=1}^{m} \bigl(w_i\,(y_i - s(x_i))\bigr)^2 \le S \]
where \( S \ge 0 \) is the smoothing factor.The result is returned in B-spline representation with coefficients \( c_j,\ j=1,\ldots,n{-}k{-}1 \) and can be evaluated with splev.

| real(fp_real) function, public fitpack_core::dblint | ( | real(fp_real), dimension(nx), intent(in) | tx, |
| integer(fp_size), intent(in) | nx, | ||
| real(fp_real), dimension(ny), intent(in) | ty, | ||
| integer(fp_size), intent(in) | ny, | ||
| real(fp_real), dimension((nx-kx-1)*(ny-ky-1)), intent(in) | c, | ||
| integer(fp_size), intent(in) | kx, | ||
| integer(fp_size), intent(in) | ky, | ||
| real(fp_real), intent(in) | xb, | ||
| real(fp_real), intent(in) | xe, | ||
| real(fp_real), intent(in) | yb, | ||
| real(fp_real), intent(in) | ye, | ||
| real(fp_real), dimension(nx+ny-kx-ky-2), intent(out) | wrk ) |
Compute the double integral of a bivariate spline over a rectangle.
Calculates \( \int_{x_b}^{x_e} \int_{y_b}^{y_e} s(x,y)\,dx\,dy \) for a bivariate spline of degrees \( k_x \) and \( k_y \) in tensor-product B-spline representation. The spline is considered identically zero outside its support rectangle \( (t^x_{k_x+1}, t^x_{n_x-k_x}) \times (t^y_{k_y+1}, t^y_{n_y-k_y}) \).
| [in] | tx | Knot positions in \( x \) (length \( n_x \)). |
| [in] | nx | Total number of knots in \( x \). |
| [in] | ty | Knot positions in \( y \) (length \( n_y \)). |
| [in] | ny | Total number of knots in \( y \). |
| [in] | c | B-spline coefficients, length \( (n_x{-}k_x{-}1)(n_y{-}k_y{-}1) \). |
| [in] | kx | Degree in \( x \). |
| [in] | ky | Degree in \( y \). |
| [in] | xb | Left boundary of integration in \( x \). |
| [in] | xe | Right boundary of integration in \( x \). |
| [in] | yb | Lower boundary of integration in \( y \). |
| [in] | ye | Upper boundary of integration in \( y \). |
| [out] | wrk | Workspace (length \( \ge n_x + n_y - k_x - k_y - 2 \)). On exit, contains integrals of normalized B-splines in each direction. |

| elemental logical(fp_bool) function, public fitpack_core::equal | ( | real(fp_real), intent(in) | a, |
| real(fp_real), intent(in) | b ) |
Test whether two reals are equal within machine precision.
Returns .true. if \( |a - b| < \text{spacing}(\min(|a|,|b|)) \).

| pure real(fp_real) function, public fitpack_core::evapol | ( | real(fp_real), dimension(nu), intent(in) | tu, |
| integer(fp_size), intent(in) | nu, | ||
| real(fp_real), dimension(nv), intent(in) | tv, | ||
| integer(fp_size), intent(in) | nv, | ||
| real(fp_real), dimension((nu-4)*(nv-4)), intent(in) | c, | ||
| procedure(fitpack_polar_boundary) | rad, | ||
| real(fp_real), intent(in) | x, | ||
| real(fp_real), intent(in) | y ) |
Evaluate a polar spline \( f(x,y) = s(u,v) \) at a Cartesian point.
Given a bicubic spline \( s(u,v) \) ( \( 0 \le u \le 1 \), \( -\pi \le v \le \pi \)) fitted by polar, evaluates \( f(x,y) \) via the polar transformation:
\[ x = u \cdot r(v) \cos v, \qquad y = u \cdot r(v) \sin v \]
where \( r(v) \) is the boundary function defining the polar domain.
| [in] | tu | Knot positions in \( u \) (length \( n_u \)). |
| [in] | nu | Total number of knots in \( u \). |
| [in] | tv | Knot positions in \( v \) (length \( n_v \)). |
| [in] | nv | Total number of knots in \( v \). |
| [in] | c | B-spline coefficients, length \( (n_u{-}4)(n_v{-}4) \). |
| [in] | rad | Boundary function \( r(v) \) defining the polar domain. |
| [in] | x | Cartesian \( x \)-coordinate. |
| [in] | y | Cartesian \( y \)-coordinate. |

| pure integer(fp_size) function, dimension(size(list)), public fitpack_core::fitpack_argsort | ( | real(fp_real), dimension(:), intent(in) | list | ) |
Return the permutation indices that would sort an array.
Returns an index array ilist such that list(ilist) is in ascending order.
| [in] | list | Array of values to sort. |
size(list)). 
| subroutine, public fitpack_core::fitpack_error_handling | ( | integer(fp_flag), intent(in) | ierr, |
| integer(fp_flag), intent(out), optional | ierr_out, | ||
| character(*), intent(in) | whereat ) |
Dispatch an error code: return it to caller or halt with a message.
If ierr_out is present, the error code is returned through it. Otherwise, if ierr indicates failure, the program halts with a diagnostic message.
| [in] | ierr | Error flag from a FITPACK routine. |
| [out] | ierr_out | Optional output flag; if present, receives ierr instead of halting. |
| [in] | whereAt | Location string for the diagnostic message. |

| pure character(len=:) function, allocatable, public fitpack_core::fitpack_message | ( | integer(fp_flag), intent(in) | ierr | ) |
Convert an integer error flag to a human-readable message string.
| [in] | ierr | FITPACK error flag (e.g., FITPACK_OK, FITPACK_INPUT_ERROR). |
|
private |
In-place quicksort with optional index tracking.
Sorts list in ascending order (or descending if down=.true.). If ilist is present, its elements are permuted in parallel to track the original positions.
| [in,out] | list | Array to sort. |
| [in,out] | ilist | Optional index array, permuted alongside list. |
| [in] | down | Optional flag for descending order. |

| elemental logical(fp_bool) function, public fitpack_core::fitpack_success | ( | integer(fp_flag), intent(in) | ierr | ) |
Test whether a FITPACK error flag indicates success.
Returns .true. if ierr <= 0 (i.e., FITPACK_OK or any negative success variant).
| [in] | ierr | Error flag from a FITPACK routine. |
.true. on success, .false. on error. 
| pure subroutine, public fitpack_core::fourco | ( | real(fp_real), dimension(n), intent(in) | t, |
| integer(fp_size), intent(in) | n, | ||
| real(fp_real), dimension(n), intent(in) | c, | ||
| real(fp_real), dimension(m), intent(in) | alfa, | ||
| integer(fp_size), intent(in) | m, | ||
| real(fp_real), dimension(m), intent(out) | ress, | ||
| real(fp_real), dimension(m), intent(out) | resc, | ||
| real(fp_real), dimension(n), intent(inout) | wrk1, | ||
| real(fp_real), dimension(n), intent(inout) | wrk2, | ||
| integer(fp_flag), intent(out) | ier ) |
Compute Fourier coefficients of a cubic spline.
For a cubic spline \( s(x) \) and a set of parameters \( \alpha_i \), \( i = 1,\ldots,m \), computes the Fourier integrals:
\[ R_s(i) = \int s(x) \sin(\alpha_i x)\,dx, \qquad R_c(i) = \int s(x) \cos(\alpha_i x)\,dx \]
over the support of the spline.
| [in] | t | Knot positions (length \( n \)). Must have \( n \ge 10 \). |
| [in] | n | Total number of knots. |
| [in] | c | B-spline coefficients (length \( n \)). |
| [in] | alfa | Fourier parameters \( \alpha_i \) (length \( m \)). |
| [in] | m | Number of integrals to compute. |
| [out] | ress | Sine integrals \( R_s(i) \) (length \( m \)). |
| [out] | resc | Cosine integrals \( R_c(i) \) (length \( m \)). |
| [in,out] | wrk1 | Real workspace (length \( n \)). |
| [in,out] | wrk2 | Real workspace (length \( n \)). |
| [out] | ier | Error flag: 0 = normal return; 10 = invalid input. |

|
private |
Expand communication buffer into 1D logical(FP_BOOL) allocatable array.
|
private |
Pack 1D logical(FP_BOOL) allocatable array into communication buffer.
|
private |
Calculate storage size for 1D logical(FP_BOOL) allocatable array.
|
private |
Find knot interval index l such that t(l) <= x < t(l+1). Uses hybrid search: linear for small ranges, binary for large. This replaces the repeated pattern: do while (x >= t(l+1) .and. l /= l_max) l = l + 1 end do.
Find the knot interval containing a given value.
Returns the index \( l \) such that \( t_l \le x < t_{l+1} \), using linear search for small ranges (or warm starts) and binary search otherwise.
| [in] | t | Knot array (non-decreasing). |
| [in] | x | Value to locate. |
| [in] | l_start | Left bound for the search. |
| [in] | l_max | Right bound for the search. |
x. | elemental integer(fp_size) function, public fitpack_core::fp_rcomms_per_bits | ( | integer(fp_size), intent(in) | nbits | ) |
Number of FP_COMM elements required to store nbits of data.

|
private |
Expand communication buffer into 1D real(FP_REAL) allocatable array.
|
private |
Expand communication buffer into 2D real(FP_REAL) allocatable array.
|
private |
Expand communication buffer into 3D real(FP_REAL) allocatable array.
|
private |
Pack 1D real(FP_REAL) allocatable array into communication buffer.
|
private |
Pack 2D real(FP_REAL) allocatable array into communication buffer.
|
private |
Pack 3D real(FP_REAL) allocatable array into communication buffer.
|
private |
Calculate storage size for 1D real(FP_REAL) allocatable array Header: 1 FP_COMM storing bounds as 2 int32 (or NOT_ALLOC marker) Data: raw transfer of array contents.
|
private |
Calculate storage size for 2D real(FP_REAL) allocatable array.
|
private |
Calculate storage size for 3D real(FP_REAL) allocatable array.
|
private |
Rotate a split row into the block-triangular periodic system with stride RHS.
Combines the two-matrix periodic decomposition (Eq. 6.13) with the stride (row-access) RHS pattern needed for grid-based surface fitting. Rotates the split row \( [h_1 \mid h_2] \) into \( [R_{11}^* \mid R_{12}^* 0 \mid R_{22}^*] \)

|
private |
Rotate an observation row into the upper triangular band matrix.
Incorporates a new observation row \( h \) (containing the \( k+1 \) non-zero B-spline values) into the upper triangular band matrix \( R \) using a sequence of Givens plane rotations (Eq. 4.15). Each rotation eliminates one element of \( h \) while updating the corresponding diagonal and upper elements of \( R \), plus the scalar right-hand side:
\[ \begin{pmatrix} c & s \\ -s & c \end{pmatrix} \begin{pmatrix} r_{j,j} \\ h_i \end{pmatrix} = \begin{pmatrix} r'_{j,j} \\ 0 \end{pmatrix} \tag{4.15} \]
This is the standard-walk variant: \( h(i) \) pivots for \( i = 1, \ldots, \texttt{band} \), targeting rows \( j = \texttt{j\_start}+1, \ldots, \texttt{j\_start}+\texttt{band} \) of \( R \). Zero pivots are skipped.
| [in,out] | h | Row to rotate, length band. Modified in place. |
| [in] | band | Number of elements in the row (typically \( k+1 \)) |
| [in,out] | a | Upper triangular band matrix \( R \). a(j,1) is the diagonal; a(j,2:) stores the upper bandwidth. |
| [in,out] | yi | Scalar RHS contribution; updated by each rotation |
| [in,out] | z | RHS vector; positions j_start+1 : j_start+band updated |
| [in] | j_start | Starting row index minus one (loop begins at j_start+1) |

|
private |
Rotate a split observation row into the block-triangular periodic system with scalar RHS.
Scalar-RHS variant of fp_rotate_row_2mat_vec. Identical two-phase algorithm for the periodic block-triangular system (Eq. 6.13) but with a scalar right-hand side \( y_i / z(j) \) instead of the vector \( \xi(d) / z(j, 1{:}d) \).
| [in,out] | h1 | First block of the observation row, length band1. Shifted left during Phase 1. |
| [in] | band1 | Length of h1 |
| [in,out] | h2 | Second block (wraparound columns), length band2 |
| [in] | band2 | Length of h2 |
| [in,out] | a1 | Band matrix \( R_{11}^* \), dimension (nest,*) |
| [in,out] | a2 | Band matrix \( R_{12}^* / R_{22}^* \), dimension (nest,*) |
| [in] | nest | Leading dimension of a1 and a2 |
| [in,out] | yi | Scalar RHS contribution; updated by rotations |
| [in,out] | z | RHS vector; entries at rows j1_start : j1_end+band2 updated |
| [in] | j1_start | First row index for Phase 1 |
| [in] | j1_end | Last row index for Phase 1 |

|
private |
Rotate a split observation row into the block-triangular periodic system with vector RHS.
Two-matrix Givens rotation for periodic spline fitting. The periodic B-spline constraint wraps the last \( k \) columns of the observation matrix into the first \( k \), producing a block-triangular structure:
\[ \begin{pmatrix} R_{11}^* & R_{12}^* \\ 0 & R_{22}^* \end{pmatrix} \tag{6.13} \]
Each observation row is split as \( [h_1 \mid h_2] \) and rotated in two phases:
| [in,out] | h1 | First block of the observation row, length band1. Shifted left during Phase 1. |
| [in] | band1 | Length of h1 (main bandwidth) |
| [in,out] | h2 | Second block (wraparound columns), length band2 |
| [in] | band2 | Length of h2 (typically \( k \)) |
| [in,out] | a1 | Band matrix \( R_{11}^* \), dimension (nest,*) |
| [in,out] | a2 | Band matrix \( R_{12}^* / R_{22}^* \), dimension (nest,*) |
| [in] | nest | Leading dimension of a1 and a2 |
| [in,out] | xi | Vector RHS contribution of length idim |
| [in,out] | z | RHS array (n, idim), one column per coordinate dimension |
| [in] | j1_start | First row index for Phase 1 |
| [in] | j1_end | Last row index for Phase 1 |
| [in] | n | Leading dimension of z |
| [in] | idim | Number of coordinate dimensions |

|
private |
Rotate a row into a band matrix with contiguous-block RHS.
Standard-walk Givens rotation for grid-based surface fitting. Rotates row \( h \) into the upper triangular band matrix \( A \), applying the same rotations to a block right-hand side: the vector right(1:nrhs) and the column q(1:nrhs, irot) of a 2D RHS matrix.
This arises from the Kronecker product decomposition of the bivariate system (Eq. 10.4-10.8), where the one-dimensional triangularizations \( A_x \) and \( A_{uu} \) operate on contiguous blocks of the tensor-product RHS.
| [in,out] | h | Row to rotate, length band. Modified in place. |
| [in] | band | Bandwidth |
| [in,out] | a | Upper triangular band matrix, dimension (na,*) |
| [in] | na | Leading dimension of a |
| [in,out] | right | Block RHS vector of length nrhs; updated by rotations |
| [in,out] | q | 2D RHS matrix (nrhs,*); column irot updated |
| [in] | nrhs | Number of RHS entries per rotation |
| [in] | irot_start | Starting row index minus one |

|
private |
Rotate a row into a band matrix with stride (row-access) RHS.
Standard-walk Givens rotation for grid-based surface fitting. Rotates row \( h \) into the upper triangular band matrix \( A \), applying the same rotations to the vector right(1:nrhs) and the row c(irot, 1:nrhs) of a 2D RHS matrix c(ldc,*).
Unlike fp_rotate_row_block (which accesses RHS by columns), this routine accesses RHS by rows — the stride pattern needed for the \( A_y \) and \( A_{vv} \) triangularizations and the tensor-product back-substitution (Eq. 10.8) in the Kronecker product decomposition.
| [in,out] | h | Row to rotate, length band. Modified in place. |
| [in] | band | Bandwidth |
| [in,out] | a | Upper triangular band matrix, dimension (na,*) |
| [in] | na | Leading dimension of a |
| [in,out] | right | Block RHS vector of length nrhs; updated by rotations |
| [in,out] | c | 2D RHS matrix (ldc,*); row irot updated |
| [in] | ldc | Leading dimension of c |
| [in] | nrhs | Number of RHS entries per rotation |
| [in] | irot_start | Starting row index minus one |

|
private |
Rotate an observation row into a band matrix with vector RHS.
Vector-RHS variant of fp_rotate_row for parametric curve fitting. Rotates a new observation row \( h \) into the upper triangular band matrix \( R \) using Givens rotations (Eq. 4.15), simultaneously transforming \( d \) right-hand side vectors stored column-wise in \( z(n, d) \).
In parametric fitting, all \( d \) coordinate curves share the same knot vector and B-spline basis, so a single triangularization of \( R \) applies the same rotations to each RHS column.
| [in,out] | h | Row to rotate, length band. Modified in place. |
| [in] | band | Bandwidth (typically \( k+1 \)) |
| [in,out] | a | Upper triangular band matrix \( R \), dimension (nest,*) |
| [in] | nest | Leading dimension of a |
| [in,out] | xi | Vector RHS contribution of length idim; updated by rotations |
| [in,out] | z | RHS array (n, idim), one column per coordinate dimension |
| [in] | j_start | Starting row index minus one |
| [in] | n | Leading dimension of z (number of coefficients) |
| [in] | idim | Number of coordinate dimensions |

|
private |
Rotate a smoothing-matrix row into a band matrix using shifted pivots.
Shifted-pivot variant of the Givens rotation for incorporating rows of the smoothing matrix \( P \) into the triangularized observation matrix. Unlike fp_rotate_row (which walks \( h(i) \) for \( i = 1, \ldots, b \)), this routine always pivots on \( h(1) \) and shifts \( h \) left after each rotation step:
\[ h \leftarrow (h_2, h_3, \ldots, h_b, 0) \]
The effective bandwidth shrinks as \( j \to \texttt{j\_end} \). This pattern arises because the smoothing matrix \( P \) (Eq. 5.5) has bandwidth \( k+2 \) and its rows are offset relative to \( R \).
| [in,out] | h | Row to rotate, length band. Shifted left at each step. |
| [in] | band | Bandwidth (typically \( k+2 \)) |
| [in,out] | a | Upper triangular band matrix \( R^* \), dimension (nest,*) |
| [in] | nest | Leading dimension of a |
| [in,out] | yi | Scalar RHS contribution; updated by rotations |
| [in,out] | z | RHS vector; positions j_start : j_end updated |
| [in] | j_start | First row index in \( R^* \) |
| [in] | j_end | Last row index in \( R^* \) |

|
private |
Rotate a smoothing-matrix row into a band matrix with vector RHS.
Shifted-pivot, vector-RHS variant of the Givens rotation. Combines the shifted-pivot pattern of fp_rotate_shifted (always pivot on \( h(1) \), shift left) with the multi-dimensional RHS of fp_rotate_row_vec. Used by smoothing iterations in parametric fitting (fpcons, fppara) where the smoothing-matrix rows \( P \) (Eq. 5.5, bandwidth \( k+2 \)) are rotated into the already-triangularized observation matrix \( R \), with \( d \) coordinate curves sharing the same knot vector.
| [in,out] | h | Row to rotate, length band. Shifted left at each step. |
| [in] | band | Bandwidth (typically \( k+2 \)) |
| [in,out] | a | Upper triangular band matrix \( R^* \), dimension (nest,*) |
| [in] | nest | Leading dimension of a |
| [in,out] | xi | Vector RHS contribution of length idim |
| [in,out] | z | RHS array (n, idim), one column per coordinate dimension |
| [in] | j_start | First row index in \( R^* \) |
| [in] | j_end | Last row index in \( R^* \) |
| [in] | n | Leading dimension of z |
| [in] | idim | Number of coordinate dimensions |

|
private |
Expand communication buffer into 1D integer(FP_SIZE) allocatable array.
|
private |
Pack 1D integer(FP_SIZE) allocatable array into communication buffer.
|
private |
Calculate storage size for 1D integer(FP_SIZE) allocatable array.
|
private |
Evaluate all derivatives of a spline at a single point.
Computes all \( k+1 \) derivatives of a spline of order \( k_1 = k+1 \) at a point \( x \) in the knot interval \( [\lambda_l, \lambda_{l+1}) \):
\[ d(j) = s^{(j-1)}(x), \quad j = 1, \ldots, k_1 \]
Uses the stable recurrence scheme of de Boor, which first forms divided differences of the B-spline coefficients, then evaluates each derivative level by the standard B-spline recursion.
| [in] | t | Knot vector \( \lambda_1, \ldots, \lambda_n \) |
| [in] | n | Length of the knot vector |
| [in] | c | B-spline coefficients, length \( n \) |
| [in] | k1 | Spline order \( k+1 \) (= degree + 1) |
| [in] | x | Evaluation point, \( \lambda_l \leq x < \lambda_{l+1} \) |
| [in] | l | Knot interval index |
| [out] | d | Array of derivatives: d(j) = \( s^{(j-1)}(x) \), \( j = 1, \ldots, k_1 \) |
|
private |
Add a branch to the constraint-set binary tree.
Adds a new branch of length n1 to the triply linked binary tree used by the Theil-Van de Panne convexity procedure (§7.2). The branch represents a candidate active-constraint set; its nodes contain constraint indices from jbind(1:n1).
The tree maintains the ordering invariant \( \text{info}(k) < \text{info}(\text{right}(k)) \) and \( \text{info}(k) < \text{info}(\text{left}(k)) \), preventing duplicate constraint sets. If no free nodes are available, fpfrno is called to reclaim nodes; if that also fails, ier = 1.
| [in] | maxtr | Size of the tree arrays |
| [in,out] | up | Parent pointers; up(i) = 0 marks a free node |
| [in,out] | left | Left-child pointers |
| [in,out] | right | Right-child pointers |
| [in,out] | info | Constraint index stored at each node |
| [in,out] | count | Next free node pointer |
| [in,out] | merk | Terminal node of the most recent branch |
| [in] | jbind | Constraint indices for the new branch, length n1 |
| [in] | n1 | Length of the new branch |
| [out] | ier | Error flag: 0 = success, 1 = tree full |

|
private |
Add a polynomial curve to a spline curve in B-spline representation.
Given a \( d \)-dimensional spline curve of degree \( k \) with knots \( t \) and coefficients \( c \), and a polynomial curve with B-spline coefficients \( c_p \) (on the knot vector \( [a, \ldots, a, b, \ldots, b] \)), computes the B-spline coefficients of their sum by inserting knots from \( t \) into the polynomial representation via fpinst, then adding coefficients.
| [in] | idim | Number of curve dimensions \( d \) |
| [in] | t | Knot vector of the spline, length n |
| [in] | n | Number of knots |
| [in,out] | c | B-spline coefficients; on exit, contains the sum |
| [in] | nc | Length of c |
| [in] | k | Spline degree |
| [in] | cp | Polynomial B-spline coefficients, length np |
| [in] | np | Length of cp |
| [in,out] | cc | Work array, length nest |
| [in,out] | t1 | Work array, length nest |
| [in,out] | t2 | Work array, length nest |

|
private |
Solve an upper triangular banded system by back-substitution.
Computes the B-spline coefficients \( c \) by solving the triangular system:
\[ R_1 \, c = z_1 \tag{4.14} \]
where \( R_1 \) is an \( n \times n \) upper triangular matrix with bandwidth \( k \), obtained from the QR factorization of the observation matrix \( E \).
\( R_1 \) is stored as a(nest, k) where a(i,1) holds the diagonal element \( r_{i,i} \) and a(i,j) for \( j > 1 \) holds \( r_{i,i+j-1} \).
| [in] | a | Upper triangular band matrix \( R_1 \), stored as a(nest, k) |
| [in] | z | Right-hand side vector \( z_1 \) of length \( n \) |
| [in] | n | Number of equations (= number of B-spline coefficients) |
| [in] | k | Bandwidth of \( R_1 \) (= spline order \( k+1 \)) |
| [in] | nest | Leading dimension of array a |
|
private |
Solve a bordered upper triangular system by back-substitution.
Computes the solution \( c \) of the system \( G \, c = z \) where \( G \) is an \( n \times n \) upper triangular matrix of the form:
\[ G = \begin{pmatrix} A & \cdot \\ 0 & B \end{pmatrix} \tag{6.6} \]
with \( A \) an \( (n-k) \times (n-k) \) upper triangular band matrix of bandwidth \( k_1 \), and \( B \) an \( n \times k \) dense matrix accounting for the periodic boundary conditions.
This arises in periodic spline fitting where the periodic B-splines \( \tilde{N}_{i,k+1} \) wrap around the domain, coupling the first and last \( k \) coefficients.
| [in] | a | Upper triangular band matrix \( A \), stored as a(nest, k1) |
| [in] | b | Dense coupling matrix \( B \), stored as b(nest, k) |
| [in] | z | Right-hand side vector of length \( n \) |
| [in] | n | Number of equations |
| [in] | k | Number of periodic coupling columns |
| [in] | k1 | Bandwidth of the triangular part \( A \) |
| [in] | nest | Leading dimension of arrays a and b |
|
private |
Compute Fourier coefficients of cubic B-splines.
Calculates the Fourier sine and cosine integrals of each cubic B-spline \( N_{j,4}(x) \) over the active knot interval:
\[ \text{ress}(j) = \int_{\lambda_4}^{\lambda_{n-3}} N_{j,4}(x) \sin(\omega x) \, dx \]
\[ \text{resc}(j) = \int_{\lambda_4}^{\lambda_{n-3}} N_{j,4}(x) \cos(\omega x) \, dx \]
for \( j = 1, \ldots, n-4 \). Uses fpcsin to evaluate the weighted integrals over each knot span.
| [in] | t | Knot vector, length n |
| [in] | n | Number of knots |
| [in] | par | Frequency \( \omega \) |
| [out] | ress | Sine integrals, length n-4 |
| [out] | resc | Cosine integrals, length n-4 |

|
private |
Evaluate a tensor product spline on a grid.
Computes the values of a bivariate spline \( s(x, y) \) of degrees \( k_x \) and \( k_y \) at the grid points \( (x_i, y_j) \), \( i = 1, \ldots, m_x \), \( j = 1, \ldots, m_y \).
The evaluation uses the two-step algorithm: first compute the B-spline basis values in each direction, then assemble:
\[ s(x, y) = \sum_{i} \left( \sum_{j} c_{i,j} \, M_{j, k_y+1}(y) \right) N_{i, k_x+1}(x) \tag{2.14-2.15} \]
The B-spline values and knot interval indices are stored in workspace arrays wx, wy, lx, ly for reuse.
| [in] | tx | Knot vector in \( x \), length nx |
| [in] | nx | Number of knots in \( x \) |
| [in] | ty | Knot vector in \( y \), length ny |
| [in] | ny | Number of knots in \( y \) |
| [in] | c | B-spline coefficients \( c_{i,j} \), length \( (n_x - k_x - 1)(n_y - k_y - 1) \) |
| [in] | kx | Spline degree in \( x \) |
| [in] | ky | Spline degree in \( y \) |
| [in] | x | Evaluation points in \( x \), length mx |
| [in] | mx | Number of evaluation points in \( x \) |
| [in] | y | Evaluation points in \( y \), length my |
| [in] | my | Number of evaluation points in \( y \) |
| [out] | z | Spline values at grid points, length mx * my, stored in row-major order: \( z((i-1) m_y + j) = s(x_i, y_j) \) |
| [out] | wx | B-spline basis values in \( x \), wx(mx, kx+1) |
| [out] | wy | B-spline basis values in \( y \), wy(my, ky+1) |
| [out] | lx | Knot interval indices in \( x \), length mx |
| [out] | ly | Knot interval indices in \( y \), length my |

|
private |
Evaluate the non-zero B-splines at a given point.
Computes the \( k+1 \) non-zero B-splines of degree \( k \) at the point \( x \) satisfying \( \lambda_l \leq x < \lambda_{l+1} \), using the stable recurrence relation of de Boor and Cox:
\[ N_{i,1}(x) = \begin{cases} 1 & \text{if } \lambda_i \leq x < \lambda_{i+1} \\ 0 & \text{otherwise} \end{cases} \]
\[ N_{i,l+1}(x) = \frac{x - \lambda_i}{\lambda_{i+l} - \lambda_i} N_{i,l}(x) + \frac{\lambda_{i+l+1} - x}{\lambda_{i+l+1} - \lambda_{i+1}} N_{i+1,l}(x) \tag{1.24} \]
The result array h contains \( N_{l-k,k+1}(x), \ldots, N_{l,k+1}(x) \) in positions h(1:k+1). When knots have multiplicity (coincident knots), zero weights are used in the recurrence (convention \( 0/0 = 0 \)).
| [in] | t | Knot vector \( \lambda_1, \ldots, \lambda_n \) |
| [in] | n | Length of the knot vector |
| [in] | k | Spline degree |
| [in] | x | Evaluation point, must satisfy \( \lambda_l \leq x < \lambda_{l+1} \) |
| [in] | l | Knot interval index, must satisfy \( k \leq l \leq n-k \) |
MAX_ORDER+1; positions 1:k+1 contain the \( k+1 \) non-zero B-spline values.
|
private |
Verify knot positions against data points (Schoenberg-Whitney check).
Checks that the knots \( \lambda_j \), \( j = 1, \ldots, n \), of a spline of degree \( k \) satisfy all conditions required for a well-posed least-squares problem with data points \( x_i \), \( i = 1, \ldots, m \).
The conditions verified are:
\[ \lambda_j < y_j < \lambda_{j+k+1}, \quad j = 1, \ldots, n-k-1 \tag{4.5} \]
guaranteeing full rank of the observation matrix.| [in] | x | Data abscissae, strictly increasing: \( x_1 < \cdots < x_m \) |
| [in] | m | Number of data points |
| [in] | t | Knot vector \( \lambda_1, \ldots, \lambda_n \) |
| [in] | n | Number of knots |
| [in] | k | Spline degree |
FITPACK_OK if all conditions hold, FITPACK_INPUT_ERROR otherwise.
|
private |
Verify knot positions for a constrained spline (Schoenberg-Whitney check).
Checks that the knots \( \lambda_j \), \( j = 1, \ldots, n \), of a spline of degree \( k \) with \( i_b \) derivative constraints at \( x_1 \) and \( i_e \) constraints at \( x_m \), satisfy all conditions required for a well-posed least-squares problem:
| [in] | x | Data abscissae, strictly increasing |
| [in] | m | Number of data points |
| [in] | t | Knot vector \( \lambda_1, \ldots, \lambda_n \) |
| [in] | n | Number of knots |
| [in] | k | Spline degree |
| [in] | ib | Number of derivative constraints at \( x_1 \) |
| [in] | ie | Number of derivative constraints at \( x_m \) |
FITPACK_OK if all conditions hold, FITPACK_INPUT_ERROR otherwise.
|
private |
Verify knot positions for a periodic spline (Schoenberg-Whitney check).
Checks that the knots \( \lambda_j \), \( j = 1, \ldots, n \), of a periodic spline of degree \( k \) satisfy all conditions required for a well-posed least-squares problem with data points \( x_i \):
| [in] | x | Data abscissae, strictly increasing |
| [in] | m | Number of data points |
| [in] | t | Knot vector \( \lambda_1, \ldots, \lambda_n \) |
| [in] | n | Number of knots |
| [in] | k | Spline degree |
FITPACK_OK if all conditions hold, FITPACK_INPUT_ERROR otherwise.
|
private |
Core algorithm for closed (periodic) parametric curve fitting.
Fits a \( d \)-dimensional closed parametric spline curve where \( s(u_1) = s(u_m) \) and all derivatives match at the closure point. The periodicity constraint wraps the last \( k \) B-spline columns into the first \( k \), creating the block-triangular structure (Eq. 6.13):
\[ \begin{pmatrix} R_{11}^* & R_{12}^* \\ 0 & R_{22}^* \end{pmatrix} \tag{6.13} \]
which is factored using two-matrix Givens rotations (fp_rotate_row_2mat_vec). The smoothing-parameter search follows the same rational interpolation scheme as fpcurf.
| [in] | iopt | 0 = new fit, 1 = continue |
| [in] | idim | Number of curve dimensions \( d \) |
| [in] | m | Number of data points |
| [in] | u | Parameter values, length m |
| [in] | mx | Length of x ( \( = m \cdot d \)) |
| [in] | x | Data coordinates, interleaved, length mx |
| [in] | w | Data weights, length m |
| [in] | k | Spline degree |
| [in] | s | Smoothing factor \( S \geq 0 \) |
| [in] | nest | Max knots |
| [in] | tol | Tolerance for smoothing condition |
| [in] | maxit | Maximum smoothing-parameter iterations |
| [in] | k1 | \( k + 1 \) |
| [in] | k2 | \( k + 2 \) |
| [in,out] | n | Number of knots |
| [in,out] | t | Knot vector, length nest |
| [in] | nc | Length of coefficient array c |
| [in,out] | c | B-spline coefficients, length nc |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | fpint | Residual sums per knot interval |
| [in,out] | z | Work: transformed RHS |
| [in,out] | a1 | Work: band matrix \( R_{11}^* \) |
| [in,out] | a2 | Work: band matrix \( R_{12}^*/R_{22}^* \) |
| [in,out] | b | Work: smoothing matrix |
| [in,out] | g1 | Work: band matrix copy |
| [in,out] | g2 | Work: band matrix copy |
| [in,out] | q | Work: B-spline values |
| [in,out] | nrdata | Interior data-point counts |
| [in,out] | ier | Error flag |

|
private |
Set up the initial knot configuration for closed-curve interpolation.
When \( s = 0 \) (interpolation) and \( k \) is odd, places interior knots at the data parameter values. For \( k = 1 \) (linear), directly sets the B-spline coefficients from the data and returns the exact interpolant. When \( k \) is even, knots are placed at midpoints of consecutive parameters.
| [in] | idim | Number of dimensions |
| [in] | k | Spline degree |
| [in] | m | Number of data points |
| [in] | mx | Length of data array x (= m * idim) |
| [in] | n | Number of knots |
| [in] | nc | Length of coefficient array c |
| [in] | nest | Maximum knots allowed |
| [in,out] | kk | Adjusted degree for iteration |
| [in,out] | kk1 | Adjusted order for iteration |
| [in] | u | Parameter values, length m |
| [in] | x | Data coordinates, length mx |
| [in,out] | t | Knot vector, length nest |
| [in,out] | c | B-spline coefficients, length nc |
| [in,out] | fp | Weighted sum of squared residuals |
| [in] | per | Period \( = u_m - u_1 \) |
| [in] | fp0 | Upper bound for the smoothing factor |
| [in] | s | Smoothing factor |
| [in,out] | fpint | Knot interval contributions, length nest |
| [in,out] | nrdata | Data point counts per interval, length nest |
| [out] | done | .true. if the interpolant was fully determined |
|
private |
Fit a convexity-constrained cubic smoothing spline.
Determines a cubic spline approximation \( s(x) \) that satisfies the convexity (or concavity) constraints specified by \( v(i) \):
while minimizing the weighted sum of squared residuals subject to \( \sum (w_i (y_i - s(x_i)))^2 \leq S \). The algorithm uses the Theil-Van de Panne quadratic programming procedure with a binary tree (§7.2) to enumerate active-constraint sets.
| [in] | iopt | Option: -1 = least-squares, 0 = new smoothing, 1 = continue from previous |
| [in] | m | Number of data points |
| [in] | x | Data abscissae, length m (strictly increasing) |
| [in] | y | Data ordinates, length m |
| [in] | w | Data weights, length m (positive) |
| [in] | v | Convexity signs, length m |
| [in] | s | Smoothing factor \( S \geq 0 \) |
| [in] | nest | Max knots (workspace dimension) |
| [in] | maxtr | Max tree nodes |
| [in] | maxbin | Max active constraints |
| [in,out] | n | Number of knots |
| [in,out] | t | Knot vector, length nest |
| [in,out] | c | B-spline coefficients, length nest |
| [in,out] | sq | Weighted sum of squared residuals |
| [in,out] | sx | Spline values at data points, length m |
| [in,out] | bind | Active constraint flags, length nest |
| [in,out] | e | Discontinuity coefficients, length nest |
| [in,out] | wrk | Work array, length lwrk |
| [in] | lwrk | Length of wrk |
| [in,out] | iwrk | Integer work array, length kwrk |
| [in] | kwrk | Length of iwrk |
| [out] | ier | Error flag |

|
private |
Core algorithm for constrained parametric curve fitting.
Fits a \( d \)-dimensional parametric spline curve \( s(u) = (s_1(u), \ldots, s_d(u)) \) subject to derivative constraints at the endpoints:
\[ s_j^{(l)}(u_1) = x_j^{(l)}, \quad l = 0, \ldots, i_b - 1 \]
\[ s_j^{(l)}(u_m) = x_j^{(l)}, \quad l = 0, \ldots, i_e - 1 \]
The algorithm first constructs a polynomial satisfying the constraints (via fppocu), then iteratively refines the knot set and solves the constrained least-squares system using Givens rotations.
| [in] | iopt | 0 = new fit, 1 = continue |
| [in] | idim | Number of curve dimensions \( d \) |
| [in] | m | Number of data points |
| [in] | u | Parameter values, length m |
| [in] | mx | Length of x ( \( = m \cdot d \)) |
| [in] | x | Data coordinates, interleaved, length mx |
| [in] | w | Data weights, length m |
| [in] | ib | Number of derivative constraints at start |
| [in] | ie | Number of derivative constraints at end |
| [in] | k | Spline degree |
| [in] | s | Smoothing factor \( S \geq 0 \) |
| [in] | nest | Max knots |
| [in] | tol | Tolerance for smoothing condition |
| [in] | maxit | Maximum smoothing-parameter iterations |
| [in] | k1 | \( k + 1 \) |
| [in] | k2 | \( k + 2 \) |
| [in,out] | n | Number of knots |
| [in,out] | t | Knot vector, length nest |
| [in] | nc | Length of coefficient array c |
| [in,out] | c | B-spline coefficients, length nc |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | fpint | Residual sums per knot interval |
| [in,out] | z | Work: transformed RHS |
| [in,out] | a | Work: band matrix |
| [in,out] | b | Work: smoothing matrix |
| [in,out] | g | Work: band matrix copy |
| [in,out] | q | Work: B-spline values |
| [in,out] | nrdata | Interior data-point counts |
| [in,out] | ier | Error flag |

|
private |
Core algorithm for convexity-constrained cubic spline fitting.
Given a fixed knot set, solves the constrained least-squares problem using the Theil-Van de Panne active-set enumeration (§7.2). For each candidate active-constraint set (tracked in a binary tree), solves the equality-constrained system and checks feasibility and optimality via the Lagrange multipliers.
| [in] | m | Number of data points |
| [in] | x | Data abscissae, length m |
| [in] | y | Data ordinates, length m |
| [in] | w | Data weights, length m |
| [in] | n | Number of knots |
| [in] | t | Knot vector, length n |
| [in] | e | Discontinuity jump coefficients, length n |
| [in] | maxtr | Max tree nodes |
| [in] | maxbin | Max active constraints |
| [in,out] | c | B-spline coefficients, length n |
| [out] | sq | Weighted sum of squared residuals |
| [in,out] | sx | Spline values at data points, length m |
| [in,out] | bind | Active constraint flags, length n |
| [in] | nm | Dimension parameter |
| [in] | mb | Dimension parameter |
| [in,out] | a | Work matrix (n, 4) |
| [in,out] | b | Work matrix (nm, maxbin) |
| [in,out] | const | Constraint vector, length n |
| [in,out] | z | Work vector, length n |
| [in,out] | zz | Work vector, length n |
| [in,out] | u | Work vector, length maxbin |
| [in,out] | q | Work matrix (m, 4) |
| [in,out] | info | Tree info array, length maxtr |
| [in,out] | up | Tree parent pointers, length maxtr |
| [in,out] | left | Tree left-child pointers, length maxtr |
| [in,out] | right | Tree right-child pointers, length maxtr |
| [in,out] | jbind | Work array for constraint indices, length mb |
| [in,out] | ibind | Work array for constraint indices, length mb |
| [out] | ier | Error flag |

|
private |
Compute weighted Fourier integrals of a cubic polynomial.
Calculates the integrals:
\[ \text{ress} = \int_a^b (b-x)^3 \sin(\omega x) \, dx, \quad \text{resc} = \int_a^b (b-x)^3 \cos(\omega x) \, dx \]
given precomputed trigonometric values at the endpoints. Used by fpbfou to compute Fourier coefficients of B-splines.
| [in] | a | Left endpoint |
| [in] | b | Right endpoint |
| [in] | par | Frequency \( \omega \) |
| [in] | sia | \( \sin(\omega a) \) |
| [in] | coa | \( \cos(\omega a) \) |
| [in] | sib | \( \sin(\omega b) \) |
| [in] | cob | \( \cos(\omega b) \) |
| [out] | ress | Sine integral result |
| [out] | resc | Cosine integral result |
|
private |
Core algorithm for univariate spline curve fitting.
Determines a smooth spline approximation \( s(x) \) of degree \( k \) on the interval \( [x_b, x_e] \) that satisfies the smoothing criterion:
\[ F_g(p) = \sum_{i=1}^{m} \bigl( w_i (y_i - s(x_i)) \bigr)^2 \leq S \tag{4.12} \]
The algorithm iterates over three levels:
| [in] | iopt | 0 = new fit, 1 = continue with more knots |
| [in] | x | Data abscissae, length m (strictly increasing) |
| [in] | y | Data ordinates, length m |
| [in] | w | Data weights, length m (positive) |
| [in] | m | Number of data points |
| [in] | xb | Left boundary of approximation interval |
| [in] | xe | Right boundary of approximation interval |
| [in] | k | Spline degree ( \( 1 \leq k \leq 5 \)) |
| [in] | s | Smoothing factor \( S \geq 0 \) |
| [in] | nest | Max number of knots (workspace bound) |
| [in] | tol | Tolerance for the smoothing condition |
| [in] | maxit | Maximum iterations for the \( p \)-search |
| [in] | k1 | \( k + 1 \) (spline order) |
| [in] | k2 | \( k + 2 \) (smoothing bandwidth) |
| [in,out] | n | Number of knots |
| [in,out] | t | Knot vector, length nest |
| [out] | c | B-spline coefficients, length nest |
| [out] | fp | Weighted sum of squared residuals \( F_g(p) \) |
| [in,out] | fpint | Residual sums per knot interval, length nest |
| [in,out] | z | Work: transformed RHS, length nest |
| [in,out] | a | Work: band matrix, (nest, k1) |
| [in,out] | b | Work: smoothing matrix, (nest, k2) |
| [in,out] | g | Work: band matrix copy, (nest, k2) |
| [in,out] | q | Work: B-spline values, (m, k1) |
| [in,out] | nrdata | Interior data-point counts per interval, length nest |
| [out] | ier | Error flag |

|
private |
Find the real zeros of a cubic polynomial.
Computes all real roots of the cubic polynomial:
\[ p(x) = a x^3 + b x^2 + c x + d \]
Handles the degenerate cases (linear, quadratic) and uses the standard trigonometric method for the irreducible case (three real roots) and Cardano's formula otherwise.
| [in] | a | Coefficient of \( x^3 \) |
| [in] | b | Coefficient of \( x^2 \) |
| [in] | c | Coefficient of \( x \) |
| [in] | d | Constant term |
| [out] | x | Array of length 3 containing the real zeros |
| [out] | n | Number of real zeros found ( \( 0 \leq n \leq 3 \)) |
|
private |
LU-decompose a cyclic tridiagonal matrix.
Computes the LU decomposition of an \( n \times n \) cyclic tridiagonal matrix arising from periodic spline fitting. The matrix has the structure:
\[ \begin{pmatrix} a_{1,2} & a_{1,3} & & & & a_{1,1} \\ a_{2,1} & a_{2,2} & a_{2,3} & & & \\ & \ddots & \ddots & \ddots & & \\ & & a_{n-1,1} & a_{n-1,2} & a_{n-1,3} \\ a_{n,3} & & & & a_{n,1} & a_{n,2} \end{pmatrix} \]
The decomposition factors are stored in columns 4-6 of the array a. The back-substitution is performed by fpcyt2.
| [in,out] | a | Matrix stored as a(nn,6). Columns 1-3 hold the tridiagonal + cyclic entries; columns 4-6 receive the LU factors. |
| [in] | n | Matrix dimension |
| [in] | nn | Leading dimension of a |
|
private |
Solve a cyclic tridiagonal system using LU factors from fpcyt1.
Solves the \( n \times n \) linear system \( A \, c = b \) where \( A \) is a cyclic tridiagonal matrix whose LU decomposition has been computed by fpcyt1 and stored in columns 4-6 of the array a.
| [in] | a | LU-factored matrix from fpcyt1, dimension (nn, 6) |
| [in] | n | System dimension |
| [in] | b | Right-hand side vector, length n |
| [out] | c | Solution vector, length n |
| [in] | nn | Leading dimension of a |
|
private |
Prune short branches from the constraint-set binary tree.
Frees all branches whose length is less than nbind by setting their up field to zero. This reclaims memory in the triply linked tree used by the Theil-Van de Panne procedure (§7.2), keeping only branches at the current search frontier.
On exit, merk points to the terminal node of the leftmost branch of length nbind, or is set to 1 if no such branch exists.
| [in] | maxtr | Size of the tree arrays |
| [in,out] | up | Parent pointers; freed nodes get up = 0 |
| [in] | left | Left-child pointers |
| [in] | right | Right-child pointers |
| [in] | nbind | Minimum branch length to retain |
| [out] | merk | Terminal node of the leftmost surviving branch, or 1 if none |
|
private |
Compute the discontinuity jumps of the B-spline derivatives.
Calculates the discontinuity jumps of the \( k \)-th derivative of the B-splines of degree \( k \) at the interior knots \( \lambda_{k+2}, \ldots, \lambda_{n-k-1} \). These coefficients \( a_{i,q} \) appear in the smoothness measure:
\[ a_{i,q} = \frac{(-1)^{k+1} \, k! \, (\lambda_{i+k+1} - \lambda_i)} {\displaystyle\prod_{\substack{j=q-k \\ j \neq i}}^{q} (\lambda_{q+1} - \lambda_{j+1})} \tag{5.6} \]
for \( q - k - 1 \leq i \leq q \), and zero otherwise. The output matrix \( B \) stores these values for use in evaluating the smoothing functional \( \sum_q [\sum_i c_i \, a_{i,q}]^2 \) (Eq. 5.5).
| [in] | t | Knot vector \( \lambda_1, \ldots, \lambda_n \) |
| [in] | n | Length of the knot vector |
| [in] | k2 | Spline order \( k + 1 \) (= degree + 1) |
| [out] | b | Discontinuity jump matrix, stored as b(nest, k2). Row \( q \) contains the \( k+1 \) non-zero jumps at interior knot \( \lambda_{q+k+1} \). |
| [in] | nest | Leading dimension of array b |
|
private |
Collect free nodes from the constraint-set binary tree.
Scans the triply linked tree for free nodes (those with up = 0, previously released by fpdeno) and makes them available for reuse. If no free nodes are found, the error flag ier is set to 1.
This routine is called by fpadno when the tree needs a new node but the count pointer has exhausted the pre-allocated array.
| [in] | maxtr | Size of the tree arrays |
| [in,out] | up | Parent pointers; up(i) = 0 marks a free node |
| [in,out] | left | Left-child pointers |
| [in,out] | right | Right-child pointers |
| [in,out] | info | Constraint index stored at each node |
| [in,out] | point | Pointer to the collected free-node chain |
| [in,out] | merk | Terminal node of the current branch |
| [in] | n1 | Maximum branch length |
| [out] | count | Number of free nodes found |
| [out] | ier | Error flag: 0 = success, 1 = no free nodes |
|
private |
Compute parameters of a Givens plane rotation.
Given a pivot element \( e_i \) and a diagonal element \( r_i \), computes the cosine \( c \) and sine \( s \) of a Givens rotation that eliminates \( e_i \):
\[ r'_i = \sqrt{r_i^2 + e_i^2}, \quad c = \frac{r_i}{r'_i}, \quad s = \frac{e_i}{r'_i} \tag{4.15} \]
The rotation preserves orthogonality ( \( c^2 + s^2 = 1 \)) and is used to triangularize the observation matrix \( E \) row by row during the QR decomposition of the least-squares system.
| [in] | piv | Pivot element \( e_i \) to be eliminated |
| [in,out] | ww | On entry, diagonal element \( r_i \). On exit, updated value \( r'_i = \sqrt{r_i^2 + e_i^2} \). |
| [out] | cos | Cosine of rotation angle |
| [out] | sin | Sine of rotation angle |
|
private |
Compute spline coefficients on a polar/spherical grid via Kronecker product.
Grid-based variant of the Kronecker product decomposition (Eq. 10.4-10.8) adapted for polar and spherical coordinates. Handles the periodic \( v \)-direction using two-matrix rotations (fp_rotate_2mat_stride) and incorporates origin/pole boundary conditions via the iop0/iop1 flags. The dz parameter provides prescribed values at \( u = 0 \) and/or \( u = 1 \).
Uses lback = .true. for back-substitution only (coefficients from a previous triangularization).
| [in,out] | ifsu | Flag: 0 = recompute \( S_{pu} \) |
| [in,out] | ifsv | Flag: 0 = recompute \( S_{pv} \) |
| [in,out] | ifbu | Flag: 0 = recompute \( B_u \) |
| [in,out] | ifbv | Flag: 0 = recompute \( B_v \) |
| [in] | lback | .true. = back-substitution only |
| [in] | u | Radial grid values, length mu |
| [in] | mu | Number of radial grid points |
| [in] | v | Angular grid values, length mv |
| [in] | mv | Number of angular grid points |
| [in] | z | Data values, length mz |
| [in] | mz | Length of z |
| [in] | dz | Boundary values at origin/edge |
| [in] | iop0 | Boundary condition at \( u = 0 \) |
| [in] | iop1 | Boundary condition at \( u = 1 \) |
| [in] | tu | Radial knot vector |
| [in] | nu | Number of radial knots |
| [in] | tv | Angular knot vector |
| [in] | nv | Number of angular knots |
| [out] | p | Smoothing parameter (output) |
| [in,out] | c | B-spline coefficients, length nc |
| [in] | nc | Length of c |
| [out] | sq | Sum of squared residuals |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | fpu | Residual sums per radial interval |
| [in,out] | fpv | Residual sums per angular interval |
| [in] | mm | Work dimension |
| [in] | mvnu | Work dimension |
| [in,out] | spu | Radial B-spline observation matrix |
| [in,out] | spv | Angular B-spline observation matrix |
| [in,out] | right | Work: RHS vector |
| [in,out] | q | Work: RHS matrix |
| [in,out] | au | Work: radial band matrix |
| [in,out] | av1 | Work: angular band matrix (main block) |
| [in,out] | av2 | Work: angular band matrix (periodic block) |
| [in,out] | bu | Work: radial discontinuity jumps |
| [in,out] | bv | Work: angular discontinuity jumps |
| [in,out] | aa | Work: boundary constraint matrix |
| [in,out] | bb | Work: boundary constraint matrix |
| [in,out] | cc | Work: boundary constraint matrix |
| [in,out] | cosi | Work: cosine integrals |
| [in,out] | nru | Work: radial knot interval indices |
| [in,out] | nrv | Work: angular knot interval indices |

|
private |
Compute parametric surface spline coefficients on a grid.
Grid-based Kronecker product decomposition (Eq. 10.9-10.12) for \( d \)-dimensional parametric surfaces. Computes the least-squares spline \( s_\infty(u,v) \) and the per-interval residual sums fpu(j) and fpv(j) needed for knot-placement decisions. Handles optional periodicity in \( u \) and/or \( v \) via the ipar flags, using two-matrix variants for periodic directions.
| [in,out] | ifsu | Flag: 0 = recompute \( S_{pu} \) |
| [in,out] | ifsv | Flag: 0 = recompute \( S_{pv} \) |
| [in,out] | ifbu | Flag: 0 = recompute \( B_u \) |
| [in,out] | ifbv | Flag: 0 = recompute \( B_v \) |
| [in] | idim | Number of surface dimensions \( d \) |
| [in] | ipar | Periodicity flags (packed) |
| [in] | u | \( u \)-grid values, length mu |
| [in] | mu | Number of \( u \)-grid points |
| [in] | v | \( v \)-grid values, length mv |
| [in] | mv | Number of \( v \)-grid points |
| [in] | z | Data values, length mz |
| [in] | mz | Length of z |
| [in] | tu | \( u \)-knot vector |
| [in] | nu | Number of \( u \)-knots |
| [in] | tv | \( v \)-knot vector |
| [in] | nv | Number of \( v \)-knots |
| [in] | p | Smoothing parameter |
| [in,out] | c | B-spline coefficients, length nc |
| [in] | nc | Length of c |
| [in,out] | fp | Total weighted sum of squared residuals |
| [in,out] | fpu | Residual sums per \( u \)-interval |
| [in,out] | fpv | Residual sums per \( v \)-interval |
| [in] | mm | Work dimension |
| [in] | mvnu | Work dimension |
| [in,out] | spu | \( u \)-B-spline observation matrix |
| [in,out] | spv | \( v \)-B-spline observation matrix |
| [in,out] | right | Work: RHS vector |
| [in,out] | q | Work: RHS matrix |
| [in,out] | au | Work: \( u \)-band matrix (main) |
| [in,out] | au1 | Work: \( u \)-band matrix (periodic) |
| [in,out] | av | Work: \( v \)-band matrix (main) |
| [in,out] | av1 | Work: \( v \)-band matrix (periodic) |
| [in,out] | bu | Work: \( u \)-discontinuity jumps |
| [in,out] | bv | Work: \( v \)-discontinuity jumps |
| [in,out] | nru | Work: \( u \)-knot interval indices |
| [in,out] | nrv | Work: \( v \)-knot interval indices |

|
private |
Compute grid-based spline coefficients via Kronecker product decomposition.
For data on a rectangular grid \( \{x_i\} \times \{y_j\} \), solves the smoothing least-squares system using the Kronecker product structure (Eq. 10.4-10.8):
\[ A_y \, C \, A_x^T = Q \tag{10.4} \]
where the augmented observation matrices are:
\[ A_x = \begin{pmatrix} S_{px} \\ \frac{1}{\sqrt{p}} B_x \end{pmatrix}, \quad A_y = \begin{pmatrix} S_{py} \\ \frac{1}{\sqrt{p}} B_y \end{pmatrix} \tag{10.5} \]
The \( x \)- and \( y \)-direction QR factorizations are performed independently using fp_rotate_row_stride (row-access RHS for \( A_y \)) and fp_rotate_row_block (column-access RHS for \( A_x \)), followed by back-substitution. Also computes residual sums fpx, fpy per knot interval for knot-placement decisions.
| [in,out] | ifsx | Flag: 0 = recompute \( S_{px} \) |
| [in,out] | ifsy | Flag: 0 = recompute \( S_{py} \) |
| [in,out] | ifbx | Flag: 0 = recompute \( B_x \) |
| [in,out] | ifby | Flag: 0 = recompute \( B_y \) |
| [in] | x | \( x \)-grid values, length mx |
| [in] | mx | Number of \( x \)-grid points |
| [in] | y | \( y \)-grid values, length my |
| [in] | my | Number of \( y \)-grid points |
| [in] | z | Data values on the grid, length mz |
| [in] | mz | Length of z ( \( = mx \cdot my \)) |
| [in] | kx | Degree in \( x \) |
| [in] | ky | Degree in \( y \) |
| [in] | tx | \( x \)-knot vector |
| [in] | nx | Number of \( x \)-knots |
| [in] | ty | \( y \)-knot vector |
| [in] | ny | Number of \( y \)-knots |
| [in] | p | Smoothing parameter |
| [in,out] | c | B-spline coefficients, length nc |
| [in] | nc | Length of c |
| [in,out] | fp | Total weighted sum of squared residuals |
| [in,out] | fpx | Residual sums per \( x \)-interval |
| [in,out] | fpy | Residual sums per \( y \)-interval |
| [in] | mm | Work dimension |
| [in] | mynx | Work dimension ( \( my \cdot (nx - kx - 1) \)) |
| [in] | kx1 | \( k_x + 1 \) |
| [in] | kx2 | \( k_x + 2 \) |
| [in] | ky1 | \( k_y + 1 \) |
| [in] | ky2 | \( k_y + 2 \) |
| [in,out] | spx | \( x \)-B-spline observation matrix |
| [in,out] | spy | \( y \)-B-spline observation matrix |
| [in,out] | right | Work: RHS vector for row rotations |
| [in,out] | q | Work: RHS matrix |
| [in,out] | ax | Work: \( x \)-band matrix |
| [in,out] | ay | Work: \( y \)-band matrix |
| [in,out] | bx | Work: \( x \)-discontinuity jumps |
| [in,out] | by | Work: \( y \)-discontinuity jumps |
| [in,out] | nrx | Work: \( x \)-knot interval indices |
| [in,out] | nry | Work: \( y \)-knot interval indices |

|
private |
Compute spherical grid spline coefficients via Kronecker product.
Spherical-coordinate variant of fpgrdi for data on a \( \theta \times \phi \) grid. Handles pole-continuity constraints at \( \theta = 0 \) and \( \theta = \pi \) via the iop0/iop1 flags, and the periodic \( \phi \)-direction using two-matrix rotations. The dr parameter provides prescribed pole values.
| [in,out] | ifsu | Flag: 0 = recompute \( S_{pu} \) |
| [in,out] | ifsv | Flag: 0 = recompute \( S_{pv} \) |
| [in,out] | ifbu | Flag: 0 = recompute \( B_u \) |
| [in,out] | ifbv | Flag: 0 = recompute \( B_v \) |
| [in] | lback | .true. = back-substitution only |
| [in] | u | Co-latitude grid values \( \theta \), length mu |
| [in] | mu | Number of \( \theta \)-grid points |
| [in] | v | Longitude grid values \( \phi \), length mv |
| [in] | mv | Number of \( \phi \)-grid points |
| [in] | r | Data values, length mr |
| [in] | mr | Length of r |
| [in] | dr | Pole boundary values |
| [in] | iop0 | Boundary condition at north pole ( \( \theta = 0 \)) |
| [in] | iop1 | Boundary condition at south pole ( \( \theta = \pi \)) |
| [in] | tu | \( \theta \)-knot vector |
| [in] | nu | Number of \( \theta \)-knots |
| [in] | tv | \( \phi \)-knot vector |
| [in] | nv | Number of \( \phi \)-knots |
| [in,out] | p | Smoothing parameter |
| [in,out] | c | B-spline coefficients, length nc |
| [in] | nc | Length of c |
| [in,out] | sq | Sum of squared residuals |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | fpu | Residual sums per \( \theta \)-interval |
| [in,out] | fpv | Residual sums per \( \phi \)-interval |
| [in] | mm | Work dimension |
| [in] | mvnu | Work dimension |
| [in,out] | spu | \( \theta \)-B-spline observation matrix |
| [in,out] | spv | \( \phi \)-B-spline observation matrix |
| [in,out] | right | Work: RHS vector |
| [in,out] | q | Work: RHS matrix |
| [in,out] | au | Work: \( \theta \)-band matrix |
| [in,out] | av1 | Work: \( \phi \)-band matrix (main) |
| [in,out] | av2 | Work: \( \phi \)-band matrix (periodic) |
| [in,out] | bu | Work: \( \theta \)-discontinuity jumps |
| [in,out] | bv | Work: \( \phi \)-discontinuity jumps |
| [in,out] | a0 | Work: north-pole constraint row |
| [in,out] | a1 | Work: south-pole constraint row |
| [in,out] | b0 | Work: north-pole smoothing row |
| [in,out] | b1 | Work: south-pole smoothing row |
| [in,out] | c0 | Work: north-pole cosine row |
| [in,out] | c1 | Work: south-pole cosine row |
| [in,out] | cosi | Work: cosine integrals |
| [in,out] | nru | Work: \( \theta \)-knot interval indices |
| [in,out] | nrv | Work: \( \phi \)-knot interval indices |

|
private |
Insert a single knot into a B-spline representation.
Given the B-spline representation \( (t, c) \) of a degree- \( k \) spline, computes the new knot vector \( t' \) and coefficients \( c' \) that represent the same spline after inserting one additional knot \( x \in [\lambda_l, \lambda_{l+1}) \). Uses the Boehm (1980) one-knot-at-a-time algorithm:
\[ d_i = r_i \, c_i + (1 - r_i) \, c_{i-1} \tag{1.47} \]
where each weight \( r_i \in [0, 1] \) is a convex combination factor:
\[ r_i = \frac{\tau_{j+1} - \tau_i}{\tau_{i+k+1} - \tau_i} \tag{1.48} \]
For periodic splines (iopt /= 0), the boundary coefficients are wrapped accordingly. At least one of \( l > 2k \) or \( l < n - 2k \) must hold.
| [in] | iopt | 0 = non-periodic spline, otherwise periodic |
| [in] | t | Input knot vector, length n |
| [in] | n | Number of input knots |
| [in] | c | Input B-spline coefficients, length n-k-1 |
| [in] | k | Spline degree |
| [in] | x | New knot to insert, \( \lambda_l \leq x < \lambda_{l+1} \) |
| [in] | l | Knot interval index where x is inserted |
| [out] | tt | Output knot vector, length nn |
| [out] | nn | Number of output knots ( \( n + 1 \)) |
| [out] | cc | Output B-spline coefficients, length nn-k-1 |
| [in] | nest | Leading dimension of arrays t, c, tt, cc |
|
private |
Compute definite integrals of the normalized B-splines.
Calculates the definite integrals of each of the \( n-k-1 \) normalized B-splines \( N_{j,k+1}(u) \) of degree \( k \) over the interval \( [x, y] \):
\[ \text{bint}(j) = \int_x^y N_{j,k+1}(u) \, du \]
Uses the Gaffney formula for indefinite integrals of B-splines, which exploits the identity (Eq. 1.42):
\[ \int_{\lambda_j}^{u} N_{j,k+1}(v) \, dv = \frac{\lambda_{j+k+1} - \lambda_j}{k+1} \sum_{i=j+1}^{g+k+1} N_{i,k+2}(u) \tag{1.42} \]
| [in] | t | Knot vector \( \lambda_1, \ldots, \lambda_n \) |
| [in] | n | Number of knots |
| [out] | bint | Array of length nk1; \( \text{bint}(j) = \int_x^y N_{j,k+1}(u)\,du \) |
| [in] | nk1 | Number of B-splines ( \( n - k - 1 \)) |
| [in] | x | Lower integration limit |
| [in] | y | Upper integration limit |

|
private |
Select and insert a new knot at the location of maximum residual.
Locates the knot interval \( [\lambda_j, \lambda_{j+1}] \) with the largest sum of squared residuals \( \delta_j \) (Eq. 5.43) and inserts a new knot at the midpoint of its interior data points. This is the greedy knot-placement strategy used by the iterative smoothing spline algorithm:
\[ \delta_j = \sideset{}{''}{\sum}_{r=u_j+1}^{u_j+m_j} \bigl( w_r (y_r - S_{g}(x_r)) \bigr)^2 \tag{5.43} \]
Only intervals with at least one interior data point ( \( m_j > 2 \)) are eligible. The new knot is placed at \( x_{u_j + \lceil m_j/2 \rceil + 1} \). After insertion, fpint and nrdata are split to reflect the two new sub-intervals.
| [in] | x | Data abscissae, length m |
| [in] | m | Number of data points |
| [in,out] | t | Knot vector; new knot inserted on exit |
| [in,out] | n | Number of knots; incremented by 1 on exit |
| [in,out] | fpint | Residual sum of squares per knot interval |
| [in,out] | nrdata | Number of interior data points per interval |
| [in,out] | nrint | Number of knot intervals; incremented by 1 |
| [in] | nest | Leading dimension of arrays t, fpint, nrdata |
| [in] | istart | Smallest eligible data index minus one |
|
private |
Compute smoothing spline on a polar grid with origin constraints.
Given data on a \( (u, v) \) grid (radial \( \times \) angular), determines the B-spline coefficients of a bicubic smoothing spline \( s_p(u,v) \) periodic in \( v \), satisfying origin-continuity constraints:
iopt(2) = 1)iopt(3) = 1)The unknown boundary parameters dz(i) (when not prescribed) are optimized to minimize the residual sum of squares, which is a quadratic function of dz. Delegates the grid QR factorization to fpgrdi.
| [in,out] | ifsu | Flag: 0 = recompute radial B-splines |
| [in,out] | ifsv | Flag: 0 = recompute angular B-splines |
| [in,out] | ifbu | Flag: 0 = recompute radial discontinuities |
| [in,out] | ifbv | Flag: 0 = recompute angular discontinuities |
| [in] | u | Radial grid values, length mu |
| [in] | mu | Number of radial points |
| [in] | v | Angular grid values, length mv |
| [in] | mv | Number of angular points |
| [in] | z | Data values, length mz |
| [in] | mz | Length of z |
| [in] | z0 | Value at origin (prescribed or initial guess) |
| [in,out] | dz | Boundary derivative parameters (3 values) |
| [in] | iopt | Constraint options (3 flags) |
| [in] | ider | Derivative specification flags |
| [in] | tu | Radial knot vector |
| [in] | nu | Number of radial knots |
| [in] | tv | Angular knot vector |
| [in] | nv | Number of angular knots |
| [in] | nuest | Max radial knots |
| [in] | nvest | Max angular knots |
| [in,out] | p | Smoothing parameter |
| [in] | step | Search step for boundary parameter optimization |
| [in,out] | c | B-spline coefficients, length nc |
| [in] | nc | Length of c |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | fpu | Residual sums per radial interval |
| [in,out] | fpv | Residual sums per angular interval |
| [in,out] | nru | Radial knot interval indices |
| [in,out] | nrv | Angular knot interval indices |
| [in,out] | wrk | Work array |
| [in] | lwrk | Length of wrk |

|
private |
Compute smoothing spline on a spherical grid with pole constraints.
Spherical counterpart of fpopdi. Given data on a \( (\theta, \phi) \) grid, determines a bicubic smoothing spline \( s_p(\theta,\phi) \) periodic in \( \phi \), satisfying pole-continuity constraints at both poles:
Unknown pole parameters dr(i) are optimized to minimize the residual. Delegates to fpgrsp for the grid QR factorization.
| [in,out] | ifsu | Flag: 0 = recompute \( \theta \)-B-splines |
| [in,out] | ifsv | Flag: 0 = recompute \( \phi \)-B-splines |
| [in,out] | ifbu | Flag: 0 = recompute \( \theta \)-discontinuities |
| [in,out] | ifbv | Flag: 0 = recompute \( \phi \)-discontinuities |
| [in] | u | Co-latitude grid \( \theta \), length mu |
| [in] | mu | Number of \( \theta \)-points |
| [in] | v | Longitude grid \( \phi \), length mv |
| [in] | mv | Number of \( \phi \)-points |
| [in] | r | Data values, length mr |
| [in] | mr | Length of r |
| [in] | r0 | North-pole value (prescribed or initial guess) |
| [in] | r1 | South-pole value (prescribed or initial guess) |
| [in,out] | dr | Pole derivative parameters (6 values) |
| [in] | iopt | Constraint options |
| [in] | ider | Derivative specification flags |
| [in] | tu | \( \theta \)-knot vector |
| [in] | nu | Number of \( \theta \)-knots |
| [in] | tv | \( \phi \)-knot vector |
| [in] | nv | Number of \( \phi \)-knots |
| [in] | nuest | Max \( \theta \)-knots |
| [in] | nvest | Max \( \phi \)-knots |
| [in,out] | p | Smoothing parameter |
| [in] | step | Search step for pole parameter optimization |
| [in,out] | c | B-spline coefficients, length nc |
| [in] | nc | Length of c |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | fpu | Residual sums per \( \theta \)-interval |
| [in,out] | fpv | Residual sums per \( \phi \)-interval |
| [in,out] | nru | \( \theta \)-knot interval indices |
| [in,out] | nrv | \( \phi \)-knot interval indices |
| [in,out] | wrk | Work array |
| [in] | lwrk | Length of wrk |

|
private |
Sort scattered data points into rectangular panels.
Assigns each data point \( (x_i, y_i) \), \( i = 1, \ldots, m \), to the rectangular panel \( R_{u,v} \) defined by \( \lambda_u^x \leq x < \lambda_{u+1}^x \) and \( \lambda_v^y \leq y < \lambda_{v+1}^y \).
For each panel, a linked-list stack is built:
index(j) points to the first data point in panel \( j \)nummer(i) gives the next data point in the same panelThis panel ordering enables efficient row-by-row construction of the observation matrix, since only the \( (k_x+1)(k_y+1) \) B-splines supported on a given panel contribute non-zero entries.
| [in] | x | Data abscissae, length m |
| [in] | y | Data ordinates, length m |
| [in] | m | Number of data points |
| [in] | kx | Spline degree in \( x \) |
| [in] | ky | Spline degree in \( y \) |
| [in] | tx | Knot vector in \( x \), length nx |
| [in] | nx | Number of knots in \( x \) |
| [in] | ty | Knot vector in \( y \), length ny |
| [in] | ny | Number of knots in \( y \) |
| [out] | nummer | Linked-list next pointers, length m |
| [out] | index | Panel head pointers, length nreg |
| [in] | nreg | Number of panels \( = (n_x - 2k_x - 1)(n_y - 2k_y - 1) \) |

|
private |
Core algorithm for open parametric curve fitting.
Fits a \( d \)-dimensional parametric spline curve \( s(u) = (s_1(u), \ldots, s_d(u)) \) of degree \( k \) on the parameter interval \( [u_b, u_e] \). All \( d \) coordinate curves share the same knot vector and are fitted simultaneously:
\[ \sum_{i=1}^{m} w_i^2 \sum_{j=1}^{d} (x_{i,j} - s_j(u_i))^2 \leq S \tag{6.9} \]
The algorithm follows the same three-level iteration as fpcurf (knot selection, QR factorization, smoothing-parameter search) but uses vector-RHS Givens rotations (fp_rotate_row_vec) to process all dimensions in a single pass.
| [in] | iopt | 0 = new fit, 1 = continue |
| [in] | idim | Number of curve dimensions \( d \) |
| [in] | m | Number of data points |
| [in] | u | Parameter values, length m |
| [in] | mx | Length of x ( \( = m \cdot d \)) |
| [in] | x | Data coordinates, interleaved, length mx |
| [in] | w | Data weights, length m |
| [in] | ub | Left boundary of parameter interval |
| [in] | ue | Right boundary of parameter interval |
| [in] | k | Spline degree |
| [in] | s | Smoothing factor \( S \geq 0 \) |
| [in] | nest | Max knots |
| [in] | tol | Tolerance for smoothing condition |
| [in] | maxit | Maximum smoothing-parameter iterations |
| [in] | k1 | \( k + 1 \) |
| [in] | k2 | \( k + 2 \) |
| [in,out] | n | Number of knots |
| [in,out] | t | Knot vector, length nest |
| [in,out] | nc | Length of coefficient array c |
| [in,out] | c | B-spline coefficients, length nc |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | fpint | Residual sums per knot interval |
| [in,out] | z | Work: transformed RHS |
| [in,out] | a | Work: band matrix |
| [in,out] | b | Work: smoothing matrix |
| [in,out] | g | Work: band matrix copy |
| [in,out] | q | Work: B-spline values |
| [in,out] | nrdata | Interior data-point counts |
| [in,out] | ier | Error flag |

|
private |
Core algorithm for parametric surface fitting on a grid.
Fits a \( d \)-dimensional parametric tensor-product spline surface \( s(u,v) = (s_1(u,v), \ldots, s_d(u,v)) \) to data on a rectangular grid \( \{u_i\} \times \{v_j\} \). Uses the Kronecker product decomposition (Eq. 10.9-10.12) that separates the bivariate problem into sequences of univariate operations:
\[ (A_u \otimes A_v) \, c = z \tag{10.9} \]
The \( u \)- and \( v \)-direction triangularizations are performed independently (via fp_rotate_row_block and fp_rotate_row_stride), followed by back-substitution.
| [in] | iopt | 0 = new fit, 1 = continue |
| [in] | ipar | Periodicity flags (packed) |
| [in] | idim | Number of surface dimensions \( d \) |
| [in] | u | \( u \)-grid values, length mu |
| [in] | mu | Number of \( u \)-grid points |
| [in] | v | \( v \)-grid values, length mv |
| [in] | mv | Number of \( v \)-grid points |
| [in] | z | Data values, length mz ( \( = mu \cdot mv \cdot d \)) |
| [in] | mz | Length of z |
| [in] | s | Smoothing factor \( S \geq 0 \) |
| [in] | nuest | Max \( u \)-knots |
| [in] | nvest | Max \( v \)-knots |
| [in] | tol | Smoothing condition tolerance |
| [in] | maxit | Maximum smoothing-parameter iterations |
| [in,out] | nc | Length of coefficient array |
| [in,out] | nu | Number of \( u \)-knots |
| [in,out] | tu | \( u \)-knot vector |
| [in,out] | nv | Number of \( v \)-knots |
| [in,out] | tv | \( v \)-knot vector |
| [in,out] | c | B-spline coefficients |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | fp0 | Initial residual sum |
| [in,out] | fpold | Previous residual sum |
| [in,out] | reducu | Residual reduction in \( u \) |
| [in,out] | reducv | Residual reduction in \( v \) |
| [in,out] | fpintu | Residual sums per \( u \)-interval |
| [in,out] | fpintv | Residual sums per \( v \)-interval |
| [in,out] | lastdi | Last direction of knot addition |
| [in,out] | nplusu | Number of \( u \)-knots to add |
| [in,out] | nplusv | Number of \( v \)-knots to add |
| [in,out] | nru | Work: \( u \)-knot interval indices |
| [in,out] | nrv | Work: \( v \)-knot interval indices |
| [in,out] | nrdatu | Interior data counts per \( u \)-interval |
| [in,out] | nrdatv | Interior data counts per \( v \)-interval |
| [in,out] | wrk | Work array |
| [in,out] | lwrk | Length of wrk |
| [in,out] | ier | Error flag |

|
private |
Core algorithm for univariate periodic spline fitting.
Fits a periodic spline \( s(x) \) of degree \( k \) where \( s^{(j)}(x_1) = s^{(j)}(x_m) \) for \( j = 0, \ldots, k-1 \). The periodicity reduces the number of free coefficients to \( n - 2k - 1 \) and wraps the B-spline columns into the block-triangular structure (Eq. 6.13) analogous to fpclos.
This is the scalar-valued counterpart of fpclos (which handles multi-dimensional parametric curves). Uses two-matrix Givens rotations (fp_rotate_row_2mat) for the periodic block structure.
| [in] | iopt | 0 = new fit, 1 = continue |
| [in] | x | Data abscissae, length m (strictly increasing) |
| [in] | y | Data ordinates, length m |
| [in] | w | Data weights, length m |
| [in] | m | Number of data points |
| [in] | k | Spline degree |
| [in] | s | Smoothing factor \( S \geq 0 \) |
| [in] | nest | Max knots |
| [in] | tol | Tolerance for smoothing condition |
| [in] | maxit | Maximum smoothing-parameter iterations |
| [in] | k1 | \( k + 1 \) |
| [in] | k2 | \( k + 2 \) |
| [in,out] | n | Number of knots |
| [in,out] | t | Knot vector, length nest |
| [in,out] | c | B-spline coefficients, length nest |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | fpint | Residual sums per knot interval |
| [in,out] | z | Work: transformed RHS |
| [in,out] | a1 | Work: band matrix \( R_{11}^* \) |
| [in,out] | a2 | Work: band matrix \( R_{12}^*/R_{22}^* \) |
| [in,out] | b | Work: smoothing matrix |
| [in,out] | g1 | Work: band matrix copy |
| [in,out] | g2 | Work: band matrix copy |
| [in,out] | q | Work: B-spline values |
| [in,out] | nrdata | Interior data-point counts |
| [in,out] | ier | Error flag |

|
private |
Set up the initial knot configuration for periodic spline interpolation.
When \( s = 0 \) (interpolation) and \( k \) is odd, places interior knots at the data abscissae. For \( k = 1 \) (linear), directly sets the B-spline coefficients from the data and returns the exact interpolant. When \( k \) is even, knots are placed at midpoints of consecutive abscissae.
| [in] | k | Spline degree |
| [in] | m | Number of data points |
| [in] | n | Number of knots |
| [in] | nest | Maximum knots allowed |
| [in,out] | kk | Adjusted degree for iteration |
| [in,out] | kk1 | Adjusted order for iteration |
| [in] | x | Data abscissae, length m |
| [in] | y | Data ordinates, length m |
| [in,out] | t | Knot vector, length nest |
| [in,out] | c | B-spline coefficients, length nest |
| [in,out] | fp | Weighted sum of squared residuals |
| [in] | per | Period \( = x_m - x_1 \) |
| [in] | fp0 | Upper bound for the smoothing factor |
| [in] | s | Smoothing factor |
| [in,out] | fpint | Knot interval contributions, length nest |
| [in,out] | nrdata | Data point counts per interval, length nest |
| [out] | done | .true. if the interpolant was fully determined |
|
private |
Construct a polynomial curve satisfying endpoint derivative constraints.
Finds a \( d \)-dimensional polynomial curve \( p(u) = (p_1(u), \ldots, p_d(u)) \) of degree \( k \) that satisfies prescribed derivative values at the endpoints \( a \) and \( b \):
\[ p_j^{(l)}(a) = \text{db}(d \cdot l + j), \quad l = 0, \ldots, i_b - 1 \]
\[ p_j^{(l)}(b) = \text{de}(d \cdot l + j), \quad l = 0, \ldots, i_e - 1 \]
The result is returned as B-spline coefficients cp(1:np) on the knot vector \( [a, \ldots, a, b, \ldots, b] \) (each with multiplicity \( k+1 \)). Used by concur to build an initial polynomial approximation for constrained parametric curves.
| [in] | idim | Number of curve dimensions \( d \) |
| [in] | k | Polynomial degree |
| [in] | a | Left endpoint |
| [in] | b | Right endpoint |
| [in] | ib | Number of derivative conditions at \( a \) |
| [in] | db | Derivative values at \( a \), length nb |
| [in] | nb | Length of db ( \( = d \cdot i_b \)) |
| [in] | ie | Number of derivative conditions at \( b \) |
| [in] | de | Derivative values at \( b \), length ne |
| [in] | ne | Length of de ( \( = d \cdot i_e \)) |
| [out] | cp | B-spline coefficients of the polynomial, length np |
| [in] | np | Length of cp ( \( = d \cdot (k+1) \)) |
|
private |
Driver for polar grid smoothing spline with knot selection.
Outer iteration loop for fitting a smoothing spline on a polar grid. Manages the knot-selection strategy (adding knots in the radial or angular direction based on residuals) and the smoothing-parameter search, delegating the actual grid computation to fpopdi at each step.
| [in] | iopt | Fitting options (3 flags) |
| [in] | ider | Derivative specification flags |
| [in] | u | Radial grid, length mu |
| [in] | mu | Number of radial points |
| [in] | v | Angular grid, length mv |
| [in] | mv | Number of angular points |
| [in] | z | Data values, length mz |
| [in] | mz | Length of z |
| [in] | z0 | Origin value |
| [in] | r | Boundary function values, length mv |
| [in] | s | Smoothing factor \( S \geq 0 \) |
| [in] | nuest | Max radial knots |
| [in] | nvest | Max angular knots |
| [in] | tol | Smoothing condition tolerance |
| [in] | maxit | Maximum smoothing-parameter iterations |
| [in] | nc | Length of coefficient array |
| [in,out] | nu | Number of radial knots |
| [in,out] | tu | Radial knot vector |
| [in,out] | nv | Number of angular knots |
| [in,out] | tv | Angular knot vector |
| [in,out] | c | B-spline coefficients |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | fp0 | Initial residual |
| [in,out] | fpold | Previous residual |
| [in,out] | reducu | Residual reduction in radial direction |
| [in,out] | reducv | Residual reduction in angular direction |
| [in,out] | fpintu | Residual sums per radial interval |
| [in,out] | fpintv | Residual sums per angular interval |
| [in,out] | dz | Boundary derivative parameters |
| [in] | step | Search step for boundary optimization |
| [in,out] | lastdi | Last direction of knot addition |
| [in,out] | nplusu | Number of radial knots to add |
| [in,out] | nplusv | Number of angular knots to add |
| [in,out] | lasttu | Last radial knot change flag |
| [in,out] | nru | Radial knot interval indices |
| [in,out] | nrv | Angular knot interval indices |
| [in,out] | nrdatu | Interior data counts per radial interval |
| [in,out] | nrdatv | Interior data counts per angular interval |
| [in,out] | wrk | Work array |
| [in] | lwrk | Length of wrk |
| [in,out] | ier | Error flag |

|
private |
Core algorithm for spline fitting on a polar domain.
Fits a smooth bivariate spline to data on a polar-like domain \( D = \{(x,y) : x^2 + y^2 \leq r(\theta)^2\} \) by transforming to coordinates \( (u, v) \) where \( u = r/r(\theta) \) (radial) and \( v = \theta \) (angular). The boundary function \( r(\theta) \) is user-supplied.
Continuity at the origin ( \( u = 0 \)) imposes constraints on the B-spline coefficients (Eq. 11.3-11.5):
The algorithm uses the same iterative scheme as fpsurf (knot placement, QR factorization with rank-deficiency handling, smoothing search) with additional logic for origin-continuity constraints and the periodic \( v \)-direction.
| [in] | iopt1 | Fitting option (0 = new, 1 = continue) |
| [in] | iopt2 | Origin BC option (0 = free, 1 = given) |
| [in] | iopt3 | Derivative BC option at origin |
| [in] | m | Number of data points |
| [in] | u | Radial coordinates, length m |
| [in] | v | Angular coordinates, length m |
| [in] | z | Data values, length m |
| [in] | w | Data weights, length m |
| [in] | rad | Boundary function values at data angles |
| [in] | s | Smoothing factor \( S \geq 0 \) |
| [in] | nuest | Max radial knots |
| [in] | nvest | Max angular knots |
| [in] | eta | Rank-deficiency tolerance factor |
| [in] | tol | Smoothing condition tolerance |
| [in] | maxit | Maximum smoothing-parameter iterations |
| [in] | ib1 | Bandwidth parameter |
| [in] | ib3 | Extended bandwidth parameter |
| [in] | nc | Length of coefficient array |
| [in] | ncc | Auxiliary coefficient dimension |
| [in] | intest | Length of fpint |
| [in] | nrest | Length of index |
| [in,out] | nu | Number of radial knots |
| [in,out] | tu | Radial knot vector |
| [in,out] | nv | Number of angular knots |
| [in,out] | tv | Angular knot vector |
| [in,out] | c | B-spline coefficients |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | sup | Upper bound for residual |
| [in,out] | fpint | Work: residual sums per panel |
| [in,out] | coord | Work: coordinates |
| [in,out] | f | Work: RHS vector |
| [in,out] | ff | Work: RHS copy |
| [in,out] | row | Work: observation row |
| [in,out] | cs | Work: cosine values |
| [in,out] | cosi | Work: cosine integrals |
| [in,out] | a | Work: band matrix |
| [in,out] | q | Work: extended band matrix |
| [in,out] | bu | Work: radial discontinuity coefficients |
| [in,out] | bv | Work: angular discontinuity coefficients |
| [in,out] | spu | Work: radial B-spline values |
| [in,out] | spv | Work: angular B-spline values |
| [in,out] | h | Work vector |
| [in,out] | index | Work: panel sorting indices |
| [in,out] | nummer | Work: data-to-panel mapping |
| [in,out] | wrk | Work array |
| [in] | lwrk | Length of wrk |
| [in,out] | ier | Error flag |

|
private |
Compute the minimum-norm least-squares solution under rank deficiency.
When the QR-triangularized observation matrix \( R \) has rank \( r < n \) (detected by near-zero diagonal elements \( |R_{ii}| < \varepsilon \)), the least-squares solution is not unique. This routine computes the minimum-norm B-spline coefficient vector \( \tilde{c} \) by factoring the reduced upper trapezoidal matrix \( W = [W_1 \ W_2] \) (Eq. 9.9):

|
private |
Rational interpolation for the smoothing parameter search.
Given three points \( (p_1, F_1) \), \( (p_2, F_2) \), \( (p_3, F_3) \) on the curve \( F(p) \), computes the zero of the rational interpolant:
\[ R(p) = \frac{u \, p + v}{p + w} \tag{5.30} \]
that passes through the three points. The zero \( \tilde{p} \) gives the next estimate of the smoothing parameter \( p \) satisfying \( F(p) = S \) during the iterative knot-placement strategy.
When \( p_3 = \infty \) (indicated by p3 <= 0), the formula simplifies to:
\[ \tilde{p} = \frac{p_1 (F_1 - F_3)(F_2 - S) - p_2 (F_2 - F_3)(F_1 - S)} {(F_1 - F_2)(F_3 - S)} \tag{5.31} \]
On exit, \( (p_1, F_1) \) and \( (p_3, F_3) \) are updated to bracket the root: \( F_1 > 0 \) and \( F_3 < 0 \).
| [in,out] | p1 | First abscissa; updated to maintain \( F_1 > 0 \) |
| [in,out] | f1 | First ordinate; updated with \( p_1 \) |
| [in] | p2 | Second abscissa (most recent iterate) |
| [in] | f2 | Second ordinate \( F(p_2) - S \) |
| [in,out] | p3 | Third abscissa; \( p_3 \leq 0 \) means \( p_3 = \infty \). Updated to maintain \( F_3 < 0 \). |
| [in,out] | f3 | Third ordinate; updated with \( p_3 \) |
| [out] | p | The new estimate \( \tilde{p} \) |
|
private |
Driver for rectangular grid smoothing surface with knot selection.
Outer iteration loop for fitting a smoothing spline surface on a rectangular grid \( \{x_i\} \times \{y_j\} \). Manages the knot selection strategy (alternating between \( x \) and \( y \) directions based on residuals) and the smoothing-parameter search, delegating the grid computation to fpgrre at each step.
| [in] | iopt | 0 = new fit, 1 = continue |
| [in,out] | x | \( x \)-grid values, length mx |
| [in] | mx | Number of \( x \)-grid points |
| [in,out] | y | \( y \)-grid values, length my |
| [in] | my | Number of \( y \)-grid points |
| [in] | z | Data values, length mz |
| [in] | mz | Length of z |
| [in] | xb | Left \( x \)-boundary |
| [in] | xe | Right \( x \)-boundary |
| [in] | yb | Lower \( y \)-boundary |
| [in] | ye | Upper \( y \)-boundary |
| [in] | kx | Degree in \( x \) |
| [in] | ky | Degree in \( y \) |
| [in] | s | Smoothing factor \( S \geq 0 \) |
| [in] | nxest | Max \( x \)-knots |
| [in] | nyest | Max \( y \)-knots |
| [in] | tol | Smoothing condition tolerance |
| [in] | maxit | Maximum smoothing-parameter iterations |
| [in] | nc | Length of coefficient array |
| [in,out] | nx | Number of \( x \)-knots |
| [in,out] | tx | \( x \)-knot vector |
| [in,out] | ny | Number of \( y \)-knots |
| [in,out] | ty | \( y \)-knot vector |
| [in,out] | c | B-spline coefficients |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | fp0 | Initial residual |
| [in,out] | fpold | Previous residual |
| [in,out] | reducx | Residual reduction in \( x \) |
| [in,out] | reducy | Residual reduction in \( y \) |
| [in,out] | fpintx | Residual sums per \( x \)-interval |
| [in,out] | fpinty | Residual sums per \( y \)-interval |
| [in,out] | lastdi | Last direction of knot addition |
| [in,out] | nplusx | Number of \( x \)-knots to add |
| [in,out] | nplusy | Number of \( y \)-knots to add |
| [in,out] | nrx | \( x \)-knot interval indices |
| [in,out] | nry | \( y \)-knot interval indices |
| [in,out] | nrdatx | Interior data counts per \( x \)-interval |
| [in,out] | nrdaty | Interior data counts per \( y \)-interval |
| [in,out] | wrk | Work array |
| [in] | lwrk | Length of wrk |
| [in,out] | ier | Error flag |

|
private |
Apply a Givens plane rotation to two scalars.
Given the cosine \( c \) and sine \( s \) of a Givens rotation (as computed by fpgivs), transforms a pair of values \( (a, b) \):
\[ a' = c \, a - s \, b, \qquad b' = s \, a + c \, b \tag{4.15} \]
This is used to propagate each Givens rotation through the remaining columns of the observation matrix and the right-hand side vector during QR factorization.
| [in] | cos | Cosine of the rotation angle |
| [in] | sin | Sine of the rotation angle |
| [in,out] | a | First element; replaced by \( c \, a - s \, b \) |
| [in,out] | b | Second element; replaced by \( s \, a + c \, b \) |
|
private |
Convert constrained polar spline coefficients to standard form.
Transforms the coefficients of a constrained bicubic spline (as computed by fppola with origin-continuity constraints) into the standard B-spline coefficient representation. The constrained form encodes the origin conditions via cosine-weighted combinations; this routine expands them into independent coefficients.
| [in] | nu | Number of radial knots |
| [in] | nv | Number of angular knots |
| [in] | if1 | Origin constraint type (position) |
| [in] | if2 | Origin constraint type (derivative) |
| [in] | cosi | Cosine integral values |
| [in] | ratio | Knot ratio for origin constraint |
| [in,out] | c | Constrained coefficients on entry; work on exit |
| [in,out] | f | Standard B-spline coefficients on exit |
| [in] | ncoff | Number of coefficients |
|
private |
Convert constrained spherical spline coefficients to standard form.
Transforms the coefficients of a constrained bicubic spline (as computed by fpsphe with pole-continuity constraints) into the standard B-spline coefficient representation. The constrained form encodes pole conditions via cosine/sine-weighted combinations at \( \theta = 0 \) and \( \theta = \pi \).
| [in] | nt | Number of \( \theta \)-knots |
| [in] | np | Number of \( \phi \)-knots |
| [in] | co | Cosine values for pole constraints |
| [in] | si | Sine values for pole constraints |
| [in,out] | c | Constrained coefficients on entry; work on exit |
| [in,out] | f | Standard B-spline coefficients on exit |
| [in] | ncoff | Number of coefficients |
|
private |
Fetch and advance to the next branch in the constraint-set tree.
Extracts the constraint indices of the branch ending at terminal node merk (length nbind) into the array ibind(1:nbind). Then advances merk to point to the next branch of the same length, or sets merk = 1 if no further branch exists.
Used by the Theil-Van de Panne procedure (§7.2) to enumerate candidate active-constraint sets level by level.
| [in] | maxtr | Size of the tree arrays |
| [in] | up | Parent pointers |
| [in] | left | Left-child pointers |
| [in] | right | Right-child pointers |
| [in] | info | Constraint index stored at each node |
| [in,out] | merk | On entry, terminal node of the branch to fetch. On exit, terminal node of the next branch of length nbind, or 1 if none. |
| [out] | ibind | Constraint indices of the fetched branch, length nbind |
| [in] | nbind | Required branch length |
|
private |
Driver for spherical grid smoothing spline with knot selection.
Outer iteration loop for fitting a smoothing spline on a spherical grid. Manages knot selection in \( \theta \) and \( \phi \) directions and the smoothing-parameter search, delegating grid computation to fpopsp. Handles pole constraints at both \( \theta = 0 \) and \( \theta = \pi \).
| [in] | iopt | Fitting options |
| [in] | ider | Derivative specification flags |
| [in] | u | Co-latitude grid \( \theta \), length mu |
| [in] | mu | Number of \( \theta \)-points |
| [in] | v | Longitude grid \( \phi \), length mv |
| [in] | mv | Number of \( \phi \)-points |
| [in] | r | Data values, length mr |
| [in] | mr | Length of r |
| [in] | r0 | North-pole value |
| [in] | r1 | South-pole value |
| [in] | s | Smoothing factor \( S \geq 0 \) |
| [in] | nuest | Max \( \theta \)-knots |
| [in] | nvest | Max \( \phi \)-knots |
| [in] | tol | Smoothing condition tolerance |
| [in] | maxit | Maximum smoothing-parameter iterations |
| [in] | nc | Length of coefficient array |
| [in,out] | nu | Number of \( \theta \)-knots |
| [in,out] | tu | \( \theta \)-knot vector |
| [in,out] | nv | Number of \( \phi \)-knots |
| [in,out] | tv | \( \phi \)-knot vector |
| [in,out] | c | B-spline coefficients |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | fp0 | Initial residual |
| [in,out] | fpold | Previous residual |
| [in,out] | reducu | Residual reduction in \( \theta \) |
| [in,out] | reducv | Residual reduction in \( \phi \) |
| [in,out] | fpintu | Residual sums per \( \theta \)-interval |
| [in,out] | fpintv | Residual sums per \( \phi \)-interval |
| [in,out] | dr | Pole derivative parameters |
| [in] | step | Search step for pole parameter optimization |
| [in,out] | lastdi | Last direction of knot addition |
| [in,out] | nplusu | Number of \( \theta \)-knots to add |
| [in,out] | nplusv | Number of \( \phi \)-knots to add |
| [in,out] | lastu0 | Last north-pole knot change flag |
| [in,out] | lastu1 | Last south-pole knot change flag |
| [in,out] | nru | \( \theta \)-knot interval indices |
| [in,out] | nrv | \( \phi \)-knot interval indices |
| [in,out] | nrdatu | Interior data counts per \( \theta \)-interval |
| [in,out] | nrdatv | Interior data counts per \( \phi \)-interval |
| [in,out] | wrk | Work array |
| [in] | lwrk | Length of wrk |
| [in,out] | ier | Error flag |

|
private |
Core algorithm for spline fitting on the sphere.
Fits a smooth bivariate spline to data on the unit sphere using coordinates \( (\theta, \phi) \) where \( \theta \in [0, \pi] \) is co-latitude and \( \phi \in [0, 2\pi) \) is longitude. The spline is periodic in \( \phi \) and must satisfy pole-continuity conditions at \( \theta = 0 \) and \( \theta = \pi \) (Eq. 11.12):
\[ s(0, \phi) = \text{const}, \quad s(\pi, \phi) = \text{const} \tag{11.12} \]
with derivative conditions analogous to the polar case (Eq. 11.14-11.16). The algorithm follows the same iterative framework as fpsurf with additional handling for pole constraints and the periodic \( \phi \)-direction.
| [in] | iopt | 0 = new fit, 1 = continue |
| [in] | m | Number of data points |
| [in] | teta | Co-latitude values \( \theta \), length m |
| [in] | phi | Longitude values \( \phi \), length m |
| [in] | r | Data values, length m |
| [in] | w | Data weights, length m |
| [in] | s | Smoothing factor \( S \geq 0 \) |
| [in] | ntest | Max \( \theta \)-knots |
| [in] | npest | Max \( \phi \)-knots |
| [in] | eta | Rank-deficiency tolerance factor |
| [in] | tol | Smoothing condition tolerance |
| [in] | maxit | Maximum smoothing-parameter iterations |
| [in] | ib1 | Bandwidth parameter |
| [in] | ib3 | Extended bandwidth parameter |
| [in] | nc | Length of coefficient array |
| [in] | ncc | Auxiliary coefficient dimension |
| [in] | intest | Length of fpint |
| [in] | nrest | Length of index |
| [in,out] | nt | Number of \( \theta \)-knots |
| [in,out] | tt | \( \theta \)-knot vector |
| [in,out] | np | Number of \( \phi \)-knots |
| [in,out] | tp | \( \phi \)-knot vector |
| [in,out] | c | B-spline coefficients |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | sup | Upper bound for residual |
| [in,out] | fpint | Work: residual sums per panel |
| [in,out] | coord | Work: coordinates |
| [in,out] | f | Work: RHS vector |
| [in,out] | ff | Work: RHS copy |
| [in,out] | row | Work: observation row |
| [in,out] | coco | Work: cosine values for pole constraints |
| [in,out] | cosi | Work: cosine integrals for pole constraints |
| [in,out] | a | Work: band matrix |
| [in,out] | q | Work: extended band matrix |
| [in,out] | bt | Work: \( \theta \)-discontinuity coefficients |
| [in,out] | bp | Work: \( \phi \)-discontinuity coefficients |
| [in,out] | spt | Work: \( \theta \)-B-spline values |
| [in,out] | spp | Work: \( \phi \)-B-spline values |
| [in,out] | h | Work vector |
| [in,out] | index | Work: panel sorting indices |
| [in,out] | nummer | Work: data-to-panel mapping |
| [in,out] | wrk | Work array |
| [in] | lwrk | Length of wrk |
| [out] | ier | Error flag |

|
private |
Evaluate a parametric bicubic tensor-product spline surface.
Computes the values of a \( d \)-dimensional bicubic spline surface \( (s_1(u,v), \ldots, s_d(u,v)) \) at the grid points \( (u_i, v_j) \), \( i = 1, \ldots, m_u \), \( j = 1, \ldots, m_v \).
For each dimension, the evaluation uses the tensor-product decomposition:
\[ s(u, v) = \sum_{i} \left( \sum_{j} c_{i,j} \, M_{j,4}(v) \right) N_{i,4}(u) \]
This is the computational core called by surev after input validation.
| [in] | idim | Number of coordinate dimensions |
| [in] | tu | Knot vector in \( u \), length nu |
| [in] | nu | Number of knots in \( u \) |
| [in] | tv | Knot vector in \( v \), length nv |
| [in] | nv | Number of knots in \( v \) |
| [in] | c | B-spline coefficients, length (nu-4)*(nv-4)*idim |
| [in] | u | Evaluation points in \( u \), length mu |
| [in] | mu | Number of evaluation points in \( u \) |
| [in] | v | Evaluation points in \( v \), length mv |
| [in] | mv | Number of evaluation points in \( v \) |
| [out] | f | Surface values, length mu * mv * idim |
| [out] | wu | B-spline basis values in \( u \), wu(mu, 4) |
| [out] | wv | B-spline basis values in \( v \), wv(mv, 4) |
| [out] | lu | Knot interval indices in \( u \), length mu |
| [out] | lv | Knot interval indices in \( v \), length mv |

|
private |
Core algorithm for bivariate tensor-product spline surface fitting.
Fits a tensor-product spline surface \( s(x,y) \) of degrees \( k_x \) and \( k_y \) to scattered data by minimizing:
\[ \sum_{i=1}^{m} \bigl( w_i (z_i - s(x_i, y_i)) \bigr)^2 \leq S \tag{9.2} \]
The B-spline representation has \( (g+k_x+1)(h+k_y+1) \) coefficients on the knot grid \( \{t_x\} \times \{t_y\} \). The algorithm iterates:
Data points are sorted into knot-interval panels using fporde for efficient row-by-row processing.
| [in] | iopt | 0 = new fit, 1 = continue |
| [in] | m | Number of data points |
| [in,out] | x | Data \( x \)-coordinates, length m |
| [in,out] | y | Data \( y \)-coordinates, length m |
| [in] | z | Data values, length m |
| [in] | w | Data weights, length m |
| [in] | xb | Left \( x \)-boundary |
| [in] | xe | Right \( x \)-boundary |
| [in] | yb | Lower \( y \)-boundary |
| [in] | ye | Upper \( y \)-boundary |
| [in] | kxx | Degree in \( x \) |
| [in] | kyy | Degree in \( y \) |
| [in] | s | Smoothing factor \( S \geq 0 \) |
| [in] | nxest | Max knots in \( x \) |
| [in] | nyest | Max knots in \( y \) |
| [in] | eta | Rank-deficiency tolerance factor |
| [in] | tol | Smoothing condition tolerance |
| [in] | maxit | Maximum smoothing-parameter iterations |
| [in] | nmax | Max of nxest, nyest |
| [in] | km1 | \( \max(k_x, k_y) + 1 \) |
| [in] | km2 | \( k_x + k_y + 2 \) |
| [in] | ib1 | \( k_x k_y + 2 \) |
| [in] | ib3 | \( k_x k_y + \max(k_x, k_y) + 2 \) |
| [in] | nc | Length of coefficient array |
| [in] | intest | Length of fpint |
| [in] | nrest | Length of index |
| [in,out] | nx0 | Number of \( x \)-knots |
| [in,out] | tx | \( x \)-knot vector |
| [in,out] | ny0 | Number of \( y \)-knots |
| [in,out] | ty | \( y \)-knot vector |
| [in,out] | c | B-spline coefficients |
| [in,out] | fp | Weighted sum of squared residuals |
| [in,out] | fp0 | Initial unweighted residual sum |
| [in,out] | fpint | Work: residual sums per panel |
| [in,out] | coord | Work: coordinates |
| [in,out] | f | Work: RHS vector |
| [in,out] | ff | Work: RHS copy |
| [in,out] | a | Work: band matrix |
| [in,out] | q | Work: extended band matrix |
| [in,out] | bx | Work: \( x \)-discontinuity coefficients |
| [in,out] | by | Work: \( y \)-discontinuity coefficients |
| [in,out] | spx | Work: \( x \)-B-spline values |
| [in,out] | spy | Work: \( y \)-B-spline values |
| [in,out] | h | Work vector |
| [in,out] | index | Work: panel sorting indices |
| [in,out] | nummer | Work: data-to-panel mapping |
| [in,out] | wrk | Work array |
| [in] | lwrk | Length of wrk |
| [in,out] | ier | Error flag |

|
private |
Solve a small symmetric linear system by Cholesky factorization.
Solves the \( n \times n \) symmetric positive definite system \( A \, b = g \) with \( n \leq 6 \) using Cholesky decomposition. On exit, g contains the solution \( b \).
Used by fpopdi and fpopsp for the small optimization problems that determine the optimal origin/pole boundary parameters.
| [in,out] | a | Symmetric matrix, dimension (6, 6). Only the first n rows and columns are used. |
| [in] | n | System dimension ( \( n \leq 6 \)) |
| [in,out] | g | On entry, right-hand side. On exit, solution. |
|
private |
Triangularize the tensor-product system for non-periodic grids.
Reduces the \( (m + n - 7) \times (n - 4) \) augmented observation matrix to upper triangular form using Givens rotations (Eq. 10.8), simultaneously transforming the \( m \times mm \times d \) data matrix \( Z \) into the \( (n-4) \times mm \times d \) RHS matrix \( Q \). Used in the second phase of the Kronecker product decomposition for parametric grid surfaces (fppasu via fpgrpa).
| [in] | m | Number of grid points in this direction |
| [in] | mm | Number of columns in the RHS (other direction size) |
| [in] | idim | Number of surface dimensions \( d \) |
| [in] | n | Number of knots in this direction |
| [in] | nr | Knot interval indices, length m |
| [in] | sp | B-spline values at grid points, (m, 4) |
| [in] | p | Smoothing parameter |
| [in] | b | Discontinuity jump matrix, (n, 5) |
| [in] | z | Data matrix, length \( m \cdot mm \cdot d \) |
| [out] | a | Triangularized band matrix, (n, 5) |
| [out] | q | Transformed RHS, length \( (n-4) \cdot mm \cdot d \) |
| [out] | right | Work: RHS row vector, length \( mm \cdot d \) |

|
private |
Triangularize the tensor-product system for periodic grids.
Periodic variant of fptrnp. Reduces the \( (m + n - 7) \times (n - 7) \) cyclic band matrix to upper triangular form using two-matrix Givens rotations (fp_rotate_2mat_stride), simultaneously transforming the data matrix \( Z \) into the RHS matrix \( Q \). The periodicity wraps the last columns into the first, creating the block-triangular structure stored in a (main) and aa (periodic block).
| [in] | m | Number of grid points in this direction |
| [in] | mm | Number of columns in the RHS |
| [in] | idim | Number of surface dimensions \( d \) |
| [in] | n | Number of knots in this direction |
| [in] | nr | Knot interval indices, length m |
| [in] | sp | B-spline values at grid points, (m, 4) |
| [in] | p | Smoothing parameter |
| [in] | b | Discontinuity jump matrix, (n, 5) |
| [in] | z | Data matrix, length \( m \cdot mm \cdot d \) |
| [out] | a | Triangularized band matrix (main block), (n, 5) |
| [out] | aa | Triangularized periodic block, (n, 4) |
| [out] | q | Transformed RHS, length \( (n-7) \cdot mm \cdot d \) |
| [out] | right | Work: RHS row vector, length \( mm \cdot d \) |

| subroutine, public fitpack_core::get_smoothing | ( | real(fp_real), intent(in) | old_smoothing, |
| real(fp_real), intent(in), optional | user_smoothing, | ||
| integer(fp_size), intent(out) | nit, | ||
| real(fp_real), dimension(3), intent(out) | smooth_now ) |
Choose the smoothing parameter(s) for an iterative fit.
Selects one or more values of the smoothing factor \( s \) for the next fitting iteration(s). If a user-supplied value is present it is used directly; if a previous value exists it is re-used; otherwise a default decreasing trajectory is applied.
| [in] | old_smoothing | Previous smoothing factor. |
| [in] | user_smoothing | Optional user-supplied value. |
| [out] | nit | Number of smoothing iterations to perform. |
| [out] | smooth_now | Array of 3 smoothing values for the iterations. |
| pure subroutine, public fitpack_core::insert | ( | integer(fp_size), intent(in) | iopt, |
| real(fp_real), dimension(nest), intent(in) | t, | ||
| integer(fp_size), intent(in) | n, | ||
| real(fp_real), dimension(nest), intent(in) | c, | ||
| integer(fp_size), intent(in) | k, | ||
| real(fp_real), intent(in) | x, | ||
| real(fp_real), dimension(nest), intent(out) | tt, | ||
| integer(fp_size), intent(out) | nn, | ||
| real(fp_real), dimension(nest), intent(out) | cc, | ||
| integer(fp_size), intent(in) | nest, | ||
| integer(fp_flag), intent(out) | ier ) |
Insert a single knot into a spline, returning a new B-spline representation.
Inserts the knot \( x \) into the B-spline representation of \( s(x) \) using the Boehm knot insertion algorithm. The spline itself is unchanged; only its representation (knots and coefficients) is updated.
Can be called with output arrays aliased to input arrays to replace the representation in place: call insert(iopt,t,n,c,k,x,t,n,c,nest,ier).
| [in] | iopt | Periodicity flag: 0 = non-periodic; /=0 = periodic spline. |
| [in] | t | Input knot positions (length nest). |
| [in] | n | Number of knots before insertion. |
| [in] | c | Input B-spline coefficients (length nest). |
| [in] | k | Degree of the spline. |
| [in] | x | Location of the knot to insert. Must satisfy \( t_{k+1} \le x \le t_{n-k} \). |
| [out] | tt | Output knot positions (length nest). |
| [out] | nn | Number of knots after insertion ( \( n + 1 \)). |
| [out] | cc | Output B-spline coefficients (length nest). |
| [in] | nest | Array dimension. Must satisfy nest > n. |
| [out] | ier | Error flag: 0 = normal return; 10 = invalid input. |

| pure subroutine, public fitpack_core::insert_inplace | ( | integer(fp_size), intent(in) | iopt, |
| real(fp_real), dimension(nest), intent(inout) | t, | ||
| integer(fp_size), intent(inout) | n, | ||
| real(fp_real), dimension(nest), intent(inout) | c, | ||
| integer(fp_size), intent(in) | k, | ||
| real(fp_real), intent(in) | x, | ||
| integer(fp_size), intent(in) | nest, | ||
| integer(fp_flag), intent(out) | ier ) |
Insert a single knot into a spline in place (avoiding aliasing issues).
Wrapper around insert that uses temporary arrays to safely update the knot and coefficient arrays in place, avoiding the aliasing of input/output arguments present in the original Fortran 77 calling convention.
| [in] | iopt | Periodicity flag: 0 = non-periodic; /=0 = periodic. |
| [in,out] | t | Knot positions (length nest). Updated on exit. |
| [in,out] | n | Number of knots. Updated to \( n + 1 \) on exit. |
| [in,out] | c | B-spline coefficients (length nest). Updated on exit. |
| [in] | k | Degree of the spline. |
| [in] | x | Location of the knot to insert. |
| [in] | nest | Array dimension. Must satisfy nest > n. |
| [out] | ier | Error flag: 0 = normal return; 10 = invalid input. |

| pure character(len=:) function, allocatable, public fitpack_core::iopt_message | ( | integer(fp_flag), intent(in) | iopt | ) |
Convert an iopt computation-mode flag to a human-readable string.
| [in] | iopt | Computation mode flag (-1 = Least-Squares, 0 = Smoothing, 1 = Old). |
|
private |
Test \( a > b \) (strict greater-than).

|
private |
Test \( a < b \) (strict less-than).

|
private |
Test \( a \ge b \).

|
private |
Test \( a \le b \).

|
private |
Choose which dimension receives the next knot during bivariate fitting.
Selects whether to add a knot in dimension 1 or 2, balancing knot insertion across dimensions. Prefers dimension 2 when it has fewer added knots, unless dimension 1 is at its maximum or no knot has been added yet.
| [in] | n1 | Current number of knots in dimension 1 |
| [in] | n1add | Number of knots added to dimension 1 this iteration |
| [in] | n1max | Maximum allowed knots in dimension 1 |
| [in] | n2 | Current number of knots in dimension 2 |
| [in] | n2add | Number of knots added to dimension 2 this iteration |
| [in] | n2max | Maximum allowed knots in dimension 2 |
| [in] | last | Last dimension a knot was added to (KNOT_DIM_1, KNOT_DIM_2, or KNOT_DIM_NONE) |
KNOT_DIM_1 or KNOT_DIM_2
|
private |
Test whether two reals differ beyond machine precision.

| pure subroutine, public fitpack_core::parcur | ( | integer(fp_size), intent(in) | iopt, |
| integer(fp_size), intent(in) | ipar, | ||
| integer(fp_size), intent(in) | idim, | ||
| integer(fp_size), intent(in) | m, | ||
| real(fp_real), dimension(m), intent(inout) | u, | ||
| integer(fp_size), intent(in) | mx, | ||
| real(fp_real), dimension(idim,m), intent(in) | x, | ||
| real(fp_real), dimension(m), intent(inout) | w, | ||
| real(fp_real), intent(inout) | ub, | ||
| real(fp_real), intent(inout) | ue, | ||
| integer(fp_size), intent(in) | k, | ||
| real(fp_real), intent(inout) | s, | ||
| integer(fp_size), intent(in) | nest, | ||
| integer(fp_size), intent(inout) | n, | ||
| real(fp_real), dimension(nest), intent(inout) | t, | ||
| integer(fp_size), intent(in) | nc, | ||
| real(fp_real), dimension(nc), intent(inout) | c, | ||
| real(fp_real), intent(out) | fp, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(nest), intent(inout) | iwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Determine a smooth parametric spline curve approximation.
Given \( m \) ordered points \( \mathbf{x}_i \in \mathbb{R}^{\text{idim}} \) with weights \( w_i > 0 \) and parameter values \( u_i \), computes an open parametric spline curve \( \mathbf{s}(u) = (s_1(u),\ldots,s_{\text{idim}}(u)) \) of degree \( k \) on \( [u_b, u_e] \).
If ipar=0, parameter values are computed automatically from cumulative chord lengths: \( u_i = v_i / v_m \) where \( v_i = v_{i-1} + \|\mathbf{x}_i - \mathbf{x}_{i-1}\| \), with \( u_b = 0 \) and \( u_e = 1 \).
Smoothness is controlled by requiring \( F(p) = \sum w_i^2 \|\mathbf{x}_i - \mathbf{s}(u_i)\|^2 \le S \).
| [in] | iopt | Computation mode: -1 (LSQ), 0 (new smoothing), 1 (continue). |
| [in] | ipar | Parameter mode: 0 = automatic, 1 = user-supplied. |
| [in] | idim | Dimension of the curve, \( 1 \le \text{idim} \le 10 \). |
| [in] | m | Number of data points, \( m > k \). |
| [in,out] | u | Parameter values (length \( m \)). Output when ipar=0. |
| [in] | mx | Declared dimension of x, \( \ge \text{idim} \times m \). |
| [in] | x | Data coordinates (length mx): x(idim*(i-1)+j) = \( j \)-th coordinate of point \( i \). |
| [in,out] | w | Weights (length \( m \)), strictly positive. |
| [in,out] | ub | Lower parameter bound. Set to 0 when ipar=0. |
| [in,out] | ue | Upper parameter bound. Set to 1 when ipar=0. |
| [in] | k | Spline degree, \( 1 \le k \le 5 \). Cubic recommended. |
| [in,out] | s | Smoothing factor \( S \ge 0 \). |
| [in] | nest | Over-estimate of total knots. nest=m+k+1 always suffices. |
| [in,out] | n | Total number of knots. |
| [in,out] | t | Knot positions (length nest). |
| [in] | nc | Declared dimension of c, \( \ge \text{nest} \times \text{idim} \). |
| [in,out] | c | B-spline coefficients (length nc). |
| [out] | fp | Weighted sum of squared residuals. |
| [in,out] | wrk | Real workspace, length \( \ge m(k+1) + \text{nest}(6+\text{idim}+3k) \). |
| [in] | lwrk | Declared dimension of wrk. |
| [in,out] | iwrk | Integer workspace (length nest). |
| [out] | ier | Error flag (same codes as curfit). |

| pure subroutine, public fitpack_core::parder | ( | real(fp_real), dimension(nx), intent(in) | tx, |
| integer(fp_size), intent(in) | nx, | ||
| real(fp_real), dimension(ny), intent(in) | ty, | ||
| integer(fp_size), intent(in) | ny, | ||
| real(fp_real), dimension((nx-kx-1)*(ny-ky-1)), intent(in) | c, | ||
| integer(fp_size), intent(in) | kx, | ||
| integer(fp_size), intent(in) | ky, | ||
| integer(fp_size), intent(in) | nux, | ||
| integer(fp_size), intent(in) | nuy, | ||
| real(fp_real), dimension(mx), intent(in) | x, | ||
| integer(fp_size), intent(in) | mx, | ||
| real(fp_real), dimension(my), intent(in) | y, | ||
| integer(fp_size), intent(in) | my, | ||
| real(fp_real), dimension(mx*my), intent(out) | z, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(kwrk), intent(inout) | iwrk, | ||
| integer(fp_size), intent(in) | kwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Evaluate a partial derivative of a bivariate spline on a rectangular grid.
Computes the partial derivative \( \frac{\partial^{\nu_x+\nu_y}}{\partial x^{\nu_x}\,\partial y^{\nu_y}} s(x,y) \) of a bivariate spline of degrees \( k_x \) and \( k_y \) on the grid \( (x_i, y_j) \), \( i=1,\ldots,m_x;\ j=1,\ldots,m_y \).

| pure subroutine, public fitpack_core::pardeu | ( | real(fp_real), dimension(nx), intent(in) | tx, |
| integer(fp_size), intent(in) | nx, | ||
| real(fp_real), dimension(ny), intent(in) | ty, | ||
| integer(fp_size), intent(in) | ny, | ||
| real(fp_real), dimension((nx-kx-1)*(ny-ky-1)), intent(in) | c, | ||
| integer(fp_size), intent(in) | kx, | ||
| integer(fp_size), intent(in) | ky, | ||
| integer(fp_size), intent(in) | nux, | ||
| integer(fp_size), intent(in) | nuy, | ||
| real(fp_real), dimension(m), intent(in) | x, | ||
| real(fp_real), dimension(m), intent(in) | y, | ||
| real(fp_real), dimension(m), intent(out) | z, | ||
| integer(fp_size), intent(in) | m, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(kwrk), intent(inout) | iwrk, | ||
| integer(fp_size), intent(in) | kwrk, | ||
| integer(fp_size), intent(out) | ier ) |
Evaluate a partial derivative of a bivariate spline at scattered points.
Computes \( \frac{\partial^{\nu_x+\nu_y}}{\partial x^{\nu_x}\,\partial y^{\nu_y}} s(x_i,y_i) \) for \( i=1,\ldots,m \) at arbitrary (unstructured) points. This is the scattered-point counterpart of parder, which evaluates on a rectangular grid.
| [in] | tx | Knot positions in \( x \)-direction (length \( n_x \)). |
| [in] | nx | Total number of knots in \( x \). |
| [in] | ty | Knot positions in \( y \)-direction (length \( n_y \)). |
| [in] | ny | Total number of knots in \( y \). |
| [in] | c | B-spline coefficients, length \( (n_x{-}k_x{-}1)(n_y{-}k_y{-}1) \). |
| [in] | kx | Degree in \( x \). |
| [in] | ky | Degree in \( y \). |
| [in] | nux | Derivative order in \( x \), \( 0 \le \nu_x < k_x \). |
| [in] | nuy | Derivative order in \( y \), \( 0 \le \nu_y < k_y \). |
| [in] | x | \( x \)-coordinates of evaluation points (length \( m \)). |
| [in] | y | \( y \)-coordinates of evaluation points (length \( m \)). |
| [out] | z | Derivative values (length \( m \)). |
| [in] | m | Number of evaluation points, \( m \ge 1 \). |
| [in,out] | wrk | Real workspace, length \( \ge m(k_x{+}1{-}\nu_x) + m(k_y{+}1{-}\nu_y) + (n_x{-}k_x{-}1)(n_y{-}k_y{-}1) \). |
| [in] | lwrk | Declared dimension of wrk. |
| [in,out] | iwrk | Integer workspace (length \( \ge 2m \)). |
| [in] | kwrk | Declared dimension of iwrk. |
| [out] | ier | Error flag: 0 = normal return; 10 = invalid input. |

| pure subroutine, public fitpack_core::pardtc | ( | real(fp_real), dimension(nx), intent(in) | tx, |
| integer(fp_size), intent(in) | nx, | ||
| real(fp_real), dimension(ny), intent(in) | ty, | ||
| integer(fp_size), intent(in) | ny, | ||
| real(fp_real), dimension((nx-kx-1)*(ny-ky-1)), intent(in) | c, | ||
| integer(fp_size), intent(in) | kx, | ||
| integer(fp_size), intent(in) | ky, | ||
| integer(fp_size), intent(in) | nux, | ||
| integer(fp_size), intent(in) | nuy, | ||
| real(fp_real), dimension((nx-kx-1)*(ny-ky-1)), intent(out) | newc, | ||
| integer(fp_flag), intent(out) | ier ) |
Transform B-spline coefficients to obtain the partial derivative spline.
Given a bivariate spline \( s(x,y) \) of degrees \( k_x, k_y \), computes the B-spline coefficients of the derivative spline \( \frac{\partial^{\nu_x+\nu_y}}{\partial x^{\nu_x}\,\partial y^{\nu_y}} s(x,y) \) of degrees \( k_x - \nu_x, k_y - \nu_y \).
Unlike parder / pardeu, this routine does not evaluate the derivative at any point; it only transforms the coefficient array. The resulting spline can then be evaluated with bispev or bispeu.
| [in] | tx | Knot positions in \( x \)-direction (length \( n_x \)). |
| [in] | nx | Total number of knots in \( x \). |
| [in] | ty | Knot positions in \( y \)-direction (length \( n_y \)). |
| [in] | ny | Total number of knots in \( y \). |
| [in] | c | B-spline coefficients, length \( (n_x{-}k_x{-}1)(n_y{-}k_y{-}1) \). |
| [in] | kx | Degree in \( x \). |
| [in] | ky | Degree in \( y \). |
| [in] | nux | Derivative order in \( x \), \( 0 \le \nu_x < k_x \). |
| [in] | nuy | Derivative order in \( y \), \( 0 \le \nu_y < k_y \). |
| [out] | newc | Derivative-spline coefficients, dimension \( (n_x{-}\nu_x{-}k_x{-}1)(n_y{-}\nu_y{-}k_y{-}1) \). |
| [out] | ier | Error flag: 0 = normal return; 10 = invalid input. |
| pure subroutine, public fitpack_core::parsur | ( | integer(fp_size), intent(in) | iopt, |
| integer(fp_size), dimension(2), intent(in) | ipar, | ||
| integer(fp_size), intent(in) | idim, | ||
| integer(fp_size), intent(in) | mu, | ||
| real(fp_real), dimension(mu), intent(in) | u, | ||
| integer(fp_size), intent(in) | mv, | ||
| real(fp_real), dimension(mv), intent(in) | v, | ||
| real(fp_real), dimension(mu*mv*idim), intent(in) | f, | ||
| real(fp_real), intent(in) | s, | ||
| integer(fp_size), intent(in) | nuest, | ||
| integer(fp_size), intent(in) | nvest, | ||
| integer(fp_size), intent(inout) | nu, | ||
| real(fp_real), dimension(nuest), intent(inout) | tu, | ||
| integer(fp_size), intent(inout) | nv, | ||
| real(fp_real), dimension(nvest), intent(inout) | tv, | ||
| real(fp_real), dimension((nuest-4)*(nvest-4)*idim), intent(inout) | c, | ||
| real(fp_real), intent(inout) | fp, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(kwrk), intent(inout) | iwrk, | ||
| integer(fp_size), intent(in) | kwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Fit a smooth parametric surface to gridded data.
Given data points \( \mathbf{f}(i,j) \in \mathbb{R}^d \) at the grid nodes \( (u_i, v_j) \), \( i=1,\ldots,m_u;\ j=1,\ldots,m_v \), determines a smooth \( d \)-dimensional bicubic spline

| pure subroutine, public fitpack_core::percur | ( | integer(fp_size), intent(in) | iopt, |
| integer(fp_size), intent(in) | m, | ||
| real(fp_real), dimension(m), intent(in) | x, | ||
| real(fp_real), dimension(m), intent(in) | y, | ||
| real(fp_real), dimension(m), intent(in) | w, | ||
| integer(fp_size), intent(in) | k, | ||
| real(fp_real), intent(in) | s, | ||
| integer(fp_size), intent(in) | nest, | ||
| integer(fp_size), intent(inout) | n, | ||
| real(fp_real), dimension(nest), intent(inout) | t, | ||
| real(fp_real), dimension(nest), intent(inout) | c, | ||
| real(fp_real), intent(inout) | fp, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(nest), intent(inout) | iwrk, | ||
| integer(fp_flag), intent(inout) | ier ) |
Determine a smooth periodic spline approximation to data.
Given data points \( (x_i, y_i) \) with weights \( w_i > 0 \), \( i=1,\ldots,m \), computes a periodic spline \( s(x) \) of degree \( k \) with period \( P = x_m - x_1 \). The periodicity means \( s(x_1) = s(x_m) \) and all derivatives match at the boundary.
iopt=-1: weighted least-squares spline with user-specified knots.iopt>=0: automatic knot placement minimizing the discontinuity jumps of the \( k \)-th derivative, subject to \( F(p) \le S \).| [in] | iopt | Computation mode: -1 (LSQ), 0 (new smoothing), 1 (continue). |
| [in] | m | Number of data points, \( m > 1 \). |
| [in] | x | Abscissae (strictly ascending). \( x_m \) defines the period length. |
| [in] | y | Ordinates \( y_1,\ldots,y_{m-1} \) (element \( y_m \) not used). |
| [in] | w | Weights \( w_1,\ldots,w_{m-1} > 0 \) ( \( w_m \) not used). |
| [in] | k | Spline degree, \( 1 \le k \le 5 \). Cubic ( \( k=3 \)) recommended. |
| [in] | s | Smoothing factor \( S \ge 0 \) (used when iopt>=0). |
| [in] | nest | Over-estimate of total knots. nest>=2*k+2; nest=m+2*k always suffices. |
| [in,out] | n | Total number of knots. |
| [in,out] | t | Knot positions (length nest). |
| [in,out] | c | B-spline coefficients (length nest). |
| [in,out] | fp | Weighted sum of squared residuals. |
| [in,out] | wrk | Real workspace, length \( \ge m(k+1) + \text{nest}(8+5k) \). |
| [in] | lwrk | Declared dimension of wrk. |
| [in,out] | iwrk | Integer workspace (length nest). |
| [in,out] | ier | Error flag (same codes as curfit, plus periodic constraints). |

| subroutine, public fitpack_core::pogrid | ( | integer(fp_size), dimension(3), intent(in) | iopt, |
| integer(fp_size), dimension(2), intent(in) | ider, | ||
| integer(fp_size), intent(in) | mu, | ||
| real(fp_real), dimension(mu), intent(in) | u, | ||
| integer(fp_size), intent(in) | mv, | ||
| real(fp_real), dimension(mv), intent(in) | v, | ||
| real(fp_real), dimension(mu*mv), intent(in) | z, | ||
| real(fp_real), intent(in) | z0, | ||
| real(fp_real), intent(in) | r, | ||
| real(fp_real), intent(in) | s, | ||
| integer(fp_size), intent(in) | nuest, | ||
| integer(fp_size), intent(in) | nvest, | ||
| integer(fp_size), intent(inout) | nu, | ||
| real(fp_real), dimension(nuest), intent(inout) | tu, | ||
| integer(fp_size), intent(inout) | nv, | ||
| real(fp_real), dimension(nvest), intent(inout) | tv, | ||
| real(fp_real), dimension((nuest-4)*(nvest-4)), intent(inout) | c, | ||
| real(fp_real), intent(inout) | fp, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(kwrk), intent(inout) | iwrk, | ||
| integer(fp_size), intent(in) | kwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Fit a smooth bivariate spline to gridded data on a polar (disc) domain.
Fits a function \( f(x,y) \) to data \( z_{ij} \) at the nodes \( (x,y) = (u_i \cos v_j,\ u_i \sin v_j) \) of a radius-angle grid over the disc

| pure subroutine, public fitpack_core::polar | ( | integer(fp_size), dimension(3), intent(in) | iopt, |
| integer(fp_size), intent(in) | m, | ||
| real(fp_real), dimension(m), intent(in) | x, | ||
| real(fp_real), dimension(m), intent(in) | y, | ||
| real(fp_real), dimension(m), intent(in) | z, | ||
| real(fp_real), dimension(m), intent(in) | w, | ||
| procedure(fitpack_polar_boundary) | rad, | ||
| real(fp_real), intent(in) | s, | ||
| integer(fp_size), intent(in) | nuest, | ||
| integer(fp_size), intent(in) | nvest, | ||
| real(fp_real), intent(in) | eps, | ||
| integer(fp_size), intent(out) | nu, | ||
| real(fp_real), dimension(nuest), intent(out) | tu, | ||
| integer(fp_size), intent(out) | nv, | ||
| real(fp_real), dimension(nvest), intent(out) | tv, | ||
| real(fp_real), dimension(m), intent(out) | u, | ||
| real(fp_real), dimension(m), intent(out) | v, | ||
| real(fp_real), dimension((nuest-4)*(nvest-4)), intent(out) | c, | ||
| real(fp_real), intent(inout) | fp, | ||
| real(fp_real), dimension(lwrk1), intent(inout) | wrk1, | ||
| integer(fp_size), intent(in) | lwrk1, | ||
| real(fp_real), dimension(lwrk2), intent(inout) | wrk2, | ||
| integer(fp_size), intent(in) | lwrk2, | ||
| integer(fp_size), dimension(kwrk), intent(inout) | iwrk, | ||
| integer(fp_size), intent(in) | kwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Fit a smooth bivariate spline to scattered data on a polar domain.
Given weighted data points \( (x_i, y_i, z_i, w_i) \) on a polar domain bounded by \( x = r(v)\cos v,\ y = r(v)\sin v \) for \( -\pi \le v \le \pi \), determines a

| pure subroutine, public fitpack_core::profil | ( | integer(fp_size), intent(in) | iopt, |
| real(fp_real), dimension(nx), intent(in) | tx, | ||
| integer(fp_size), intent(in) | nx, | ||
| real(fp_real), dimension(ny), intent(in) | ty, | ||
| integer(fp_size), intent(in) | ny, | ||
| real(fp_real), dimension((nx-kx-1)*(ny-ky-1)), intent(in) | c, | ||
| integer(fp_size), intent(in) | kx, | ||
| integer(fp_size), intent(in) | ky, | ||
| real(fp_real), intent(in) | u, | ||
| integer(fp_size), intent(in) | nu, | ||
| real(fp_real), dimension(nu), intent(out) | cu, | ||
| integer(fp_flag), intent(out) | ier ) |
Extract a cross-section (profile) of a bivariate spline.
Given a bivariate spline \( s(x,y) \), computes the B-spline coefficients of a univariate cross-section:
iopt=0: \( f(y) = s(u, y) \) — profile at fixed \( x = u \).iopt=1: \( g(x) = s(x, u) \) — profile at fixed \( y = u \).The resulting 1-D spline can be evaluated using splev or other univariate routines.
| [in] | iopt | Profile direction: 0 = fix \( x \), extract \( f(y) \); 1 = fix \( y \), extract \( g(x) \). |
| [in] | tx | Knot positions in \( x \)-direction (length \( n_x \)). |
| [in] | nx | Total number of knots in \( x \). |
| [in] | ty | Knot positions in \( y \)-direction (length \( n_y \)). |
| [in] | ny | Total number of knots in \( y \). |
| [in] | c | B-spline coefficients, length \( (n_x{-}k_x{-}1)(n_y{-}k_y{-}1) \). |
| [in] | kx | Degree in \( x \). |
| [in] | ky | Degree in \( y \). |
| [in] | u | Cross-section coordinate. Must satisfy \( t_{k_x+1} \le u \le t_{n_x-k_x} \) if iopt=0, or \( t_{k_y+1} \le u \le t_{n_y-k_y} \) if iopt=1. |
| [in] | nu | Declared dimension of cu. Must be \( \ge n_y \) if iopt=0, \( \ge n_x \) if iopt=1. |
| [out] | cu | B-spline coefficients of the 1-D cross-section (length nu). |
| [out] | ier | Error flag: 0 = normal return; 10 = invalid input. |

| pure subroutine, public fitpack_core::regrid | ( | integer(fp_size), intent(in) | iopt, |
| integer(fp_size), intent(in) | mx, | ||
| real(fp_real), dimension(mx), intent(in) | x, | ||
| integer(fp_size), intent(in) | my, | ||
| real(fp_real), dimension(my), intent(in) | y, | ||
| real(fp_real), dimension(mx*my), intent(in) | z, | ||
| real(fp_real), intent(in) | xb, | ||
| real(fp_real), intent(in) | xe, | ||
| real(fp_real), intent(in) | yb, | ||
| real(fp_real), intent(in) | ye, | ||
| integer(fp_size), intent(in) | kx, | ||
| integer(fp_size), intent(in) | ky, | ||
| real(fp_real), intent(in) | s, | ||
| integer(fp_size), intent(in) | nxest, | ||
| integer(fp_size), intent(in) | nyest, | ||
| integer(fp_size), intent(inout) | nx, | ||
| real(fp_real), dimension(nxest), intent(inout) | tx, | ||
| integer(fp_size), intent(inout) | ny, | ||
| real(fp_real), dimension(nyest), intent(inout) | ty, | ||
| real(fp_real), dimension((nxest-kx-1)*(nyest-ky-1)), intent(inout) | c, | ||
| real(fp_real), intent(out) | fp, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(kwrk), intent(inout) | iwrk, | ||
| integer(fp_size), intent(in) | kwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Fit a smoothing bivariate spline to data on a rectangular grid.
Determines a smooth bivariate spline \( s(x,y) \) of degrees \( k_x, k_y \) approximating data values \( z_{ij} \) at the grid nodes \( (x_i, y_j) \), \( i=1,\ldots,m_x;\ j=1,\ldots,m_y \), on the rectangle \( [x_b, x_e] \times [y_b, y_e] \).
The smoothing factor \( s \ge 0 \) controls the trade-off: the routine minimizes discontinuity jumps in the spline derivatives subject to
\[ \sum_{i=1}^{m_x} \sum_{j=1}^{m_y} \bigl(z_{ij} - s(x_i, y_j)\bigr)^2 \le s. \]
Setting \( s = 0 \) produces an interpolating spline.
| [in] | iopt | Computation mode: -1 = least-squares with user knots; 0 = smoothing, fresh start; 1 = smoothing, continue with previous knots. |
| [in] | mx | Number of grid points along \( x \), \( m_x > k_x \). |
| [in] | x | Strictly increasing \( x \)-grid coordinates (length \( m_x \)). |
| [in] | my | Number of grid points along \( y \), \( m_y > k_y \). |
| [in] | y | Strictly increasing \( y \)-grid coordinates (length \( m_y \)). |
| [in] | z | Data values, length \( m_x \cdot m_y \): z(my*(i-1)+j) = value at \( (x_i, y_j) \). |
| [in] | xb | Lower \( x \)-boundary, \( x_b \le x_1 \). |
| [in] | xe | Upper \( x \)-boundary, \( x_e \ge x_{m_x} \). |
| [in] | yb | Lower \( y \)-boundary, \( y_b \le y_1 \). |
| [in] | ye | Upper \( y \)-boundary, \( y_e \ge y_{m_y} \). |
| [in] | kx | Degree in \( x \), \( 1 \le k_x \le 5 \) (bicubic \( k_x{=}3 \) recommended). |
| [in] | ky | Degree in \( y \), \( 1 \le k_y \le 5 \). |
| [in] | s | Smoothing factor, \( s \ge 0 \) (ignored when iopt=-1). |
| [in] | nxest | Upper bound for \( n_x \), \( \ge 2(k_x{+}1) \). |
| [in] | nyest | Upper bound for \( n_y \), \( \ge 2(k_y{+}1) \). |
| [in,out] | nx | Total number of knots in \( x \). |
| [in,out] | tx | Knot positions in \( x \) (length nxest). |
| [in,out] | ny | Total number of knots in \( y \). |
| [in,out] | ty | Knot positions in \( y \) (length nyest). |
| [out] | c | B-spline coefficients, length \( (n_x{-}k_x{-}1)(n_y{-}k_y{-}1) \). |
| [out] | fp | Sum of squared residuals \( F_p \). |
| [in,out] | wrk | Real workspace (length lwrk). |
| [in] | lwrk | Declared dimension of wrk. |
| [in,out] | iwrk | Integer workspace (length kwrk). |
| [in] | kwrk | Declared dimension of iwrk. |
| [out] | ier | Error flag: \( \le 0 \) = success, 1–5 = convergence warnings, 10 = invalid input. |

|
private |
Update the smoothing parameter \( p \) during iterative knot selection.
Given the current iterate \( (p, F(p) - S) \) and the bracketing triple \( (p_1, F_1), (p_2, F_2), (p_3, F_3) \) with \( F_1 > 0 \) and \( F_3 < 0 \), updates the bracket and computes the next estimate via rational interpolation (fprati, Eq. 5.30).
During the initial phase (before the bracket is established), the routine adjusts \( p \) by multiplicative factors to find \( p \) values that bracket the root \( F(p) = 0 \).
| [in,out] | p1 | Left bracket; satisfies \( F_1 > 0 \) |
| [in,out] | f1 | \( F(p_1) - S \); updated with \( p_1 \) |
| [in,out] | p2 | Most recent iterate; set to p on entry |
| [in,out] | f2 | \( F(p_2) - S \); set to fpms on entry |
| [in,out] | p3 | Right bracket; satisfies \( F_3 < 0 \) |
| [in,out] | f3 | \( F(p_3) - S \); updated with \( p_3 \) |
| [in,out] | p | Current smoothing parameter; updated to next estimate |
| [in] | fpms | Current residual \( F(p) - S \) |
| [in] | acc | Convergence tolerance |
| [in,out] | check1 | .true. once lower bracket is established |
| [in,out] | check3 | .true. once upper bracket is established |
| [out] | success | .false. if iteration stalls (non-monotone \( F \)) |

| pure subroutine, public fitpack_core::spalde | ( | real(fp_real), dimension(n), intent(in) | t, |
| integer(fp_size), intent(in) | n, | ||
| real(fp_real), dimension(n), intent(in) | c, | ||
| integer(fp_size), intent(in) | k1, | ||
| real(fp_real), intent(in) | x, | ||
| real(fp_real), dimension(k1), intent(out) | d, | ||
| integer(fp_flag), intent(out) | ier ) |
Evaluate all derivatives of a spline at a single point.
Given a spline \( s(x) \) of order \( k_1 = k + 1 \) (degree \( k \)) in B-spline representation, computes \( d_j = s^{(j-1)}(x) \) for \( j = 1,\ldots,k_1 \) using the stable recurrence scheme of de Boor.
| [in] | t | Knot positions (length \( n \)). |
| [in] | n | Total number of knots. |
| [in] | c | B-spline coefficients (length \( n \)). |
| [in] | k1 | Order of the spline ( \( k_1 = k + 1 \)). |
| [in] | x | Point where derivatives are evaluated. Must satisfy \( t_{k_1} \le x \le t_{n-k_1+1} \). |
| [out] | d | Derivative values (length \( k_1 \)): \( d(j) = s^{(j-1)}(x) \) for \( j = 1,\ldots,k_1 \). |
| [out] | ier | Error flag: 0 = normal return; 10 = invalid input. |

| pure subroutine, public fitpack_core::spgrid | ( | integer(fp_size), dimension(3), intent(in) | iopt, |
| integer(fp_size), dimension(4), intent(in) | ider, | ||
| integer(fp_size), intent(in) | mu, | ||
| real(fp_real), dimension(mu), intent(in) | u, | ||
| integer(fp_size), intent(in) | mv, | ||
| real(fp_real), dimension(mv), intent(in) | v, | ||
| real(fp_real), dimension(mu*mv), intent(in) | r, | ||
| real(fp_real), intent(in) | r0, | ||
| real(fp_real), intent(in) | r1, | ||
| real(fp_real), intent(in) | s, | ||
| integer(fp_size), intent(in) | nuest, | ||
| integer(fp_size), intent(in) | nvest, | ||
| integer(fp_size), intent(inout) | nu, | ||
| real(fp_real), dimension(nuest), intent(inout) | tu, | ||
| integer(fp_size), intent(inout) | nv, | ||
| real(fp_real), dimension(nvest), intent(inout) | tv, | ||
| real(fp_real), dimension((nuest-4)*(nvest-4)), intent(inout) | c, | ||
| real(fp_real), intent(inout) | fp, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(kwrk), intent(inout) | iwrk, | ||
| integer(fp_size), intent(in) | kwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Fit a smooth bivariate spline to gridded data on a sphere (latitude-longitude grid).
Given data values \( r_{ij} \) on the latitude-longitude grid \( (u_i, v_j) \) with \( 0 < u_i < \pi \) (colatitude), \( v_b \le v_j < v_b + 2\pi \) (longitude), determines a bicubic spline \( s(u,v) \) satisfying pole continuity constraints (value and optional gradient at \( u=0 \) and \( u=\pi \)) and periodicity in \( v \):
\[ \sum_{i,j}(r_{ij} - s(u_i,v_j))^2 + (r_0 - s(0,v))^2 + (r_1 - s(\pi,v))^2 \le s. \]
| [in] | iopt | Integer array(3): iopt(1) = computation mode (-1/0/1); iopt(2) = continuity order at pole \( u=0 \) (0/1); iopt(3) = continuity order at pole \( u=\pi \) (0/1). |
| [in] | ider | Integer array(4): pole data/derivative flags — ider(1) and ider(3) specify whether data at poles exist; ider(2) and ider(4) specify vanishing derivatives. |
| [in] | mu | Number of latitude grid points, \( 0 < u_i < \pi \). |
| [in] | u | Strictly increasing colatitudes (length \( m_u \)). |
| [in] | mv | Number of longitude grid points, \( m_v > 3 \). |
| [in] | v | Strictly increasing longitudes (length \( m_v \)), \( -\pi \le v_1 < \pi,\ v_{m_v} < v_1 + 2\pi \). |

| pure subroutine, public fitpack_core::sphere | ( | integer(fp_size), intent(in) | iopt, |
| integer(fp_size), intent(in) | m, | ||
| real(fp_real), dimension(m), intent(in) | teta, | ||
| real(fp_real), dimension(m), intent(in) | phi, | ||
| real(fp_real), dimension(m), intent(in) | r, | ||
| real(fp_real), dimension(m), intent(in) | w, | ||
| real(fp_real), intent(in) | s, | ||
| integer(fp_size), intent(in) | ntest, | ||
| integer(fp_size), intent(in) | npest, | ||
| real(fp_real), intent(in) | eps, | ||
| integer(fp_size), intent(inout) | nt, | ||
| real(fp_real), dimension(ntest), intent(inout) | tt, | ||
| integer(fp_size), intent(inout) | np, | ||
| real(fp_real), dimension(npest), intent(inout) | tp, | ||
| real(fp_real), dimension((ntest-4)*(npest-4)), intent(inout) | c, | ||
| real(fp_real), intent(inout) | fp, | ||
| real(fp_real), dimension(lwrk1), intent(inout) | wrk1, | ||
| integer(fp_size), intent(in) | lwrk1, | ||
| real(fp_real), dimension(lwrk2), intent(inout) | wrk2, | ||
| integer(fp_size), intent(in) | lwrk2, | ||
| integer(fp_size), dimension(kwrk), intent(inout) | iwrk, | ||
| integer(fp_size), intent(in) | kwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Fit a smooth bicubic spherical spline to scattered data on a sphere.
Given weighted data points \( (\theta_i, \phi_i, r_i, w_i) \), \( i=1,\ldots,m \), with \( 0 \le \theta \le \pi \) (colatitude) and \( 0 \le \phi \le 2\pi \) (longitude), determines a bicubic spline \( s(\theta, \phi) \) satisfying:
The smoothing factor \( s \ge 0 \) controls the trade-off:
\[ \sum_{i=1}^{m} \bigl[w_i\,(r_i - s(\theta_i, \phi_i))\bigr]^2 \le s. \]
| [in] | iopt | Computation mode: -1 = least-squares with user knots; 0 = smoothing, fresh start; 1 = smoothing, continue. |
| [in] | m | Number of data points, \( m \ge 2 \). |
| [in] | teta | Colatitudes \( \theta_i \in [0, \pi] \) (length \( m \)). |
| [in] | phi | Longitudes \( \phi_i \in [0, 2\pi] \) (length \( m \)). |
| [in] | r | Data values (length \( m \)). |
| [in] | w | Positive weights (length \( m \)). |
| [in] | s | Smoothing factor, \( s \ge 0 \) (ignored when iopt=-1). |
| [in] | ntest | Upper bound for \( n_\theta \), \( \ge 8 \). |
| [in] | npest | Upper bound for \( n_\phi \), \( \ge 8 \). |
| [in] | eps | Rank-deficiency threshold, \( 0 < \varepsilon < 1 \). |
| [in,out] | nt | Total number of knots in \( \theta \). |
| [in,out] | tt | Knot positions in \( \theta \) (length ntest). |
| [in,out] | np | Total number of knots in \( \phi \). |
| [in,out] | tp | Knot positions in \( \phi \) (length npest). |
| [out] | c | B-spline coefficients, length \( (n_\theta{-}4)(n_\phi{-}4) \). |
| [out] | fp | Weighted sum of squared residuals \( F_p \). |
| [in,out] | wrk1 | Real workspace (length lwrk1). |
| [in] | lwrk1 | Declared dimension of wrk1. |
| [in,out] | wrk2 | Secondary workspace for rank-deficient systems (length lwrk2). |
| [in] | lwrk2 | Declared dimension of wrk2. |
| [in,out] | iwrk | Integer workspace (length kwrk). |
| [in] | kwrk | Declared dimension of iwrk. |
| [out] | ier | Error flag: \( \le 0 \) = success, 1–5 = convergence warnings, 10 = invalid input, >10 = lwrk2 too small. |

| pure subroutine, public fitpack_core::splder | ( | real(fp_real), dimension(n), intent(in) | t, |
| integer(fp_size), intent(in) | n, | ||
| real(fp_real), dimension(n), intent(in) | c, | ||
| integer(fp_size), intent(in) | k, | ||
| integer(fp_size), intent(in) | nu, | ||
| real(fp_real), dimension(m), intent(in) | x, | ||
| real(fp_real), dimension(m), intent(out) | y, | ||
| integer(fp_size), intent(in) | m, | ||
| integer(fp_flag), intent(in) | e, | ||
| real(fp_real), dimension(n), intent(inout) | wrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Evaluate the \( \nu \)-th derivative of a spline \( s(x) \) at a set of points.
Given a spline of degree \( k \) in B-spline representation, evaluates \( s^{(\nu)}(x_i) \) for \( i = 1,\ldots,m \) using the recurrence scheme of de Boor. The derivative of order \( \nu \) of a degree- \( k \) spline is a degree- \( (k{-}\nu) \) spline whose B-spline coefficients are computed via the de Boor recurrence.
| [in] | t | Knot positions (length \( n \)). |
| [in] | n | Total number of knots. |
| [in] | c | B-spline coefficients (length \( n \)). |
| [in] | k | Degree of the spline. |
| [in] | nu | Order of derivative, \( 0 \le \nu \le k \). |
| [in] | x | Evaluation points (length \( m \)). |
| [out] | y | Derivative values \( s^{(\nu)}(x_i) \) (length \( m \)). |
| [in] | m | Number of evaluation points, \( m \ge 1 \). |
| [in] | e | Extrapolation mode for points outside the support:
|
| [in,out] | wrk | Real workspace (length \( n \)). Contains derivative coefficients on exit. |
| [out] | ier | Error flag: 0 = normal; 1 = out of bounds with e=2; 10 = invalid input. |

| pure subroutine, public fitpack_core::splev | ( | real(fp_real), dimension(n), intent(in) | t, |
| integer(fp_size), intent(in) | n, | ||
| real(fp_real), dimension(n), intent(in) | c, | ||
| integer(fp_size), intent(in) | k, | ||
| real(fp_real), dimension(m), intent(in) | x, | ||
| real(fp_real), dimension(m), intent(out) | y, | ||
| integer(fp_size), intent(in) | m, | ||
| integer(fp_flag), intent(in) | e, | ||
| integer(fp_flag), intent(out) | ier ) |
Evaluate a spline \( s(x) \) of degree \( k \) at a set of points.
Given a spline in its B-spline representation (knots \( t \), coefficients \( c \), degree \( k \)), evaluates \( s(x_i) \) for \( i = 1,\ldots,m \).
| [in] | t | Knot positions (length \( n \)). |
| [in] | n | Total number of knots. |
| [in] | c | B-spline coefficients (length \( n \)). |
| [in] | k | Degree of the spline. |
| [in] | x | Evaluation points (length \( m \)). |
| [out] | y | Spline values \( s(x_i) \) (length \( m \)). |
| [in] | m | Number of evaluation points. Must satisfy \( m \ge 1 \). |
| [in] | e | Extrapolation mode for points outside \( [t_{k+1}, t_{n-k}] \):
|
| [out] | ier | Error flag: 0 = normal return; 10 = invalid input. |

| real(fp_real) function, public fitpack_core::splint | ( | real(fp_real), dimension(n), intent(in) | t, |
| integer(fp_size), intent(in) | n, | ||
| real(fp_real), dimension(n), intent(in) | c, | ||
| integer(fp_size), intent(in) | k, | ||
| real(fp_real), intent(in) | a, | ||
| real(fp_real), intent(in) | b, | ||
| real(fp_real), dimension(n), intent(inout) | wrk ) |
Compute the definite integral of a spline \( s(x) \) over \( [a, b] \).
Calculates \( \int_a^b s(x)\,dx \) for a spline of degree \( k \) given in B-spline representation. The spline is considered identically zero outside its support \( (t_{k+1}, t_{n-k}) \).
Uses the method of Gaffney (1976): first computes the integrals of each normalized B-spline \( N_{i,k+1}(x) \) over \( [a, b] \), then forms the weighted sum with the spline coefficients.
| [in] | t | Knot positions (length \( n \)). |
| [in] | n | Total number of knots. |
| [in] | c | B-spline coefficients (length \( n \)). |
| [in] | k | Degree of the spline. |
| [in] | a | Left endpoint of the integration interval. |
| [in] | b | Right endpoint of the integration interval. |
| [in,out] | wrk | Real workspace (length \( n \)). On exit, contains integrals of normalized B-splines. |

| pure subroutine, public fitpack_core::sproot | ( | real(fp_real), dimension(n), intent(in) | t, |
| integer(fp_size), intent(in) | n, | ||
| real(fp_real), dimension(n), intent(in) | c, | ||
| real(fp_real), dimension(mest), intent(out) | zeros, | ||
| integer(fp_size), intent(in) | mest, | ||
| integer(fp_size), intent(out) | m, | ||
| integer(fp_flag), intent(out) | ier ) |
Find the zeros of a cubic spline \( s(x) \) given in B-spline representation.
Locates all real roots of a cubic spline ( \( k = 3 \)) by reducing the problem to finding zeros of the cubic polynomial on each knot interval \( [t_l, t_{l+1}] \). Uses continuity of the spline and its derivative to propagate endpoint values across intervals, calling fpcuro for each cubic piece.
| [in] | t | Knot positions (length \( n \)). Must satisfy \( n \ge 8 \). |
| [in] | n | Total number of knots. |
| [in] | c | B-spline coefficients (length \( n \)). |
| [out] | zeros | Array of zeros found (length mest). |
| [in] | mest | Maximum number of zeros that can be stored. |
| [out] | m | Actual number of zeros found. |
| [out] | ier | Error flag:
|

| pure subroutine, public fitpack_core::surev | ( | integer(fp_size), intent(in) | idim, |
| real(fp_real), dimension(nu), intent(in) | tu, | ||
| integer(fp_size), intent(in) | nu, | ||
| real(fp_real), dimension(nv), intent(in) | tv, | ||
| integer(fp_size), intent(in) | nv, | ||
| real(fp_real), dimension((nu-4)*(nv-4)*idim), intent(in) | c, | ||
| real(fp_real), dimension(mu), intent(in) | u, | ||
| integer(fp_size), intent(in) | mu, | ||
| real(fp_real), dimension(mv), intent(in) | v, | ||
| integer(fp_size), intent(in) | mv, | ||
| real(fp_real), dimension(mf), intent(out) | f, | ||
| integer(fp_size), intent(in) | mf, | ||
| real(fp_real), dimension(lwrk), intent(inout) | wrk, | ||
| integer(fp_size), intent(in) | lwrk, | ||
| integer(fp_size), dimension(kwrk), intent(inout) | iwrk, | ||
| integer(fp_size), intent(in) | kwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Evaluate a parametric bicubic spline surface on a grid.
Evaluates an \( d \)-dimensional ( \( d = \) idim) bicubic spline surface at the grid \( (u_i, v_j) \), \( i=1,\ldots,m_u;\
j=1,\ldots,m_v \).

| pure subroutine, public fitpack_core::surfit | ( | integer(fp_size), intent(in) | iopt, |
| integer(fp_size), intent(in) | m, | ||
| real(fp_real), dimension(m), intent(inout) | x, | ||
| real(fp_real), dimension(m), intent(inout) | y, | ||
| real(fp_real), dimension(m), intent(in) | z, | ||
| real(fp_real), dimension(m), intent(in) | w, | ||
| real(fp_real), intent(in) | xb, | ||
| real(fp_real), intent(in) | xe, | ||
| real(fp_real), intent(in) | yb, | ||
| real(fp_real), intent(in) | ye, | ||
| integer(fp_size), intent(in) | kx, | ||
| integer(fp_size), intent(in) | ky, | ||
| real(fp_real), intent(in) | s, | ||
| integer(fp_size), intent(in) | nxest, | ||
| integer(fp_size), intent(in) | nyest, | ||
| integer(fp_size), intent(in) | nmax, | ||
| real(fp_real), intent(in) | eps, | ||
| integer(fp_size), intent(inout) | nx, | ||
| real(fp_real), dimension(nmax), intent(inout) | tx, | ||
| integer(fp_size), intent(inout) | ny, | ||
| real(fp_real), dimension(nmax), intent(inout) | ty, | ||
| real(fp_real), dimension((nxest-kx-1)*(nyest-ky-1)), intent(inout) | c, | ||
| real(fp_real), intent(inout) | fp, | ||
| real(fp_real), dimension(lwrk1), intent(inout) | wrk1, | ||
| integer(fp_size), intent(in) | lwrk1, | ||
| real(fp_real), dimension(lwrk2), intent(inout) | wrk2, | ||
| integer(fp_size), intent(in) | lwrk2, | ||
| integer(fp_size), dimension(kwrk), intent(inout) | iwrk, | ||
| integer(fp_size), intent(in) | kwrk, | ||
| integer(fp_flag), intent(out) | ier ) |
Fit a smoothing bivariate spline to scattered data.
Given weighted data points \( (x_i, y_i, z_i, w_i) \), \( i=1,\ldots,m \), determines a bivariate spline \( s(x,y) \) of degrees \( k_x, k_y \) on the rectangle \( [x_b, x_e] \times [y_b, y_e] \).
The smoothing factor \( s \ge 0 \) controls the trade-off: the routine minimizes discontinuity jumps in the spline derivatives subject to
\[ \sum_{i=1}^{m} \bigl[w_i\,(z_i - s(x_i, y_i))\bigr]^2 \le s. \]
Setting \( s = 0 \) produces an interpolating spline. The result is given in tensor-product B-spline representation and can be evaluated with bispev / bispeu.
| [in] | iopt | Computation mode: -1 = least-squares with user knots; 0 = smoothing, fresh start; 1 = smoothing, continue. |
| [in] | m | Number of data points, \( m \ge (k_x{+}1)(k_y{+}1) \). |
| [in,out] | x | \( x \)-coordinates of data points (length \( m \)). |
| [in,out] | y | \( y \)-coordinates of data points (length \( m \)). |
| [in] | z | Data values (length \( m \)). |
| [in] | w | Positive weights (length \( m \)). |
| [in] | xb | Lower \( x \)-boundary. |
| [in] | xe | Upper \( x \)-boundary. |
| [in] | yb | Lower \( y \)-boundary. |
| [in] | ye | Upper \( y \)-boundary. |
| [in] | kx | Degree in \( x \), \( 1 \le k_x \le 5 \) (bicubic recommended). |
| [in] | ky | Degree in \( y \), \( 1 \le k_y \le 5 \). |
| [in] | s | Smoothing factor, \( s \ge 0 \) (ignored when iopt=-1). |
| [in] | nxest | Upper bound for \( n_x \), \( \ge 2(k_x{+}1) \). |
| [in] | nyest | Upper bound for \( n_y \), \( \ge 2(k_y{+}1) \). |
| [in] | nmax | Dimension of tx/ty arrays, \( \ge \max(n_x^{\text{est}}, n_y^{\text{est}}) \). |
| [in] | eps | Rank-deficiency threshold, \( 0 < \varepsilon < 1 \). |
| [in,out] | nx | Total number of knots in \( x \). |
| [in,out] | tx | Knot positions in \( x \) (length nmax). |
| [in,out] | ny | Total number of knots in \( y \). |
| [in,out] | ty | Knot positions in \( y \) (length nmax). |
| [out] | c | B-spline coefficients, length \( (n_x{-}k_x{-}1)(n_y{-}k_y{-}1) \). |
| [out] | fp | Weighted sum of squared residuals \( F_p \). |
| [in,out] | wrk1 | Real workspace (length lwrk1). |
| [in] | lwrk1 | Declared dimension of wrk1. |
| [in,out] | wrk2 | Secondary workspace for rank-deficient systems (length lwrk2). |
| [in] | lwrk2 | Declared dimension of wrk2. |
| [in,out] | iwrk | Integer workspace (length kwrk). |
| [in] | kwrk | Declared dimension of iwrk. |
| [out] | ier | Error flag: \( \le 0 \) = success, 1–5 = convergence warnings, 10 = invalid input, >10 = lwrk2 too small. |

|
private |
Swap two real values in place.
|
private |
Swap two integer values in place.
| integer(fp_flag), parameter, public fitpack_core::concon_maxbin = 14 |
| integer(fp_flag), parameter, public fitpack_core::concon_maxtr = 15 |
| integer(fp_flag), parameter, public fitpack_core::concon_qp_fail = 16 |
| integer(fp_size), parameter, public fitpack_core::degree_3 = 3 |
| integer(fp_size), parameter, public fitpack_core::degree_4 = 4 |
| integer(fp_size), parameter, public fitpack_core::degree_5 = 5 |
| integer(fp_flag), parameter, public fitpack_core::fitpack_input_error = 10 |
| integer(fp_flag), parameter, public fitpack_core::fitpack_insufficient_knots = 13 |
| integer(fp_flag), parameter, public fitpack_core::fitpack_insufficient_storage = 1 |
| integer(fp_flag), parameter, public fitpack_core::fitpack_interpolating_ok = -1 |
| integer(fp_flag), parameter, public fitpack_core::fitpack_invalid_constraint = 12 |
| integer(fp_flag), parameter, public fitpack_core::fitpack_invalid_range = 6 |
| integer(fp_flag), parameter, public fitpack_core::fitpack_leastsquares_ok = -2 |
| integer(fp_flag), parameter, public fitpack_core::fitpack_maxit = 3 |
| integer(fp_flag), parameter, public fitpack_core::fitpack_ok = 0 |
| integer(fp_flag), parameter, public fitpack_core::fitpack_overlapping_knots = 5 |
| integer(fp_flag), parameter, public fitpack_core::fitpack_s_too_small = 2 |
| integer(fp_flag), parameter, public fitpack_core::fitpack_test_error = 11 |
| integer(fp_flag), parameter, public fitpack_core::fitpack_too_many_knots = 4 |
| real(fp_real), parameter, public fitpack_core::five = 5.0_FP_REAL |
| real(fp_real), parameter, public fitpack_core::four = 4.0_FP_REAL |
| real(fp_real), parameter, public fitpack_core::fourth = 0.25_FP_REAL |
| integer, parameter, public fitpack_core::fp_bool = c_bool |
| integer, parameter, public fitpack_core::fp_comm = c_double |
| logical(fp_bool), parameter, public fitpack_core::fp_false = .false._FP_BOOL |
| integer, parameter, public fitpack_core::fp_flag = c_int32_t |
|
private |
Marker for unallocated arrays in communication buffers.
| integer, parameter, public fitpack_core::fp_real = c_double |
| integer, parameter, public fitpack_core::fp_size = c_int32_t |
| logical(fp_bool), parameter, public fitpack_core::fp_true = .true._FP_BOOL |
| real(fp_real), parameter, public fitpack_core::half = 0.5_FP_REAL |
|
private |
|
private |
|
private |
| integer(fp_flag), parameter, public fitpack_core::iopt_new_leastsquares = -1 |
| integer(fp_flag), parameter, public fitpack_core::iopt_new_smoothing = 0 |
| integer(fp_flag), parameter, public fitpack_core::iopt_old_fit = 1 |
|
private |
|
private |
|
private |
| integer(fp_flag), parameter, public fitpack_core::knot_dim_1 = -1 |
| integer(fp_flag), parameter, public fitpack_core::knot_dim_2 = 1 |
| integer(fp_flag), parameter, public fitpack_core::knot_dim_none = 0 |
| integer(fp_size), parameter, public fitpack_core::max_idim = 10 |
| integer(fp_size), parameter, public fitpack_core::max_order = 19 |
| real(fp_real), parameter, public fitpack_core::one = 1.0_FP_REAL |
| real(fp_real), parameter, public fitpack_core::onep5 = 1.5_FP_REAL |
| integer(fp_flag), parameter, public fitpack_core::outside_extrapolate = 0 |
| integer(fp_flag), parameter, public fitpack_core::outside_nearest_bnd = 3 |
| integer(fp_flag), parameter, public fitpack_core::outside_not_allowed = 2 |
| integer(fp_flag), parameter, public fitpack_core::outside_zero = 1 |
| real(fp_real), parameter, public fitpack_core::six = 6.0_FP_REAL |
| real(fp_real), parameter, public fitpack_core::smallnum03 = 1.0e-03_FP_REAL |
| real(fp_real), parameter, public fitpack_core::smallnum06 = 1.0e-06_FP_REAL |
| real(fp_real), parameter, public fitpack_core::smallnum08 = 1.0e-08_FP_REAL |
| real(fp_real), parameter, public fitpack_core::smallnum10 = 1.0e-10_FP_REAL |
| real(fp_real), parameter, public fitpack_core::ten = 10.0_FP_REAL |
| real(fp_real), parameter, public fitpack_core::three = 3.0_FP_REAL |
| real(fp_real), parameter, public fitpack_core::two = 2.0_FP_REAL |
| real(fp_real), parameter, public fitpack_core::zero = 0.0_FP_REAL |