linear_interpolation_module Module

Multidimensional linear interpolation/extrapolation.

Uses repeated linear interpolation to evaluate functions which have been tabulated at the nodes of an n-dimensional rectangular grid. If any coordinate lies outside the range of the corresponding variable, then extrapolation is performed using the two nearest points.

Note

The default real kind (wp) can be changed using optional preprocessor flags. This library was built with real kind: real(kind=real64) [8 bytes]


Uses

  • module~~linear_interpolation_module~~UsesGraph module~linear_interpolation_module linear_interpolation_module iso_fortran_env iso_fortran_env module~linear_interpolation_module->iso_fortran_env

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: finterp_rk = real64

real kind used by this module [8 bytes]

integer, private, parameter :: wp = finterp_rk

local copy of finterp_rk with a shorter name

real(kind=wp), private, parameter :: zero = 0.0_wp

numeric constant

real(kind=wp), private, parameter :: one = 1.0_wp

numeric constant


Abstract Interfaces

abstract interface

  • private pure elemental subroutine destroy_func(me)

    interface for bspline destructor routines

    Arguments

    Type IntentOptional Attributes Name
    class(linear_interp_class), intent(inout) :: me

Derived Types

type, public ::  linear_interp_class

Base class for the linear interpolation types

Components

Type Visibility Attributes Name Initial
logical, private :: initialized = .false.

if the class was properly initialized

Type-Bound Procedures

procedure(destroy_func), public, deferred :: destroy ../../

destructor

procedure, private :: check_inputs

type, public, extends(linear_interp_class) ::  linear_interp_1d

Class for 1d linear interpolation.

Components

Type Visibility Attributes Name Initial
real(kind=wp), private, dimension(:), allocatable :: f
real(kind=wp), private, dimension(:), allocatable :: x
integer, private :: ilox = 1

Finalizations Procedures

final :: finalize_1d

Type-Bound Procedures

procedure, public :: initialize => initialize_1d
procedure, public :: evaluate => interp_1d
procedure, public :: destroy => destroy_1d

type, public, extends(linear_interp_class) ::  linear_interp_2d

Class for 2d linear interpolation.

Components

Type Visibility Attributes Name Initial
real(kind=wp), private, dimension(:,:), allocatable :: f
real(kind=wp), private, dimension(:), allocatable :: x
real(kind=wp), private, dimension(:), allocatable :: y
integer, private :: ilox = 1
integer, private :: iloy = 1

Finalizations Procedures

final :: finalize_2d

Type-Bound Procedures

procedure, public :: initialize => initialize_2d
procedure, public :: evaluate => interp_2d
procedure, public :: destroy => destroy_2d

type, public, extends(linear_interp_class) ::  linear_interp_3d

Class for 3d linear interpolation.

Components

Type Visibility Attributes Name Initial
real(kind=wp), private, dimension(:,:,:), allocatable :: f
real(kind=wp), private, dimension(:), allocatable :: x
real(kind=wp), private, dimension(:), allocatable :: y
real(kind=wp), private, dimension(:), allocatable :: z
integer, private :: ilox = 1
integer, private :: iloy = 1
integer, private :: iloz = 1

Finalizations Procedures

final :: finalize_3d

Type-Bound Procedures

procedure, public :: initialize => initialize_3d
procedure, public :: evaluate => interp_3d
procedure, public :: destroy => destroy_3d

type, public, extends(linear_interp_class) ::  linear_interp_4d

Class for 4d linear interpolation.

Components

Type Visibility Attributes Name Initial
real(kind=wp), private, dimension(:,:,:,:), allocatable :: f
real(kind=wp), private, dimension(:), allocatable :: x
real(kind=wp), private, dimension(:), allocatable :: y
real(kind=wp), private, dimension(:), allocatable :: z
real(kind=wp), private, dimension(:), allocatable :: q
integer, private :: ilox = 1
integer, private :: iloy = 1
integer, private :: iloz = 1
integer, private :: iloq = 1

Finalizations Procedures

final :: finalize_4d

Type-Bound Procedures

procedure, public :: initialize => initialize_4d
procedure, public :: evaluate => interp_4d
procedure, public :: destroy => destroy_4d

type, public, extends(linear_interp_class) ::  linear_interp_5d

Class for 5d linear interpolation.

Components

