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

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

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