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

Last change on this file since 177 was 134, checked in by navarro, 18 years ago

change *.pro file properties (del eof-style, del executable, set keywords Id

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