source: trunk/SRC/Interpolation/spl_incr.pro @ 260

Last change on this file since 260 was 242, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers + replace some message by some report

  • Property svn:keywords set to Id
File size: 19.3 KB
Line 
1;+
2;
3; @file_comments
4; Given the arrays X and Y, which tabulate a function (with the X[i]
5; AND Y[i] in ascending order), and given an input value X2, the
6; spl_incr function returns an interpolated value for the given values
7; of X2. The interpolation method is based on cubic spline, corrected
8; in a way that interpolated values are also monotonically increasing.
9;
10; @param x1 {in}{required}
11; An n-elements (at least 2) input vector that specifies the tabulate points in
12; a strict ascending order.
13;
14; @param y1 {in}{required}
15; f(x) = y. An n-elements input vector that specifies the values
16; of the tabulated function F(Xi) corresponding to Xi. As f is
17; supposed to be monotonically increasing, y values must be
18; monotonically increasing. y can have equal consecutive values.
19;
20; @param x2 {in}{required}
21; The input values for which the interpolated values are
22; desired. Its values must be strictly monotonically increasing.
23;
24; @param der2
25;
26; @param x
27;
28; @returns
29; y2: f(x2) = y2. Double precision array
30;
31; @restrictions
32; It might be possible that y2[i+1]-y2[i] has very small negative
33; values (amplitude smaller than 1.e-6)...
34;
35; @examples
36; IDL> n = 100L
37; IDL> x = (dindgen(n))^2
38; IDL> y = abs(randomn(0, n))
39; IDL> y[n/2:n/2+1] = 0.
40; IDL> y[n-n/3] = 0.
41; IDL> y[n-n/6:n-n/6+5] = 0.
42; IDL> y = total(y, /cumulative, /double)
43; IDL> x2 = dindgen((n-1)^2)
44; IDL> n2 = n_elements(x2)
45; IDL> print, min(y[1:n-1]-y[0:n-2]) LT 0
46; IDL> y2 = spl_incr( x, y, x2)
47; IDL> splot, x, y, xstyle = 1, ystyle = 1, ysurx=.25, petit = [1, 2, 1], /land
48; IDL> oplot, x2, y2, color = 100
49; IDL> c = y2[1:n2-1] - y2[0:n2-2]
50; IDL> print, min(c) LT 0
51; IDL> print, min(c, max = ma), ma
52; IDL> splot,c,xstyle=1,ystyle=1, yrange=[-.01,.05], ysurx=.25, petit = [1, 2, 2], /noerase
53; IDL> oplot,[0, n_elements(c)], [0, 0], linestyle = 1
54;
55; @history
56;  Sebastien Masson (smasson\@lodyc.jussieu.fr): May-Dec 2005
57;
58; @version
59; $Id$
60;
61;-
62;
63FUNCTION pure_concave, x1, x2, y1, y2, der2, x
64;
65  compile_opt idl2, strictarrsubs
66;
67; X^n type
68;
69  xx = (double(x)-double(x1))/(double(x2)-double(x1))
70  f = (double(x2)-double(x1))/(double(y2)-double(y1))
71  n = der2*temporary(f)
72  res = xx^(n)
73;   IF check_math() GT 0 THEN BEGIN
74;       zero = where(abs(res) LT 1.e-10)
75;       IF zero[0] NE -1 THEN res[zero] = 0.0d
76;   END
77  res = temporary(res)*(double(y2)-double(y1))+y1
78;
79;  IF array_equal(sort(res), lindgen(n_elements(res)) ) NE 1 THEN stop
80  RETURN, res
81END
82;
83;+
84;
85; @param x1 {in}{required}
86; An n-elements (at least 2) input vector that specifies the tabulate points in
87; a strict ascending order.
88;
89; @param y1 {in}{required}
90; f(x) = y. An n-elements input vector that specifies the values
91;    of the tabulated function F(Xi) corresponding to Xi. As f is
92;    supposed to be monotonically increasing, y values must be
93;    monotonically increasing. y can have equal consecutive values.
94;
95; @param x2 {in}{required}
96; The input values for which the interpolated values are
97; desired. Its values must be strictly monotonically increasing.
98;
99; @param der2
100;
101; @param x
102;
103;-
104;
105FUNCTION pure_convex, x1, x2, y1, y2, der2, x
106;
107  compile_opt idl2, strictarrsubs
108;
109; 1-(1-X)^n type
110;
111  xx = 1.0d - (double(x)-double(x1))/(double(x2)-double(x1))
112  f = (double(x2)-double(x1))/(double(y2)-double(y1))
113  n = der2*temporary(f)
114  res = xx^(n)
115;   IF check_math() GT 0 THEN BEGIN
116;       zero = where(abs(res) LT 1.e-10)
117;       IF zero[0] NE -1 THEN res[zero] = 0.0d
118;   END
119  res = 1.0d - temporary(res)
120  res = temporary(res)*(y2-y1)+y1
121;
122;  IF array_equal(sort(res), lindgen(n_elements(res)) ) NE 1 THEN stop
123  RETURN, res
124END
125;
126;+
127;
128; @param x
129; @param y
130; @param x2
131; @keyword YP0
132; The first derivative of the interpolating function at the
133;    point X0. If YP0 is omitted, the second derivative at the
134;    boundary is set to zero, resulting in a "natural spline."
135;
136; @keyword YPN_1
137; The first derivative of the interpolating function at the
138;    point Xn-1. If YPN_1 is omitted, the second derivative at the
139;    boundary is set to zero, resulting in a "natural spline."
140;-
141;
142FUNCTION spl_incr, x, y, x2, YP0 = yp0, YPN_1 = ypn_1
143;
144  compile_opt idl2, strictarrsubs
145;
146;---------------------------------
147; check and initialization ...
148;---------------------------------
149;
150  nx = n_elements(x)
151  ny = n_elements(y)
152  nx2 = n_elements(x2)
153; x must have at least 2 elements
154  IF nx LT 2 THEN stop
155; y must have the same number of elements than x
156  IF nx NE ny THEN stop
157; x be monotonically increasing
158  IF min(x[1:nx-1]-x[0:nx-2]) LE 0 THEN stop
159; x2 be monotonically increasing
160  IF N_ELEMENTS(X2) GE 2 THEN $
161  IF min(x2[1:nx2-1]-x2[0:nx2-2])  LE 0 THEN stop
162; y be monotonically increasing
163  IF min(y[1:ny-1]-y[0:ny-2]) LT 0 THEN stop
164;---------------------------------
165; first check: check if two consecutive values are equal
166;---------------------------------
167  bad = where(y[1:ny-1]-y[0:ny-2] EQ 0, cntbad)
168  IF cntbad NE 0 THEN BEGIN
169; define the results: y2
170      y2 = dblarr(nx2)
171; define xinx2: see help of value_locate
172;  if xinx2[i] eq -1   :                 x[bad[i]] <  x2[0]
173;  if xinx2[i] eq nx2-1:                 x[bad[i]] >= x2[nx2-1]
174;  else                : x2[xinx2[i]] <= x[bad[i]] <  x2[xinx2[i]+1]
175    xinx2 = value_locate(x2, x[bad])
176    xinx2_1 = value_locate(x2, x[bad+1])
177;
178; left side ... if there is x2 values smaller that x[bad[0]].
179; we force ypn_1 = 0.0d
180    IF xinx2[0] NE -1 THEN BEGIN
181      IF bad[0] EQ 0 THEN BEGIN
182        IF xinx2[0] NE 0 THEN stop
183        y2[0] = y[0]
184      ENDIF ELSE BEGIN
185        y2[0:xinx2[0]] $
186          = spl_incr(x[0:bad[0]], y[0:bad[0]], x2[0:xinx2[0]] $
187                     , yp0 = yp0, ypn_1 = 0.0d)
188      ENDELSE
189    ENDIF
190; flat section
191    IF xinx2_1[0] NE -1 THEN $
192      y2[(xinx2[0]+1) < xinx2_1[0] : xinx2_1[0]] = y[bad[0]]
193; middle pieces ... if cntbad gt 1 then we have to cut spl_incr in
194; more than 2 pieces...
195      IF cntbad GT 1 THEN BEGIN
196; we take care of the piece located wetween bad[ib-1]+1 and bad[ib]
197        FOR ib = 1, cntbad-1 DO BEGIN
198; if there is x2 values smaller that x[bad[ib]], then the x2 values
199; located between bad[ib-1]+1 and bad[ib] are (xinx2_1[ib-1]+1:xinx2[ib]
200; and if we don't have two consecutive flat sections
201          IF xinx2[ib] NE -1 AND (bad[ib-1] NE bad[ib]-1) THEN begin
202            y2[(xinx2_1[ib-1]+1) < xinx2[ib]:xinx2[ib]] $
203              = spl_incr(x[bad[ib-1]+1:bad[ib]], y[bad[ib-1]+1:bad[ib]] $
204                         , x2[(xinx2_1[ib-1]+1) < xinx2[ib]:xinx2[ib]] $
205                         , yp0 = 0.0d, ypn_1 = 0.0d)
206          ENDIF
207; flat section
208          IF xinx2_1[ib] NE -1 THEN $
209            y2[(xinx2[ib]+1) < xinx2_1[ib] : xinx2_1[ib]] = y[bad[ib]]
210        ENDFOR
211      ENDIF
212; right side ... if there is x2 values larger that x[bad[cntbad-1]+1].
213; we force yp0 = 0.0d
214      IF xinx2_1[cntbad-1] NE nx2-1 THEN $
215        y2[xinx2_1[cntbad-1]+1:nx2-1] $
216        = spl_incr(x[bad[cntbad-1]+1:nx-1], y[bad[cntbad-1]+1:nx-1] $
217                        , x2[xinx2_1[cntbad-1]+1:nx2-1] $
218                        , yp0 = 0.0d, ypn_1 = ypn_1new)
219
220    RETURN, y2
221
222  ENDIF
223;-----------
224; compute the second derivative of the cubic spline on each x.
225;-----------
226  yscd = spl_init(x, y, yp0 = yp0, ypn_1 = ypn_1, /double)
227;---------------------------------
228; second check: none of the first derivative on x values must be negative.
229;---------------------------------
230;
231; compute the first derivative on x
232;
233  yifrst = spl_fstdrv(x, y, yscd, x)
234;
235; we force the negative first derivative to 0 by calling again
236; spl_incr with the keywords yp0 and ypn_1 to specify the
237; first derivative equal to 0
238;
239  bad = where(yifrst LT 0.0d, cntbad)
240  IF cntbad NE 0 THEN BEGIN
241;
242; we define the new values of the keyword ypn_1:
243; if the first derivative of the last value of x is negative
244; we define the new values of the keyword ypn_1 to 0.0d0
245    IF bad[cntbad-1] EQ nx-1 THEN BEGIN
246      ypn_1new = 0.0d
247; we remove this case from the list
248      IF cntbad GE 2 THEN bad = bad[0:cntbad-2]
249      cntbad = cntbad-1
250; else we take the value of ypn_1 if it was already defined
251    ENDIF ELSE IF n_elements(ypn_1) NE 0 THEN ypn_1new = ypn_1
252;
253; we define the new values of the keyword yp0:
254; if the first derivative of the first value of x is negative
255; we define the new values of the keyword yp0 to 0.0
256    IF bad[0] EQ 0 THEN BEGIN
257      yp0new = 0.0d
258; we remove this case from the list
259      IF cntbad GE 2 THEN bad = bad[1:cntbad-1]
260      cntbad = cntbad-1
261; else we take the value of yp0 if it was already defined
262    ENDIF ELSE IF n_elements(yp0) NE 0 THEN yp0new = yp0
263;
264; if all the negative derivative corresponded to one of the cases above,
265; then we can directly call spl_incr with the new yp0new and ypn_1new
266    IF cntbad LE 0 THEN BEGIN
267      y2 = spl_incr(x, y, x2, yp0 = yp0new, ypn_1 = ypn_1new)
268;
269; else: there is still cases with negative derivative ...
270; we will cut spl_incr in n spl_incr and specify yp0, ypn_1
271; for each of this n spl_incr
272    ENDIF ELSE BEGIN
273; define xinx2: see help of value_locate
274;  if xinx2[i] eq -1   :                 x[bad[i]] <  x2[0]
275;  if xinx2[i] eq nx2-1:                 x[bad[i]] >= x2[nx2-1]
276;  else                : x2[xinx2[i]] <= x[bad[i]] <  x2[xinx2[i]+1]
277      xinx2 = value_locate(x2, x[bad])
278      y2 = dblarr(nx2)
279; left side ... if there is x2 values smaller that x[bad[0]].
280; we force ypn_1 = 0.0d
281      IF xinx2[0] NE -1 THEN $
282        y2[0:xinx2[0]] $
283        = spl_incr(x[0:bad[0]], y[0:bad[0]], x2[0:xinx2[0]] $
284                        , yp0 = yp0new, ypn_1 = 0.0d)
285; middle pieces ... if cntbad gt 1 then we have to cut spl_incr in
286; more than 2 pieces -> we have middle pieces for which
287; we force yp0 = 0.0d and ypn_1 = 0.0d
288      IF cntbad GT 1 THEN BEGIN
289; we take care of the piece located wetween bad[ib-1] and bad[ib]
290        FOR ib = 1, cntbad-1 DO BEGIN
291; if there is x2 values smaller that x[bad[ib]], then the x2 values
292; located between bad[ib-1] and bad[ib] are (xinx2[ib-1]+1:xinx2[ib]
293          IF xinx2[ib] NE -1 THEN begin
294            y2[(xinx2[ib-1]+1) < xinx2[ib]:xinx2[ib]] $
295              = spl_incr(x[bad[ib-1]:bad[ib]], y[bad[ib-1]:bad[ib]] $
296                              , x2[(xinx2[ib-1]+1) < xinx2[ib]:xinx2[ib]] $
297                              , yp0 = 0.0d, ypn_1 = 0.0d)
298          endif
299        ENDFOR
300      ENDIF
301; right side ... if there is x2 values larger that x[bad[cntbad-1]].
302; we force yp0 = 0.0d
303      IF xinx2[cntbad-1] NE nx2-1 THEN $
304        y2[xinx2[cntbad-1]+1:nx2-1] $
305        = spl_incr(x[bad[cntbad-1]:nx-1], y[bad[cntbad-1]:nx-1] $
306                        , x2[xinx2[cntbad-1]+1:nx2-1] $
307                        , yp0 = 0.0d, ypn_1 = ypn_1new)
308    ENDELSE
309; we return the checked and corrected value of yfrst
310;       FOR i = 0, nx-1 DO BEGIN
311;         same = where(abs(x2- x[i]) LT 1.e-10, cnt)
312; ;        IF cnt NE 0 THEN y2[same] = y[i]
313;       ENDFOR
314    RETURN, y2
315  ENDIF
316;
317; we can be in this part of the code only if:
318;  (1) spl_incr is called by itself
319;  (2) none are the first derivative in x are negative (because they have been
320;      checked and corrected by the previous call to spl_incr, see above)
321;---------------------------------
322; third check: we have to make sure that the first derivative cannot
323;               have negative values between on x[0] and x[nx-1]
324;---------------------------------
325;
326; first we compute the first derivative, next we correct the values
327; where we know that the first derivative can be negative.
328;
329  y2 = spl_interp(x, y, yscd, x2, /double)
330;
331; between x[i] and x[i+1], the cubic spline is a cubic function:
332; y  =  a*X^3 +  b*X^2 + c*X + d
333; y' = 3a*X^2 + 2b*X   + c
334; y''= 6a*X   + 2b
335; if we take X = x[i+1]-x[i] then
336;    d = y[i]; c = y'[i]; b = 0.5 * y''[i],
337;    a = 1/6 * (y''[i+1]-y''[i])/(x[i+1]-x[i])
338;
339; y'[i] and y'[i+1] are positive so y' can be negative
340; between x[i] and x[i+1] only if
341;   1) a > 0
342;            ==> y''[i+1] > y''[i]
343;   2) y' reach its minimum value between  x[i] and x[i+1]
344;      -> 0 < - b/(3a) < x[i+1]-x[i]
345;            ==> y''[i+1] > 0 > y''[i]
346;
347; we do a first selection by looking for those points...
348;
349  loc = lindgen(nx-1)
350  maybebad = where(yscd[loc] LE 0.0d AND yscd[loc+1] GE 0.0d, cntbad)
351;
352  IF cntbad NE 0 THEN BEGIN
353
354    mbbloc = loc[maybebad]
355
356    aaa = (yscd[mbbloc+1]-yscd[mbbloc])/(6.0d*(x[mbbloc+1]-x[mbbloc]))
357    bbb = 0.5d * yscd[mbbloc]
358    ccc = yifrst[mbbloc]
359    ddd = y[mbbloc]
360;
361; definitive selection:
362; y' can become negative if and only if (2b)^2 - 4(3a)c > 0
363; y' can become negative if and only if    b^2  - (3a)c > 0
364;
365    delta = bbb*bbb - 3.0d*aaa*ccc
366;
367    bad = where(delta GT 0, cntbad)
368;
369    IF cntbad NE 0 THEN BEGIN
370      delta = delta[bad]
371      aaa = aaa[bad]
372      bbb = bbb[bad]
373      ccc = ccc[bad]
374      ddd = ddd[bad]
375      bad = maybebad[bad]
376; define xinx2_1: see help of value_locate
377;  if xinx2_1[i] eq -1   :                   x[bad[i]] <  x2[0]
378;  if xinx2_1[i] eq nx2-1:                   x[bad[i]] >= x2[nx2-1]
379;  else                  : x2[xinx2_1[i]] <= x[bad[i]] <  x2[xinx2_1[i]+1]
380      xinx2_1 = value_locate(x2, x[bad])
381; define xinx2_2: see help of value_locate
382;  if xinx2_2[i] eq -1   :                   x[bad[i]+1] <  x2[0]
383;  if xinx2_2[i] eq nx2-1:                   x[bad[i]+1] >= x2[nx2-1]
384;  else                  : x2[xinx2_2[i]] <= x[bad[i]+1] <  x2[xinx2_2[i]+1]
385      xinx2_2 = value_locate(x2, x[bad+1])
386; to avoid the particular case when x2 = x[bad[i]]
387; and there is no other x2 point until x[bad[i]+1]
388      xinx2_1 = xinx2_1 < (xinx2_2-1)
389;
390      FOR ib = 0, cntbad-1 DO BEGIN
391;
392; at least one of the x2 points must be located between
393; x[bad[ib]] and x[bad[ib]+1]
394        IF x2[0] LE x[bad[ib]+1] AND x2[nx2-1] GE x[bad[ib]] THEN BEGIN
395;
396          CASE 1 OF
397            yifrst[bad[ib]+1] EQ 0.0d:BEGIN
398; case pur convex: we use the first derivative of 1-(1-x)^n
399; and ajust n to get the good value: yifrst[bad[ib]] in x[bad[ib]]
400              y2[xinx2_1[ib]+1:xinx2_2[ib]] $
401                = pure_convex(x[bad[ib]], x[bad[ib]+1] $
402                              , y[bad[ib]], y[bad[ib]+1]  $
403                              , yifrst[bad[ib]] $
404                              , x2[xinx2_1[ib]+1:xinx2_2[ib]])
405            END
406            yifrst[bad[ib]] EQ 0.0d:BEGIN
407; case pur concave: we use the first derivative of x^n
408; and ajust n to get the good value: yifrst[bad[ib]+1] in x[bad[ib]+1]
409              y2[xinx2_1[ib]+1:xinx2_2[ib]] $
410                = pure_concave(x[bad[ib]], x[bad[ib]+1] $
411                               , y[bad[ib]], y[bad[ib]+1] $
412                               , yifrst[bad[ib]+1] $
413                               , x2[xinx2_1[ib]+1:xinx2_2[ib]])
414            END
415            ELSE:BEGIN
416; in those cases, the first derivative has 2 zero between
417; x[bad[ib]] and x[bad[ib]+1]. We look for the minimum value of the
418; first derivative that correspond to the inflection point of y
419              xinfl = -bbb[ib]/(3.0d*aaa[ib])
420; we compute the y value for xinfl
421              yinfl = aaa[ib]*xinfl*xinfl*xinfl + bbb[ib]*xinfl*xinfl $
422                + ccc[ib]*xinfl + ddd[ib]
423;
424              CASE 1 OF
425; if y[xinfl] smaller than y[bad[ib]] then we conserve y2 until
426; the first zero of y2 and from this point we use x^n and ajust n to
427; get the good value: yifrst[bad[ib]+1] in x[bad[ib]+1]
428                yinfl LT y[bad[ib]]:BEGIN
429; value of the first zero (y'[xzero]=0)
430                  xzero = (-bbb[ib]-sqrt(delta[ib]))/(3.0d*aaa[ib])
431; value of y[xzero]...
432                  yzero = aaa[ib]*xzero*xzero*xzero + bbb[ib]*xzero*xzero $
433                    + ccc[ib]*xzero + ddd[ib]
434; if yzero > y[bad[ib]+1] then we cannot applay the method we want to
435; apply => we use then convex-concave case by changing by hand the
436; value of yinfl and xinfl
437                  IF yzero GT y[bad[ib]+1] THEN BEGIN
438                    yinfl = 0.5d*(y[bad[ib]+1]+y[bad[ib]])
439                    xinfl = 0.5d*(x[bad[ib]+1]-x[bad[ib]])
440                    GOTO, convexconcave
441                  ENDIF
442; define xinx2_3: see help of value_locate
443;  if xinx2_3[ib] eq -1   :                x[bad[ib]]+xzero <  x2[0]
444;  if xinx2_3[ib] eq nx2-1:                x[bad[ib]]+xzero >= x2[nx2-1]
445;  else                   : x2[xinx2_3] <= x[bad[ib]]+xzero <  x2[xinx3_2+1]
446                  xinx2_3 = value_locate(x2, x[bad[ib]]+xzero)
447; to avoid the particular case when x2 = x[bad[ib]]+xzero
448; and there is no other x2 point until x[bad[ib]+1]
449                  xinx2_3 = xinx2_3 < (xinx2_2[ib]-1)
450                  IF xinx2_2[ib] GE xinx2_3+1 THEN BEGIN
451                    y2[xinx2_3+1:xinx2_2[ib]] $
452                      = pure_concave(x[bad[ib]]+xzero, x[bad[ib]+1] $
453                                     , yzero, y[bad[ib]+1] $
454                                     , yifrst[bad[ib]+1] $
455                                     , x2[xinx2_3+1:xinx2_2[ib]])
456                  ENDIF
457                END
458; if y[xinfl] bigger than y[bad[ib]+1] then we conserve y2 from
459; the second zero of y2 and before this point we use 1-(1-x)^n and
460; ajust n to get the good value: yifrst[bad[ib]] in x[bad[ib]]
461                yinfl GT y[bad[ib]+1]:BEGIN
462; value of the second zero (y'[xzero]=0)
463                  xzero = (-bbb[ib]+sqrt(delta[ib]))/(3.0d*aaa[ib])
464; value of y[xzero]...
465                  yzero = aaa[ib]*xzero*xzero*xzero + bbb[ib]*xzero*xzero $
466                    + ccc[ib]*xzero + ddd[ib]
467; if yzero < y[bad[ib]] then we cannot applay the method we want to
468; apply => we use then convex-concave case by changing by hand the
469; value of yinfl and xinfl
470                  IF yzero lt y[bad[ib]] THEN BEGIN
471                    yinfl = 0.5d*(y[bad[ib]+1]+y[bad[ib]])
472                    xinfl = 0.5d*(x[bad[ib]+1]-x[bad[ib]])
473                    GOTO, convexconcave
474                  ENDIF
475; define xinx2_3: see help of value_locate
476;  if xinx2_3[ib] eq -1   :                x[bad[ib]]+xzero <  x2[0]
477;  if xinx2_3[ib] eq nx2-1:                x[bad[ib]]+xzero >= x2[nx2-1]
478;  else                   : x2[xinx2_3] <= x[bad[ib]]+xzero <  x2[xinx3_2+1]
479                  xinx2_3 = value_locate(x2, x[bad[ib]]+xzero)
480                  IF xinx2_3 ge xinx2_1[ib]+1 THEN BEGIN
481                    y2[xinx2_1[ib]+1:xinx2_3] $
482                      = pure_convex(x[bad[ib]], x[bad[ib]]+xzero  $
483                                    , y[bad[ib]], yzero   $
484                                    , yifrst[bad[ib]] $
485                                    , x2[xinx2_1[ib]+1:xinx2_3])
486                  ENDIF
487                END
488                ELSE:BEGIN
489convexconcave:
490; define xinx2_3: see help of value_locate
491;  if xinx2_3[ib] eq -1   :                x[bad[ib]]+xzero <  x2[0]
492;  if xinx2_3[ib] eq nx2-1:                x[bad[ib]]+xzero >= x2[nx2-1]
493;  else                   : x2[xinx2_3] <= x[bad[ib]]+xzero <  x2[xinx3_2+1]
494                  xinx2_3 = value_locate(x2, x[bad[ib]]+xinfl)
495
496                  IF xinx2_3 ge xinx2_1[ib]+1 THEN BEGIN
497                    y2[xinx2_1[ib]+1:xinx2_3] $
498                      = pure_convex(x[bad[ib]], x[bad[ib]]+xinfl  $
499                                    , y[bad[ib]], yinfl  $
500                                    , yifrst[bad[ib]] $
501                                    , x2[xinx2_1[ib]+1:xinx2_3])
502
503                  ENDIF
504                  IF xinx2_2[ib] GE xinx2_3+1 THEN BEGIN
505                    y2[xinx2_3+1:xinx2_2[ib]] $
506                      = pure_concave(x[bad[ib]]+xinfl, x[bad[ib]+1] $
507                                     , yinfl, y[bad[ib]+1] $
508                                     , yifrst[bad[ib]+1] $
509                                     , x2[xinx2_3+1:xinx2_2[ib]])
510                  ENDIF
511                END
512              ENDCASE
513
514            END
515          ENDCASE
516        ENDIF
517      ENDFOR
518
519    ENDIF
520  ENDIF
521;
522  RETURN, y2
523;
524END
Note: See TracBrowser for help on using the repository browser.