• Stars
    star
    165
  • Rank 228,906 (Top 5 %)
  • Language
    Fortran
  • License
    Other
  • Created over 9 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Multidimensional B-Spline Interpolation of Data on a Regular Grid

bspline-fortran

Multidimensional B-Spline Interpolation of Data on a Regular Grid

Status

GitHub release Build Status codecov last-commit DOI

Brief description

The library provides subroutines for 1D-6D interpolation and extrapolation using B-splines. The code is written in modern Fortran (i.e., Fortran 2003+). There are two ways to use the module, via a basic subroutine interface and an object-oriented interface. Both are thread safe.

Subroutine interface

The core routines for the subroutine interface are:

!f(x)
subroutine db1ink(x,nx,fcn,kx,iknot,tx,bcoef,iflag)
subroutine db1val(xval,idx,tx,nx,kx,bcoef,f,iflag,inbvx,w0,extrap)

!f(x,y)
subroutine db2ink(x,nx,y,ny,fcn,kx,ky,iknot,tx,ty,bcoef,iflag)
subroutine db2val(xval,yval,idx,idy,tx,ty,nx,ny,kx,ky,bcoef,f,iflag,inbvx,inbvy,iloy,w1,w0,extrap)

!f(x,y,z)
subroutine db3ink(x,nx,y,ny,z,nz,fcn,kx,ky,kz,iknot,tx,ty,tz,bcoef,iflag)
subroutine db3val(xval,yval,zval,idx,idy,idz,tx,ty,tz,nx,ny,nz,kx,ky,kz,bcoef,f,iflag,inbvx,inbvy,inbvz,iloy,iloz,w2,w1,w0,extrap)

!f(x,y,z,q)
subroutine db4ink(x,nx,y,ny,z,nz,q,nq,fcn,kx,ky,kz,kq,iknot,tx,ty,tz,tq,bcoef,iflag)
subroutine db4val(xval,yval,zval,qval,idx,idy,idz,idq,tx,ty,tz,tq,nx,ny,nz,nq,kx,ky,kz,kq,bcoef,f,iflag,inbvx,inbvy,inbvz,inbvq,iloy,iloz,iloq,w3,w2,w1,w0,extrap)

!f(x,y,z,q,r)
subroutine db5ink(x,nx,y,ny,z,nz,q,nq,r,nr,fcn,kx,ky,kz,kq,kr,iknot,tx,ty,tz,tq,tr,bcoef,iflag)
subroutine db5val(xval,yval,zval,qval,rval,idx,idy,idz,idq,idr,tx,ty,tz,tq,tr,nx,ny,nz,nq,nr,kx,ky,kz,kq,kr,bcoef,f,iflag,inbvx,inbvy,inbvz,inbvq,inbvr,iloy,iloz,iloq,ilor,w4,w3,w2,w1,w0,extrap)

!f(x,y,z,q,r,s)
subroutine db6ink(x,nx,y,ny,z,nz,q,nq,r,nr,s,ns,fcn,kx,ky,kz,kq,kr,ks,iknot,tx,ty,tz,tq,tr,ts,bcoef,iflag)
subroutine db6val(xval,yval,zval,qval,rval,sval,idx,idy,idz,idq,idr,ids,tx,ty,tz,tq,tr,ts,nx,ny,nz,nq,nr,ns,kx,ky,kz,kq,kr,ks,bcoef,f,iflag,inbvx,inbvy,inbvz,inbvq,inbvr,inbvs,iloy,iloz,iloq,ilor,ilos,w5,w4,w3,w2,w1,w0,extrap)

The ink routines compute the interpolant coefficients, and the val routines evalute the interpolant at the specified value of each coordinate. The 2D and 3D routines are extensively refactored versions of the original routines from the NIST Core Math Library. The others are new, and are simply extensions of the same algorithm into the other dimensions.

Object-oriented interface

In addition to the main subroutines, an object-oriented interface is also provided. For example, for the 3D case:

type(bspline_3d) :: s
call s%initialize(x,y,z,fcn,kx,ky,kz,iflag,extrap)
call s%evaluate(xval,yval,zval,idx,idy,idz,f,iflag)
call s%destroy()