Type Visibility Attributes Name Initial
real(kind=wp), private, dimension(:,:,:,:,:), allocatable :: f
real(kind=wp), private, dimension(:), allocatable :: x
real(kind=wp), private, dimension(:), allocatable :: y
real(kind=wp), private, dimension(:), allocatable :: z
real(kind=wp), private, dimension(:), allocatable :: q
real(kind=wp), private, dimension(:), allocatable :: r
integer, private :: ilox = 1
integer, private :: iloy = 1
integer, private :: iloz = 1
integer, private :: iloq = 1
integer, private :: ilor = 1

Finalizations Procedures

final :: finalize_5d

Type-Bound Procedures

procedure, public :: initialize => initialize_5d
procedure, public :: evaluate => interp_5d
procedure, public :: destroy => destroy_5d

type, public, extends(linear_interp_class) ::  linear_interp_6d

Class for 6d linear interpolation.

Components

Type Visibility Attributes Name Initial
real(kind=wp), private, dimension(:,:,:,:,:,:), allocatable :: f
real(kind=wp), private, dimension(:), allocatable :: x
real(kind=wp), private, dimension(:), allocatable :: y
real(kind=wp), private, dimension(:), allocatable :: z
real(kind=wp), private, dimension(:), allocatable :: q
real(kind=wp), private, dimension(:), allocatable :: r
real(kind=wp), private, dimension(:), allocatable :: s
integer, private :: ilox = 1
integer, private :: iloy = 1
integer, private :: iloz = 1
integer, private :: iloq = 1
integer, private :: ilor = 1
integer, private :: ilos = 1

Finalizations Procedures

final :: finalize_6d

Type-Bound Procedures

procedure, public :: initialize => initialize_6d
procedure, public :: evaluate => interp_6d
procedure, public :: destroy => destroy_6d

type, public, extends(linear_interp_1d) ::  nearest_interp_1d

Class for 1d nearest neighbor interpolation.

Type-Bound Procedures

procedure, public :: initialize => initialize_1d
procedure, public :: destroy => destroy_1d
procedure, public :: evaluate => nearest_1d

type, public, extends(linear_interp_2d) ::  nearest_interp_2d

Class for 2d nearest neighbor interpolation.

Type-Bound Procedures

procedure, public :: initialize => initialize_2d
procedure, public :: destroy => destroy_2d
procedure, public :: evaluate => nearest_2d

type, public, extends(linear_interp_3d) ::  nearest_interp_3d

Class for 3d nearest neighbor interpolation.

Type-Bound Procedures

procedure, public :: initialize => initialize_3d
procedure, public :: destroy => destroy_3d
procedure, public :: evaluate => nearest_3d

type, public, extends(linear_interp_4d) ::  nearest_interp_4d

Class for 4d nearest neighbor interpolation.

Type-Bound Procedures

procedure, public :: initialize => initialize_4d
procedure, public :: destroy => destroy_4d
procedure, public :: evaluate => nearest_4d

type, public, extends(linear_interp_5d) ::  nearest_interp_5d

Class for 5d nearest neighbor interpolation.

Type-Bound Procedures

procedure, public :: initialize => initialize_5d
procedure, public :: destroy => destroy_5d
procedure, public :: evaluate => nearest_5d

type, public, extends(linear_interp_6d) ::  nearest_interp_6d

Class for 6d nearest neighbor interpolation.

Type-Bound Procedures

procedure, public :: initialize => initialize_6d
procedure, public :: destroy => destroy_6d
procedure, public :: evaluate => nearest_6d

Subroutines

private pure elemental subroutine finalize_1d(me)

Finalizer for a linear_interp_1d type.

Arguments

Type IntentOptional Attributes Name
type(linear_interp_1d), intent(inout) :: me

private pure elemental subroutine finalize_2d(me)

Finalizer for a linear_interp_2d type.

Arguments

Type IntentOptional Attributes Name
type(linear_interp_2d), intent(inout) :: me

private pure elemental subroutine finalize_3d(me)

Finalizer for a linear_interp_3d type.

Arguments

Type IntentOptional Attributes Name
type(linear_interp_3d), intent(inout) :: me

private pure elemental subroutine finalize_4d(me)

Finalizer for a linear_interp_4d type.

Arguments

Type IntentOptional Attributes Name
type(linear_interp_4d), intent(inout) :: me

private pure elemental subroutine finalize_5d(me)

Finalizer for a linear_interp_5d type.

Arguments

Type IntentOptional Attributes Name
type(linear_interp_5d), intent(inout) :: me

private pure elemental subroutine finalize_6d(me)

