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

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

debug + new xxx

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME:spl_fstdrv
6;
7; PURPOSE: 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; CATEGORY:
18;
19; CALLING SEQUENCE: y2 =  spl_fstdrv(x, y, yscd, x2)
20;
21; INPUTS:
22;
23;    x: An n-element (at least 2) input vector that specifies the
24;    tabulate points in ascending order.
25;
26;    y: f(x) = y. An n-element input vector that specifies the values
27;    of the tabulated function F(Xi) corresponding to Xi.
28;
29;    yscd: The output from SPL_INIT for the specified X and Y.
30;
31;    x2: The input values for which the first derivative values are
32;    desired. X can be scalar or an array of values.
33
34; KEYWORD PARAMETERS: none
35;
36; OUTPUTS:
37;
38;    y2: f'(x2) = y2.
39;
40; COMMON BLOCKS: none
41;
42; SIDE EFFECTS: ?
43;
44; RESTRICTIONS: ?
45;
46; EXAMPLE:
47;
48; MODIFICATION HISTORY:
49;  Sebastien Masson (smasson@lodyc.jussieu.fr): May 2005
50;-
51;------------------------------------------------------------
52;------------------------------------------------------------
53;------------------------------------------------------------
54FUNCTION spl_fstdrv, x, y, yscd, x2
55;
56; compute the first derivative of the spline function;
57;
58  nx = n_elements(x)
59  ny = n_elements(y)
60; x must have at least 2 elements
61  IF nx LT 2 THEN stop   
62; y must have the same number of elements than x
63  IF nx NE ny THEN stop
64; define loc in a way that
65;  if loc[i] eq -1   :                 x2[i] <  x[0]
66;  if loc[i] eq nx2-1:                 x2[i] >= x[nx-1]
67;  else              :    x[loc[i]] <= x2[i] <  x[loc[i]+1]
68  loc = value_locate(x, x2)
69; change loc in order to
70; use x[0]    and x[1]    even if x2[i] <  x[0]    -> extrapolation
71; use x[nx-2] and x[nx-1] even if x2[i] >= x[nx-1] -> extrapolation
72  loc = 0 > temporary(loc) < (nx-2)
73; distance between to consecutive x
74  deltax = x[loc+1]-x[loc]
75; distance between to consecutive y
76  deltay = y[loc+1]-y[loc]
77; relative distance between x2[i] and x[loc[i]+1]
78  a = (x[loc+1]-x2)/deltax
79; relative distance between x2[i] and x[loc[i]]
80  b = 1.0d - a
81; compute the first derivative on x (see numerical recipes Chap 3.3)
82  yfrst = temporary(deltay)/deltax $
83    - 1.0d/6.0d * (3.0d*a*a - 1.0d) * deltax * yscd[loc] $
84    + 1.0d/6.0d * (3.0d*b*b - 1.0d) * deltax * yscd[loc+1]
85; beware of the computation precision...
86; force near zero values to be exactly 0.0
87  zero = where(abs(yfrst) LT 1.e-10)
88  IF zero[0] NE -1 THEN yfrst[zero] = 0.0d
89
90  RETURN, yfrst
91END
92
Note: See TracBrowser for help on using the repository browser.