Which uses the default "not-a-knot" end conditions. You can also specify the knot vectors (in this case, tx, ty, and tz) manually during class initialization:

call s%initialize(x,y,z,fcn,kx,ky,kz,tx,ty,tz,iflag,extrap)

The various bspline classes can also be initialized using constructors, which have similar interfaces as the initialize methods. For example:

type(bspline_3d) :: s
s = bspline_3d(x,y,z,fcn,kx,ky,kz,iflag,extrap)

Extrapolation

The library optionally supports extrapolation for points outside the range of the coefficients. This is disabled by default (in which case an error code is returned for points outside the bounds). To enable extrapolation, use the optional extrap input to the various db*val subroutines or the initialize methods from the object-oriented interface.

Integration

The library also contains routines for computing definite integrals of bsplines. There are two methods (currently only for 1D):

  • Basic version: db1sqad (integral in the object-oriented interface) -- Computes the integral on (x1,x2) of a b-spline by applying a 2, 6, or 10 point Gauss formula on subintervals of (x1,x2). This is only valid for orders <= 20.
  • More general version: db1fqad (fintegral in the object-oriented interface) -- Computes the integral on (x1,x2) of a product of a user-defined function fun(x) and the ith derivative of a b-spline with an adaptive 8-point Legendre-Gauss algorithm.

Note that extrapolation is not currently supported for these.

Least squares fitting

The BSpline-Fortran library also exports the defc subroutine, which can be used to fit B-spline polynomials to 1D data using a weighted least squares method. The dfc subroutine also allows for equality and inequality constraints to be imposed on the fitted curve. These procedures are not yet available in the object oriented interface.

Examples

See the examples for more details. Note that, to compile and run some of the test programs, the pyplot-fortran library (which is used to generate plots) is required. This will automatically be downloaded by FPM.

Compiling

The library can be compiled with recent versions the Intel Fortran Compiler and GFortran (and presumably any other Fortran compiler that supports modern standards).

FPM

A fmp.toml file is provided for compiling bspline-fortran with the Fortran Package Manager. For example, to build:

fpm build --profile release

By default, the library is built with double precision (real64) real values and single precision (int32) integer values. Explicitly specifying the real or integer kinds can be done using the following processor flags:

Preprocessor flag Kind Number of bytes
REAL32 real(kind=real32) 4
REAL64 real(kind=real64) 8
REAL128 real(kind=real128) 16
Preprocessor flag Kind Number of bytes
INT8 integer(kind=int8) 1
INT16 integer(kind=int16) 2
INT32 integer(kind=int32) 4
INT64 integer(kind=int64) 8

For example, to build a single precision version of the library, use:

fpm build --profile release --flag "-DREAL32"

To run the unit tests:

fpm test --profile release

To use bspline-fortran within your fpm project, add the following to your fpm.toml file:

[dependencies]
bspline-fortran = { git="https://github.com/jacobwilliams/bspline-fortran.git" }

or, to use a specific version:

[dependencies]
bspline-fortran = { git="https://github.com/jacobwilliams/bspline-fortran.git", tag = "7.3.0"  }

CMake

A basic CMake configuration file is also included. For example, to build a static library:

 mkdir build
 cd build
 cmake ..
 make

Or, to build a shared library:

 cmake -DBUILD_SHARED_LIBS=ON ..

For a debug build:

 cmake -DCMAKE_BUILD_TYPE=DEBUG ..

Dependencies

The library requires some BLAS routines, which are included. However, the user may also choose to link to an external BLAS library. This can be done by using the HAS_BLAS compiler directive. For example:

fpm build --compiler gfortran --flag "-DHAS_BLAS -lblas"

However, note that an external BLAS can only be used if the library is compiled with double precision (real64) reals.

Documentation

The latest API documentation can be found here. This was generated from the source code using FORD (i.e. by running ford bspline-fortran.md).

License

The bspline-fortran source code and related files and documentation are distributed under a permissive free software license (BSD-style).