Finalizer for a linear_interp_6d type.

Arguments

Type IntentOptional Attributes Name
type(linear_interp_6d), intent(inout) :: me

private pure elemental subroutine destroy_1d(me)

Destructor for a linear_interp_1d class.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_1d), intent(inout) :: me

private pure elemental subroutine destroy_2d(me)

Destructor for a linear_interp_2d class.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_2d), intent(inout) :: me

private pure elemental subroutine destroy_3d(me)

Destructor for a linear_interp_3d class.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_3d), intent(inout) :: me

private pure elemental subroutine destroy_4d(me)

Destructor for a linear_interp_4d class.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_4d), intent(inout) :: me

private pure elemental subroutine destroy_5d(me)

Destructor for a linear_interp_5d class.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_5d), intent(inout) :: me

private pure elemental subroutine destroy_6d(me)

Destructor for a linear_interp_6d class.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_6d), intent(inout) :: me

private pure subroutine initialize_1d(me, x, f, istat)

Constructor for a linear_interp_1d class.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_1d), intent(inout) :: me
real(kind=wp), intent(in), dimension(:) :: x
real(kind=wp), intent(in), dimension(:) :: f
integer, intent(out) :: istat

0 : no problems, 1 : x is not strictly increasing, 10 : x is not equal to size(f,1), 100 : cannot use linear interpolation for only one point.

private pure subroutine initialize_2d(me, x, y, f, istat)

Constructor for a linear_interp_2d class.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_2d), intent(inout) :: me
real(kind=wp), intent(in), dimension(:) :: x
real(kind=wp), intent(in), dimension(:) :: y
real(kind=wp), intent(in), dimension(:,:) :: f
integer, intent(out) :: istat

0 : no problems, 1 : x is not strictly increasing, 2 : y is not strictly increasing, 10 : x is not equal to size(f,1), 20 : y is not equal to size(f,2), 100 : cannot use linear interpolation for only one point.

private pure subroutine initialize_3d(me, x, y, z, f, istat)

Constructor for a linear_interp_3d class.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_3d), intent(inout) :: me
real(kind=wp), intent(in), dimension(:) :: x
real(kind=wp), intent(in), dimension(:) :: y
real(kind=wp), intent(in), dimension(:) :: z
real(kind=wp), intent(in), dimension(:,:,:) :: f
integer, intent(out) :: istat

0 : no problems, 1 : x is not strictly increasing, 2 : y is not strictly increasing, 3 : z is not strictly increasing, 10 : x is not equal to size(f,1), 20 : y is not equal to size(f,2), 30 : z is not equal to size(f,3), 100 : cannot use linear interpolation for only one point.

private pure subroutine initialize_4d(me, x, y, z, q, f, istat)

Constructor for a linear_interp_4d class.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_4d), intent(inout) :: me
real(kind=wp), intent(in), dimension(:) :: x
real(kind=wp), intent(in), dimension(:) :: y
real(kind=wp), intent(in), dimension(:) :: z
real(kind=wp), intent(in), dimension(:) :: q
real(kind=wp), intent(in), dimension(:,:,:,:) :: f
integer, intent(out) :: istat

0 : no problems, 1 : x is not strictly increasing, 2 : y is not strictly increasing, 3 : z is not strictly increasing, 4 : q is not strictly increasing, 10 : x is not equal to size(f,1), 20 : y is not equal to size(f,2), 30 : z is not equal to size(f,3), 40 : q is not equal to size(f,4), 100 : cannot use linear interpolation for only one point.

private pure subroutine initialize_5d(me, x, y, z, q, r, f, istat)

Constructor for a linear_interp_5d class.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_5d), intent(inout) :: me
real(kind=wp), intent(in), dimension(:) :: x
real(kind=wp), intent(in), dimension(:) :: y
real(kind=wp), intent(in), dimension(:) :: z
real(kind=wp), intent(in), dimension(:) :: q
real(kind=wp), intent(in), dimension(:) :: r
real(kind=wp), intent(in), dimension(:,:,:,:,:) :: f
integer, intent(out) :: istat

0 : no problems, 1 : x is not strictly increasing, 2 : y is not strictly increasing, 3 : z is not strictly increasing, 4 : q is not strictly increasing, 5 : r is not strictly increasing, 10 : x is not equal to size(f,1), 20 : y is not equal to size(f,2), 30 : z is not equal to size(f,3), 40 : q is not equal to size(f,4), 50 : r is not equal to size(f,5), 100 : cannot use linear interpolation for only one point.

