source: trunk/SRC/Interpolation/spl_fstdrv.pro @ 232

Last change on this file since 232 was 231, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1;+
2;
3; @file_comments
4; SPL_FSTDRV returns the values of the first derivative of
5; the interpolating function at the points X2i. It is a double
6; precision array.
7;
8; Given the arrays X and Y, which tabulate a function (with the X[i]
9; AND Y[i] in ascending order), and given an input value X2, the
10; SPL_INCR function returns an interpolated value for the given values
11; of X2. The interpolation method is based on cubic spline, corrected
12; in a way that interpolated value are also in ascending order
13;
14; @examples
15; IDL> y2 =  spl_fstdrv(x, y, yscd, x2)
16;
17; @param x {in}{required}
18; An n-element (at least 2) input vector that specifies the
19; tabulate points in ascending order.
20;
21; @param y {in}{required}
22; f(x) = y. An n-element input vector that specifies the values
23; of the tabulated function F(Xi) corresponding to Xi.
24;
25; @param yscd {in}{required}
26; The output from SPL_INIT for the specified X and Y.
27;
28; @param x2 {in}{required}
29; The input values for which the first derivative values are desired.
30; X can be scalar or an array of values.
31;
32; @returns
33;    y2: f'(x2) = y2.
34;
35; @history
36;  Sebastien Masson (smasson\@lodyc.jussieu.fr): May 2005
37;
38; @version
39; $Id$
40;
41;-
42;
43FUNCTION spl_fstdrv, x, y, yscd, x2
44;
45; compute the first derivative of the spline function
46;
47  compile_opt idl2, strictarrsubs
48;
49  nx = n_elements(x)
50  ny = n_elements(y)
51; x must have at least 2 elements
52  IF nx LT 2 THEN stop
53; y must have the same number of elements than x
54  IF nx NE ny THEN stop
55; define loc in a way that
56;  if loc[i] eq -1   :                 x2[i] <  x[0]
57;  if loc[i] eq nx2-1:                 x2[i] >= x[nx-1]
58;  else              :    x[loc[i]] <= x2[i] <  x[loc[i]+1]
59  loc = value_locate(x, x2)
60; change loc in order to
61; use x[0]    and x[1]    even if x2[i] <  x[0]    -> extrapolation
62; use x[nx-2] and x[nx-1] even if x2[i] >= x[nx-1] -> extrapolation
63  loc = 0 > temporary(loc) < (nx-2)
64; distance between to consecutive x
65  deltax = x[loc+1]-x[loc]
66; distance between to consecutive y
67  deltay = y[loc+1]-y[loc]
68; relative distance between x2[i] and x[loc[i]+1]
69  a = (x[loc+1]-x2)/deltax
70; relative distance between x2[i] and x[loc[i]]
71  b = 1.0d - a
72; compute the first derivative on x (see numerical recipes Chap 3.3)
73  yfrst = temporary(deltay)/deltax $
74    - 1.0d/6.0d * (3.0d*a*a - 1.0d) * deltax * yscd[loc] $
75    + 1.0d/6.0d * (3.0d*b*b - 1.0d) * deltax * yscd[loc+1]
76; beware of the computation precision...
77; force near zero values to be exactly 0.0
78  zero = where(abs(yfrst) LT 1.e-10)
79  IF zero[0] NE -1 THEN yfrst[zero] = 0.0d
80
81  RETURN, yfrst
82END
83
Note: See TracBrowser for help on using the repository browser.