gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
pchim.c
Go to the documentation of this file.
1 /* pchim.f -- translated by f2c (version 20061008).
2  You must link the resulting object file with libf2c:
3  on Microsoft Windows system, link with libf2c.lib;
4  on Linux or Unix systems, link with .../path/to/libf2c.a -lm
5  or, if you install libf2c.a in a standard place, with -lf2c -lm
6  -- in that order, at the end of the command line, as in
7  cc *.o -lf2c -lm
8  Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
9 
10  http://www.netlib.org/f2c/libf2c.zip
11 */
12 
13 #include "f2c.h"
14 
15 /* Table of constant values */
16 
17 static integer c__1 = 1;
18 
19 /* $Author: ulammers $ */
20 /* $Date: 1997/02/14 14:13:13 $ */
21 /* $Id: pchim.f,v 1.1 1997/02/14 14:13:13 ulammers Exp $ */
22 /* $Source: /usr4/users/aparmar/SAXDAS/pipeline/LE_lemat/RCS/pchim.f,v $ */
23 
24 /* --- SLATEC ROUTINES --------------------------------------------- */
25 
26 /* PCHIM */
27 /* PCHFE */
28 /* PCHST */
29 /* CHFEV */
30 
31 /* XERMSG - this is a subsidiary routine used by all the above to */
32 /* output error messages. Here it simply calls FTOOL's */
33 /* FCERR. */
34 /* ----------------------------------------------------------------- */
35 
36 /* DECK PCHIM */
37 /* Subroutine */ int pchim_(integer *n, real *x, real *f, real *d__, integer *
38  incfd, integer *ierr)
39 {
40  /* Initialized data */
41 
42  static real zero = 0.f;
43  static real three = 3.f;
44 
45  /* System generated locals */
46  integer f_dim1, f_offset, d_dim1, d_offset, i__1;
47  real r__1, r__2;
48 
49  /* Local variables */
50  static integer i__;
51  static real h1, h2, w1, w2, del1, del2, dmin__, dmax__, hsum, drat1,
52  drat2, dsave;
53  extern doublereal pchst_(real *, real *);
54  static integer nless1;
55  static real hsumt3;
56  extern /* Subroutine */ int xermsg_(char *, char *, char *, integer *,
57  integer *, ftnlen, ftnlen, ftnlen);
58 
59 /* ***BEGIN PROLOGUE PCHIM */
60 /* ***PURPOSE Set derivatives needed to determine a monotone piecewise */
61 /* cubic Hermite interpolant to given data. Boundary values */
62 /* are provided which are compatible with monotonicity. The */
63 /* interpolant will have an extremum at each point where mono- */
64 /* tonicity switches direction. (See PCHIC if user control is */
65 /* desired over boundary or switch conditions.) */
66 /* ***LIBRARY SLATEC (PCHIP) */
67 /* ***CATEGORY E1A */
68 /* ***TYPE SINGLE PRECISION (PCHIM-S, DPCHIM-D) */
69 /* ***KEYWORDS CUBIC HERMITE INTERPOLATION, MONOTONE INTERPOLATION, */
70 /* PCHIP, PIECEWISE CUBIC INTERPOLATION */
71 /* ***AUTHOR Fritsch, F. N., (LLNL) */
72 /* Lawrence Livermore National Laboratory */
73 /* P.O. Box 808 (L-316) */
74 /* Livermore, CA 94550 */
75 /* FTS 532-4275, (510) 422-4275 */
76 /* ***DESCRIPTION */
77 
78 /* PCHIM: Piecewise Cubic Hermite Interpolation to */
79 /* Monotone data. */
80 
81 /* Sets derivatives needed to determine a monotone piecewise cubic */
82 /* Hermite interpolant to the data given in X and F. */
83 
84 /* Default boundary conditions are provided which are compatible */
85 /* with monotonicity. (See PCHIC if user control of boundary con- */
86 /* ditions is desired.) */
87 
88 /* If the data are only piecewise monotonic, the interpolant will */
89 /* have an extremum at each point where monotonicity switches direc- */
90 /* tion. (See PCHIC if user control is desired in such cases.) */
91 
92 /* To facilitate two-dimensional applications, includes an increment */
93 /* between successive values of the F- and D-arrays. */
94 
95 /* The resulting piecewise cubic Hermite function may be evaluated */
96 /* by PCHFE or PCHFD. */
97 
98 /* ---------------------------------------------------------------------- */
99 
100 /* Calling sequence: */
101 
102 /* PARAMETER (INCFD = ...) */
103 /* INTEGER N, IERR */
104 /* REAL X(N), F(INCFD,N), D(INCFD,N) */
105 
106 /* CALL PCHIM (N, X, F, D, INCFD, IERR) */
107 
108 /* Parameters: */
109 
110 /* N -- (input) number of data points. (Error RETURN if N.LT.2 .) */
111 /* If N=2, simply does linear interpolation. */
112 
113 /* X -- (input) real array of independent variable values. The */
114 /* elements of X must be strictly increasing: */
115 /* X(I-1) .LT. X(I), I = 2(1)N. */
116 /* (Error RETURN if not.) */
117 
118 /* F -- (input) real array of dependent variable values to be inter- */
119 /* polated. F(1+(I-1)*INCFD) is value corresponding to X(I). */
120 /* PCHIM is designed for monotonic data, but it will work for */
121 /* any F-array. It will force extrema at points where mono- */
122 /* tonicity switches direction. If some other treatment of */
123 /* switch points is desired, PCHIC should be used instead. */
124 /* ----- */
125 /* D -- (output) real array of derivative values at the data points. */
126 /* If the data are monotonic, these values will determine a */
127 /* a monotone cubic Hermite function. */
128 /* The value corresponding to X(I) is stored in */
129 /* D(1+(I-1)*INCFD), I=1(1)N. */
130 /* No other entries in D are changed. */
131 
132 /* INCFD -- (input) increment between successive values in F and D. */
133 /* This argument is provided primarily for 2-D applications. */
134 /* (Error RETURN if INCFD.LT.1 .) */
135 
136 /* IERR -- (output) error flag. */
137 /* Normal RETURN: */
138 /* IERR = 0 (no errors). */
139 /* Warning error: */
140 /* IERR.GT.0 means that IERR switches in the direction */
141 /* of monotonicity were detected. */
142 /* "Recoverable" errors: */
143 /* IERR = -1 if N.LT.2 . */
144 /* IERR = -2 if INCFD.LT.1 . */
145 /* IERR = -3 if the X-array is not strictly increasing. */
146 /* (The D-array has not been changed in any of these cases.) */
147 /* NOTE: The above errors are checked in the order listed, */
148 /* and following arguments have **NOT** been validated. */
149 
150 /* ***REFERENCES 1. F. N. Fritsch and J. Butland, A method for construc- */
151 /* ting local monotone piecewise cubic interpolants, SIAM */
152 /* Journal on Scientific and Statistical Computing 5, 2 */
153 /* (June 1984), pp. 300-304. */
154 /* 2. F. N. Fritsch and R. E. Carlson, Monotone piecewise */
155 /* cubic interpolation, SIAM Journal on Numerical Ana- */
156 /* lysis 17, 2 (April 1980), pp. 238-246. */
157 /* ***ROUTINES CALLED PCHST, XERMSG */
158 /* ***REVISION HISTORY (YYMMDD) */
159 /* 811103 DATE WRITTEN */
160 /* 820201 1. Introduced PCHST to reduce possible over/under- */
161 /* flow problems. */
162 /* 2. Rearranged derivative formula for same reason. */
163 /* 820602 1. Modified end conditions to be continuous functions */
164 /* of data when monotonicity switches in next interval. */
165 /* 2. Modified formulas so end conditions are less prone */
166 /* of over/underflow problems. */
167 /* 820803 Minor cosmetic changes for release 1. */
168 /* 870813 Updated Reference 1. */
169 /* 890411 Added SAVE statements (Vers. 3.2). */
170 /* 890531 Changed all specific intrinsics to generic. (WRB) */
171 /* 890703 Corrected category record. (WRB) */
172 /* 890831 Modified array declarations. (WRB) */
173 /* 890831 REVISION DATE from Version 3.2 */
174 /* 891214 Prologue converted to Version 4.0 format. (BAB) */
175 /* 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ) */
176 /* 920429 Revised format and order of references. (WRB,FNF) */
177 /* ***END PROLOGUE PCHIM */
178 /* Programming notes: */
179 
180 /* 1. The function PCHST(ARG1,ARG2) is assumed to RETURN zero if */
181 /* either argument is zero, +1 if they are of the same sign, and */
182 /* -1 if they are of opposite sign. */
183 /* 2. To produce a double precision version, simply: */
184 /* a. Change PCHIM to DPCHIM wherever it occurs, */
185 /* b. Change PCHST to DPCHST wherever it occurs, */
186 /* c. Change all references to the Fortran intrinsics to their */
187 /* double precision equivalents, */
188 /* d. Change the real declarations to double precision, and */
189 /* e. Change the constants ZERO and THREE to double precision. */
190 
191 /* DECLARE ARGUMENTS. */
192 
193 
194 /* DECLARE LOCAL VARIABLES. */
195 
196  /* Parameter adjustments */
197  --x;
198  d_dim1 = *incfd;
199  d_offset = 1 + d_dim1;
200  d__ -= d_offset;
201  f_dim1 = *incfd;
202  f_offset = 1 + f_dim1;
203  f -= f_offset;
204 
205  /* Function Body */
206 
207 /* VALIDITY-CHECK ARGUMENTS. */
208 
209 /* ***FIRST EXECUTABLE STATEMENT PCHIM */
210  if (*n < 2) {
211  goto L5001;
212  }
213  if (*incfd < 1) {
214  goto L5002;
215  }
216  i__1 = *n;
217  for (i__ = 2; i__ <= i__1; ++i__) {
218  if (x[i__] <= x[i__ - 1]) {
219  goto L5003;
220  }
221 /* L1: */
222  }
223 
224 /* FUNCTION DEFINITION IS OK, GO ON. */
225 
226  *ierr = 0;
227  nless1 = *n - 1;
228  h1 = x[2] - x[1];
229  del1 = (f[(f_dim1 << 1) + 1] - f[f_dim1 + 1]) / h1;
230  dsave = del1;
231 
232 /* SPECIAL CASE N=2 -- USE LINEAR INTERPOLATION. */
233 
234  if (nless1 > 1) {
235  goto L10;
236  }
237  d__[d_dim1 + 1] = del1;
238  d__[*n * d_dim1 + 1] = del1;
239  goto L5000;
240 
241 /* NORMAL CASE (N .GE. 3). */
242 
243 L10:
244  h2 = x[3] - x[2];
245  del2 = (f[f_dim1 * 3 + 1] - f[(f_dim1 << 1) + 1]) / h2;
246 
247 /* SET D(1) VIA NON-CENTERED THREE-POINT FORMULA, ADJUSTED TO BE */
248 /* SHAPE-PRESERVING. */
249 
250  hsum = h1 + h2;
251  w1 = (h1 + hsum) / hsum;
252  w2 = -h1 / hsum;
253  d__[d_dim1 + 1] = w1 * del1 + w2 * del2;
254  if (pchst_(&d__[d_dim1 + 1], &del1) <= zero) {
255  d__[d_dim1 + 1] = zero;
256  } else if (pchst_(&del1, &del2) < zero) {
257 /* NEED DO THIS CHECK ONLY IF MONOTONICITY SWITCHES. */
258  dmax__ = three * del1;
259  if ((r__1 = d__[d_dim1 + 1], dabs(r__1)) > dabs(dmax__)) {
260  d__[d_dim1 + 1] = dmax__;
261  }
262  }
263 
264 /* LOOP THROUGH INTERIOR POINTS. */
265 
266  i__1 = nless1;
267  for (i__ = 2; i__ <= i__1; ++i__) {
268  if (i__ == 2) {
269  goto L40;
270  }
271 
272  h1 = h2;
273  h2 = x[i__ + 1] - x[i__];
274  hsum = h1 + h2;
275  del1 = del2;
276  del2 = (f[(i__ + 1) * f_dim1 + 1] - f[i__ * f_dim1 + 1]) / h2;
277 L40:
278 
279 /* SET D(I)=0 UNLESS DATA ARE STRICTLY MONOTONIC. */
280 
281  d__[i__ * d_dim1 + 1] = zero;
282  if ((r__1 = pchst_(&del1, &del2)) < 0.f) {
283  goto L42;
284  } else if (r__1 == 0) {
285  goto L41;
286  } else {
287  goto L45;
288  }
289 
290 /* COUNT NUMBER OF CHANGES IN DIRECTION OF MONOTONICITY. */
291 
292 L41:
293  if (del2 == zero) {
294  goto L50;
295  }
296  if (pchst_(&dsave, &del2) < zero) {
297  ++(*ierr);
298  }
299  dsave = del2;
300  goto L50;
301 
302 L42:
303  ++(*ierr);
304  dsave = del2;
305  goto L50;
306 
307 /* USE BRODLIE MODIFICATION OF BUTLAND FORMULA. */
308 
309 L45:
310  hsumt3 = hsum + hsum + hsum;
311  w1 = (hsum + h1) / hsumt3;
312  w2 = (hsum + h2) / hsumt3;
313 /* Computing MAX */
314  r__1 = dabs(del1), r__2 = dabs(del2);
315  dmax__ = dmax(r__1,r__2);
316 /* Computing MIN */
317  r__1 = dabs(del1), r__2 = dabs(del2);
318  dmin__ = dmin(r__1,r__2);
319  drat1 = del1 / dmax__;
320  drat2 = del2 / dmax__;
321  d__[i__ * d_dim1 + 1] = dmin__ / (w1 * drat1 + w2 * drat2);
322 
323 L50:
324  ;
325  }
326 
327 /* SET D(N) VIA NON-CENTERED THREE-POINT FORMULA, ADJUSTED TO BE */
328 /* SHAPE-PRESERVING. */
329 
330  w1 = -h2 / hsum;
331  w2 = (h2 + hsum) / hsum;
332  d__[*n * d_dim1 + 1] = w1 * del1 + w2 * del2;
333  if (pchst_(&d__[*n * d_dim1 + 1], &del2) <= zero) {
334  d__[*n * d_dim1 + 1] = zero;
335  } else if (pchst_(&del1, &del2) < zero) {
336 /* NEED DO THIS CHECK ONLY IF MONOTONICITY SWITCHES. */
337  dmax__ = three * del2;
338  if ((r__1 = d__[*n * d_dim1 + 1], dabs(r__1)) > dabs(dmax__)) {
339  d__[*n * d_dim1 + 1] = dmax__;
340  }
341  }
342 
343 /* NORMAL RETURN. */
344 
345 L5000:
346  return 0;
347 
348 /* ERROR returns. */
349 
350 L5001:
351 /* N.LT.2 RETURN. */
352  *ierr = -1;
353  xermsg_("SLATEC", "PCHIM", "NUMBER OF DATA POINTS LESS THAN TWO", ierr, &
354  c__1, (ftnlen)6, (ftnlen)5, (ftnlen)35);
355  return 0;
356 
357 L5002:
358 /* INCFD.LT.1 RETURN. */
359  *ierr = -2;
360  xermsg_("SLATEC", "PCHIM", "INCREMENT LESS THAN ONE", ierr, &c__1, (
361  ftnlen)6, (ftnlen)5, (ftnlen)23);
362  return 0;
363 
364 L5003:
365 /* X-ARRAY NOT STRICTLY INCREASING. */
366  *ierr = -3;
367  xermsg_("SLATEC", "PCHIM", "X-ARRAY NOT STRICTLY INCREASING", ierr, &c__1,
368  (ftnlen)6, (ftnlen)5, (ftnlen)31);
369  return 0;
370 /* ------------- LAST LINE OF PCHIM FOLLOWS ------------------------------ */
371 } /* pchim_ */
372 
float * x
int pchim_(integer *n, real *x, real *f, real *d__, integer *incfd, integer *ierr)
Definition: pchim.c:37
int xermsg_(char *libname, char *subname, char *errmsg, integer *errcode, integer *retcode, ftnlen libname_len, ftnlen subname_len, ftnlen errmsg_len)
Definition: xermsg.c:19
static integer c__1
Definition: pchim.c:17
doublereal pchst_(real *arg1, real *arg2)
Definition: pchst.c:20
gtkIOStream: /tmp/gtkiostream/futureInclusions/cubicInterp/pchim.c Source File
GTK+ IOStream  Beta