private pure subroutine initialize_6d(me, x, y, z, q, r, s, f, istat)

Constructor for a linear_interp_6d class.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_6d), intent(inout) :: me
real(kind=wp), intent(in), dimension(:) :: x
real(kind=wp), intent(in), dimension(:) :: y
real(kind=wp), intent(in), dimension(:) :: z
real(kind=wp), intent(in), dimension(:) :: q
real(kind=wp), intent(in), dimension(:) :: r
real(kind=wp), intent(in), dimension(:) :: s
real(kind=wp), intent(in), dimension(:,:,:,:,:,:) :: f
integer, intent(out) :: istat

0 : no problems, 1 : x is not strictly increasing, 2 : y is not strictly increasing, 3 : z is not strictly increasing, 4 : q is not strictly increasing, 5 : r is not strictly increasing, 6 : s is not strictly increasing, 10 : x is not equal to size(f,1), 20 : y is not equal to size(f,2), 30 : z is not equal to size(f,3), 40 : q is not equal to size(f,4), 50 : r is not equal to size(f,5), 60 : s is not equal to size(f,6), 100 : cannot use linear interpolation for only one point.

private pure subroutine interp_1d(me, x, f, istat)

1D linear interpolation routine.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_1d), intent(inout) :: me
real(kind=wp), intent(in) :: x
real(kind=wp), intent(out) :: f

Interpolated

integer, intent(out), optional :: istat

0 : no problems, -1 : class has not been initialized

private pure subroutine interp_2d(me, x, y, f, istat)

2D linear interpolation routine.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_2d), intent(inout) :: me
real(kind=wp), intent(in) :: x
real(kind=wp), intent(in) :: y
real(kind=wp), intent(out) :: f

Interpolated

integer, intent(out), optional :: istat

0 : no problems, -1 : class has not been initialized

private pure subroutine interp_3d(me, x, y, z, f, istat)

3D linear interpolation routine.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_3d), intent(inout) :: me
real(kind=wp), intent(in) :: x
real(kind=wp), intent(in) :: y
real(kind=wp), intent(in) :: z
real(kind=wp), intent(out) :: f

Interpolated

integer, intent(out), optional :: istat

0 : no problems, -1 : class has not been initialized

private pure subroutine interp_4d(me, x, y, z, q, f, istat)

4D linear interpolation routine.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_4d), intent(inout) :: me
real(kind=wp), intent(in) :: x
real(kind=wp), intent(in) :: y
real(kind=wp), intent(in) :: z
real(kind=wp), intent(in) :: q
real(kind=wp), intent(out) :: f

Interpolated

integer, intent(out), optional :: istat

0 : no problems, -1 : class has not been initialized

private pure subroutine interp_5d(me, x, y, z, q, r, f, istat)

5D linear interpolation routine.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_5d), intent(inout) :: me
real(kind=wp), intent(in) :: x
real(kind=wp), intent(in) :: y
real(kind=wp), intent(in) :: z
real(kind=wp), intent(in) :: q
real(kind=wp), intent(in) :: r
real(kind=wp), intent(out) :: f

Interpolated

integer, intent(out), optional :: istat

0 : no problems, -1 : class has not been initialized

private pure subroutine interp_6d(me, x, y, z, q, r, s, f, istat)

6D linear interpolation routine.

Arguments

Type IntentOptional Attributes Name
class(linear_interp_6d), intent(inout) :: me
real(kind=wp), intent(in) :: x
real(kind=wp), intent(in) :: y
real(kind=wp), intent(in) :: z
real(kind=wp), intent(in) :: q
real(kind=wp), intent(in) :: r
real(kind=wp), intent(in) :: s
real(kind=wp), intent(out) :: f

Interpolated

integer, intent(out), optional :: istat

0 : no problems, -1 : class has not been initialized

private pure subroutine dintrv(xt, x, ilo, ileft, iright, mflag, inearest)

Returns the indices in xt that bound x, to use for interpolation. If outside the range, then the indices are returned that can be used for extrapolation. Precisely,

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: xt

a knot or break point vector

real(kind=wp), intent(in) :: x

argument

integer, intent(inout) :: ilo

an initialization parameter which must be set to 1 the first time the array xt is processed by dintrv. ilo contains information for efficient processing after the initial call and ilo must not be changed by the user. each dimension requires a distinct ilo parameter.