More Repositories

1

json-fortran

A Modern Fortran JSON API
Fortran
331
star
2

pyplot-fortran

For generating plots from Fortran using Python's matplotlib.pyplot πŸ“ˆ
Fortran
191
star
3

Fortran-Astrodynamics-Toolkit

A Modern Fortran Library for Astrodynamics πŸš€
Fortran
170
star
4

csv-fortran

Read and Write CSV Files Using Modern Fortran
Fortran
94
star
5

slsqp

Modern Fortran Edition of the SLSQP Optimizer
Fortran
87
star
6

rklib

Fixed and variable-step Runge-Kutta solvers in Modern Fortran
Fortran
71
star
7

NumDiff

Modern Fortran Numerical Differentiation Library
Fortran
65
star
8

quadpack

Modern Fortran QUADPACK Library for 1D numerical quadrature
Fortran
61
star
9

finterp

Multidimensional (1D-6D) Linear and Nearest-Neighbor Interpolation with Modern Fortran
Fortran
54
star
10

dop853

Modern Fortran Edition of Hairer's DOP853 ODE Solver. An explicit Runge-Kutta method of order 8(5,3) for problems y'=f(x,y); with dense output of order 7
Fortran
47
star
11

odepack

Work in Progress to refactor and modernize the ODEPACK Library
Fortran
44
star
12

nlesolver-fortran

Nonlinear Equation Solver with Modern Fortran
Fortran
37
star
13

pikaia

Modern Fortran Edition of the Pikaia Genetic Algorithm
Fortran
35
star
14

PowellOpt

Optimization algorithms by M.J.D. Powell
Fortran
35
star
15

roots-fortran

A modern Fortran library for finding the roots of continuous scalar functions of a single real variable, using derivative-free methods.
Fortran
34
star
16

quadrature-fortran

1D-6D Adaptive Gaussian Quadrature with Modern Fortran
Fortran
34
star
17

ddeabm

Modern Fortran implementation of the DDEABM Adams-Bashforth algorithm
Fortran
33
star
18

fortran_function_parser

Modern Fortran function parser. An update of "fparser" by Roland Schmehl
Fortran
32
star
19

flist

Modern Fortran Linked List
Fortran
31
star
20

PCHIP

Modern Fortran Piecewise Cubic Hermite Interpolation Package
Fortran
25
star
21

nswc

NSWC Mathematics Subroutine Library
Fortran
24
star
22

daglib

Directed Acyclic Graphs With Modern Fortran
Fortran
24
star
23

fortran-search-and-sort

Searching and sorting with modern Fortran
C++
24
star
24

LSQR

Modern Fortran sparse linear systems solver
Fortran
23
star
25

stl-fortran

Fortran STL File I/O
Fortran
22
star
26

simulated-annealing

Simulated Annealing with Modern Fortran
Fortran
22
star
27

polyroots-fortran

Modern Fortran library for finding the roots of real and complex polynomial equations
Fortran
22
star
28

matlab

Fortran
20
star
29

stringsort

Modern Fortran sorting routines for strings
Fortran
18
star
30

FGIF

Create Animated GIFs with Fortran
Fortran
16
star
31

astro-fortran

Modern Fortran implementations of standard models used in fundamental astronomy
Fortran
16
star
32

carlson-elliptic-integrals

Carlson symmetric forms of elliptic integrals
Fortran
14
star
33

regridpack

Modern Fortran Edition of REGRIDPACK
Fortran
13
star
34

CMLIB

NBS Core Math Library (CMLIB) Unofficial Mirror
Fortran
13
star
35

namelist2json

Converting a Fortran namelist to JSON
Fortran
12
star
36

halo

Halo orbit solver with modern Fortran
Fortran
10
star
37

uuid-fortran

Fortran module for generating UUIDs
Fortran
9
star
38

splpak

Modernized SPLPAK library for multidimensional least-squares cubic spline fitting
Fortran
8
star
39

fortran-json-python

Interfacing Fortran and Python via JSON
Fortran
8
star
40

math77

Unofficial Mirror of the JPL MATH77 Library
Fortran
8
star
41