integer, intent(out) :: ileft

left index

integer, intent(out) :: iright

right index

integer, intent(out) :: mflag

signals when x lies out of bounds

integer, intent(out), optional :: inearest

nearest index

private pure subroutine nearest_1d(me, x, f, istat)

1D nearest neighbor interpolation routine.

Arguments

Type IntentOptional Attributes Name
class(nearest_interp_1d), intent(inout) :: me
real(kind=wp), intent(in) :: x
real(kind=wp), intent(out) :: f

Nearest

integer, intent(out), optional :: istat

0 : no problems, -1 : class has not been initialized

private pure subroutine nearest_2d(me, x, y, f, istat)

2D nearest neighbor interpolation routine.

Arguments

Type IntentOptional Attributes Name
class(nearest_interp_2d), intent(inout) :: me
real(kind=wp), intent(in) :: x
real(kind=wp), intent(in) :: y
real(kind=wp), intent(out) :: f

Nearest

integer, intent(out), optional :: istat

0 : no problems, -1 : class has not been initialized

private pure subroutine nearest_3d(me, x, y, z, f, istat)

3D nearest neighbor interpolation routine.

Arguments

Type IntentOptional Attributes Name
class(nearest_interp_3d), intent(inout) :: me
real(kind=wp), intent(in) :: x
real(kind=wp), intent(in) :: y
real(kind=wp), intent(in) :: z
real(kind=wp), intent(out) :: f

Nearest

integer, intent(out), optional :: istat

0 : no problems, -1 : class has not been initialized

private pure subroutine nearest_4d(me, x, y, z, q, f, istat)

4D nearest neighbor interpolation routine.

Arguments

Type IntentOptional Attributes Name
class(nearest_interp_4d), intent(inout) :: me
real(kind=wp), intent(in) :: x
real(kind=wp), intent(in) :: y
real(kind=wp), intent(in) :: z
real(kind=wp), intent(in) :: q
real(kind=wp), intent(out) :: f

Nearest

integer, intent(out), optional :: istat

0 : no problems, -1 : class has not been initialized

private pure subroutine nearest_5d(me, x, y, z, q, r, f, istat)

5D nearest neighbor interpolation routine.

Arguments

Type IntentOptional Attributes Name
class(nearest_interp_5d), intent(inout) :: me
real(kind=wp), intent(in) :: x
real(kind=wp), intent(in) :: y
real(kind=wp), intent(in) :: z
real(kind=wp), intent(in) :: q
real(kind=wp), intent(in) :: r
real(kind=wp), intent(out) :: f

Nearest

integer, intent(out), optional :: istat

0 : no problems, -1 : class has not been initialized

private pure subroutine nearest_6d(me, x, y, z, q, r, s, f, istat)

6D nearest neighbor interpolation routine.

Arguments

Type IntentOptional Attributes Name
class(nearest_interp_6d), intent(inout) :: me
real(kind=wp), intent(in) :: x
real(kind=wp), intent(in) :: y
real(kind=wp), intent(in) :: z
real(kind=wp), intent(in) :: q
real(kind=wp), intent(in) :: r
real(kind=wp), intent(in) :: s
real(kind=wp), intent(out) :: f

Nearest

integer, intent(out), optional :: istat

0 : no problems, -1 : class has not been initialized

private pure subroutine check_inputs(me, x, y, z, q, r, s, ierr)

Check the validity of the inputs to the initialize routines. Prints warning message if there is an error, and also sets ierr (/=0 if there were any errors).

Read more…

Arguments

Type IntentOptional Attributes Name
class(linear_interp_class), intent(in) :: me
real(kind=wp), intent(in), optional, dimension(:) :: x

x abscissa vector

real(kind=wp), intent(in), optional, dimension(:) :: y

y abscissa vector

real(kind=wp), intent(in), optional, dimension(:) :: z

z abscissa vector

real(kind=wp), intent(in), optional, dimension(:) :: q

q abscissa vector

real(kind=wp), intent(in), optional, dimension(:) :: r

r abscissa vector

real(kind=wp), intent(in), optional, dimension(:) :: s

s abscissa vector

integer, intent(out) :: ierr

0 : no problems, 1 : x is not strictly increasing, 2 : y is not strictly increasing, 3 : z is not strictly increasing, 4 : q is not strictly increasing, 5 : r is not strictly increasing, 6 : s is not strictly increasing, 100 : cannot use linear interpolation for only one point.