LOM

Low Lunar Orbit Maintenance
Fortran
7
star
42

lbfgsb

Modern Fortran Refactoring of L-BFGS-B Nonlinear Optimization Code
Fortran
7
star
43

specfun

Special functions with Modern Fortran
Fortran
7
star
44

HOMPACK90

Unofficial mirror of HOMPACK90 from http://people.cs.vt.edu/~ltw/hompack/hompack90.html
Fortran
7
star
45

geodesic-fortran

Geodesic routines for Modern Fortran
Fortran
6
star
46

argv-fortran

A better get_command_argument for Fortran
Fortran
6
star
47

fastnml

Python module for reading and writing Fortran namelists
Python
6
star
48

mersenne-twister-fortran

Mersenne Twister pseudorandom number generator for Fortran
Fortran
5
star
49

fmin

Derivative free 1D function minimizer in modern Fortran
Fortran
5
star
50

LSMR

Fortran Package Manager version of LSMR: Sparse Equations and Least Squares
Fortran
5
star
51

kronrod

Program for generating Gauss-Kronrod Coefficients
Fortran
5
star
52

INPE-atmosphere-models

Fortran code for various atmosphere modes from http://www.dem.inpe.br/~val/atmod/default.html
Fortran
5
star
53

rksuite

Unofficial mirror of RKSUITE http://www.netlib.org/ode/rksuite/
Fortran
5
star
54

dvode

Modern Fortran Edition of the DVODE ODE Solver
Fortran
4
star
55

AoC-2023

Advent of Code 2023 with Modern Fortran
Fortran
4
star
56

FMLIB

Unofficial mirror of FMLIB for Multiple Precision Computations
Fortran
4
star
57

FilterSD

Unofficial mirror of FilterSD https://github.com/coin-or/filterSD
Fortran
3
star
58

conmax

Modern Fortran CONMAX Optimization Method for general nonlinearly constrained function minimization
Fortran
3
star
59

radbelt

AE-8/AP-8 Van Allen belt model in modern Fortran
Fortran
3
star
60

1976-standard-atmosphere

1976 Standard Atmosphere in Modern Fortran
Fortran
3
star
61

AoC-2021

Advent of Code 2021 with Fortran.
Fortran
3
star
62

MPFUN2015

Unofficial Mirror of MPFUN2015 from https://www.davidhbailey.com/dhbsoftware/
Fortran
3
star
63

popen-fortran

Simple Fortran module for popen
Fortran
3
star
64

IAU_SOFA

Unofficial Mirror of the IAU SOFA Fortran Library
Fortran
2
star
65

divalib

DIVA integrator from MATH77
Fortran
2
star
66

diff

Numerical Differentiation of a User Defined Function
Fortran
2
star
67

StatLib

Unofficial mirror of StatLib http://lib.stat.cmu.edu/apstat/
Fortran
2
star
68

dfo

Unofficial mirror of DFO: https://projects.coin-or.org/Dfo
Fortran
2
star
69

mpfun2020-var1

FPM Package for MPFUN2020 (var1) https://www.davidhbailey.com/dhbsoftware/
Fortran
2
star
70

fortran-mach

Modern Fortran Machine Constants Module (r1mach, d1mach, i1mach)
Fortran
1
star
71

MPFUN2020

Unofficial Mirror of MPFUN2020 from https://www.davidhbailey.com/dhbsoftware/
Fortran
1
star
72

NOVAS

Refactoring of NOVAS: Naval Observatory Vector Astrometry Subroutines
Fortran
1
star
73

SofaMerge

A simple script to make one module from all the SOFA files
Python
1
star
74

AoC-2022

Advent of Code 2022 in Fortran
Fortran
1
star
75

ffp

Unofficial mirror of Fortran Function Parser from http://www.labfit.net/functionparser.htm
Fortran
1
star
76

NRLMSIS2.1

Unofficial Mirror of NRLMSIS2.1 https://map.nrl.navy.mil/map/pub/nrl/NRLMSIS/NRLMSIS2.1/
Fortran
1
star