gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
pchfe.c
Go to the documentation of this file.
1 /* pchfe.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 static integer c__2 = 2;
19 
20 /* $Author: ulammers $ */
21 /* $Date: 1997/02/14 14:13:13 $ */
22 /* $Id: pchfe.f,v 1.1 1997/02/14 14:13:13 ulammers Exp $ */
23 /* $Source: /usr4/users/aparmar/SAXDAS/pipeline/LE_lemat/RCS/pchfe.f,v $ */
24 /* DECK PCHFE */
25 /* Subroutine */ int pchfe_(integer *n, real *x, real *f, real *d__, integer *
26  incfd, logical *skip, integer *ne, real *xe, real *fe, integer *ierr)
27 {
28  /* System generated locals */
29  integer f_dim1, f_offset, d_dim1, d_offset, i__1, i__2;
30 
31  /* Local variables */
32  static integer i__, j, nj, ir, ierc, next[2];
33  extern /* Subroutine */ int chfev_(real *, real *, real *, real *, real *,
34  real *, integer *, real *, real *, integer *, integer *);
35  static integer jfirst;
36  extern /* Subroutine */ int xermsg_(char *, char *, char *, integer *,
37  integer *, ftnlen, ftnlen, ftnlen);
38 
39 /* ***BEGIN PROLOGUE PCHFE */
40 /* ***PURPOSE Evaluate a piecewise cubic Hermite function at an array of */
41 /* points. May be used by itself for Hermite interpolation, */
42 /* or as an evaluator for PCHIM or PCHIC. */
43 /* ***LIBRARY SLATEC (PCHIP) */
44 /* ***CATEGORY E3 */
45 /* ***TYPE SINGLE PRECISION (PCHFE-S, DPCHFE-D) */
46 /* ***KEYWORDS CUBIC HERMITE EVALUATION, HERMITE INTERPOLATION, PCHIP, */
47 /* PIECEWISE CUBIC EVALUATION */
48 /* ***AUTHOR Fritsch, F. N., (LLNL) */
49 /* Lawrence Livermore National Laboratory */
50 /* P.O. Box 808 (L-316) */
51 /* Livermore, CA 94550 */
52 /* FTS 532-4275, (510) 422-4275 */
53 /* ***DESCRIPTION */
54 
55 /* PCHFE: Piecewise Cubic Hermite Function Evaluator */
56 
57 /* Evaluates the cubic Hermite function defined by N, X, F, D at */
58 /* the points XE(J), J=1(1)NE. */
59 
60 /* To provide compatibility with PCHIM and PCHIC, includes an */
61 /* increment between successive values of the F- and D-arrays. */
62 
63 /* ---------------------------------------------------------------------- */
64 
65 /* Calling sequence: */
66 
67 /* PARAMETER (INCFD = ...) */
68 /* INTEGER N, NE, IERR */
69 /* REAL X(N), F(INCFD,N), D(INCFD,N), XE(NE), FE(NE) */
70 /* LOGICAL SKIP */
71 
72 /* CALL PCHFE (N, X, F, D, INCFD, SKIP, NE, XE, FE, IERR) */
73 
74 /* Parameters: */
75 
76 /* N -- (input) number of data points. (Error RETURN if N.LT.2 .) */
77 
78 /* X -- (input) real array of independent variable values. The */
79 /* elements of X must be strictly increasing: */
80 /* X(I-1) .LT. X(I), I = 2(1)N. */
81 /* (Error RETURN if not.) */
82 
83 /* F -- (input) real array of function values. F(1+(I-1)*INCFD) is */
84 /* the value corresponding to X(I). */
85 
86 /* D -- (input) real array of derivative values. D(1+(I-1)*INCFD) is */
87 /* the value corresponding to X(I). */
88 
89 /* INCFD -- (input) increment between successive values in F and D. */
90 /* (Error RETURN if INCFD.LT.1 .) */
91 
92 /* SKIP -- (input/output) logical variable which should be set to */
93 /* .TRUE. if the user wishes to skip checks for validity of */
94 /* preceding parameters, or to .FALSE. otherwise. */
95 /* This will save time in case these checks have already */
96 /* been performed (say, in PCHIM or PCHIC). */
97 /* SKIP will be set to .TRUE. on normal RETURN. */
98 
99 /* NE -- (input) number of evaluation points. (Error RETURN if */
100 /* NE.LT.1 .) */
101 
102 /* XE -- (input) real array of points at which the function is to be */
103 /* evaluated. */
104 
105 /* NOTES: */
106 /* 1. The evaluation will be most efficient if the elements */
107 /* of XE are increasing relative to X; */
108 /* that is, XE(J) .GE. X(I) */
109 /* implies XE(K) .GE. X(I), all K.GE.J . */
110 /* 2. If any of the XE are outside the interval [X(1),X(N)], */
111 /* values are extrapolated from the nearest extreme cubic, */
112 /* and a warning error is RETURNed. */
113 
114 /* FE -- (output) real array of values of the cubic Hermite function */
115 /* defined by N, X, F, D at the points XE. */
116 
117 /* IERR -- (output) error flag. */
118 /* Normal RETURN: */
119 /* IERR = 0 (no errors). */
120 /* Warning error: */
121 /* IERR.GT.0 means that extrapolation was performed at */
122 /* IERR points. */
123 /* "Recoverable" errors: */
124 /* IERR = -1 if N.LT.2 . */
125 /* IERR = -2 if INCFD.LT.1 . */
126 /* IERR = -3 if the X-array is not strictly increasing. */
127 /* IERR = -4 if NE.LT.1 . */
128 /* (The FE-array has not been changed in any of these cases.) */
129 /* NOTE: The above errors are checked in the order listed, */
130 /* and following arguments have **NOT** been validated. */
131 
132 /* ***REFERENCES (NONE) */
133 /* ***ROUTINES CALLED CHFEV, XERMSG */
134 /* ***REVISION HISTORY (YYMMDD) */
135 /* 811020 DATE WRITTEN */
136 /* 820803 Minor cosmetic changes for release 1. */
137 /* 870707 Minor cosmetic changes to prologue. */
138 /* 890531 Changed all specific intrinsics to generic. (WRB) */
139 /* 890831 Modified array declarations. (WRB) */
140 /* 890831 REVISION DATE from Version 3.2 */
141 /* 891214 Prologue converted to Version 4.0 format. (BAB) */
142 /* 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ) */
143 /* ***END PROLOGUE PCHFE */
144 /* Programming notes: */
145 
146 /* 1. To produce a double precision version, simply: */
147 /* a. Change PCHFE to DPCHFE, and CHFEV to DCHFEV, wherever they */
148 /* occur, */
149 /* b. Change the real declaration to double precision, */
150 
151 /* 2. Most of the coding between the call to CHFEV and the end of */
152 /* the IR-loop could be eliminated if it were permissible to */
153 /* assume that XE is ordered relative to X. */
154 
155 /* 3. CHFEV does not assume that X1 is less than X2. thus, it would */
156 /* be possible to write a version of PCHFE that assumes a strict- */
157 /* ly decreasing X-array by simply running the IR-loop backwards */
158 /* (and reversing the order of appropriate tests). */
159 
160 /* 4. The present code has a minor bug, which I have decided is not */
161 /* worth the effort that would be required to fix it. */
162 /* If XE contains points in [X(N-1),X(N)], followed by points .LT. */
163 /* X(N-1), followed by points .GT.X(N), the extrapolation points */
164 /* will be counted (at least) twice in the total RETURNed in IERR. */
165 
166 /* DECLARE ARGUMENTS. */
167 
168 
169 /* DECLARE LOCAL VARIABLES. */
170 
171 
172 /* VALIDITY-CHECK ARGUMENTS. */
173 
174 /* ***FIRST EXECUTABLE STATEMENT PCHFE */
175  /* Parameter adjustments */
176  --x;
177  d_dim1 = *incfd;
178  d_offset = 1 + d_dim1;
179  d__ -= d_offset;
180  f_dim1 = *incfd;
181  f_offset = 1 + f_dim1;
182  f -= f_offset;
183  --xe;
184  --fe;
185 
186  /* Function Body */
187  if (*skip) {
188  goto L5;
189  }
190 
191  if (*n < 2) {
192  goto L5001;
193  }
194  if (*incfd < 1) {
195  goto L5002;
196  }
197  i__1 = *n;
198  for (i__ = 2; i__ <= i__1; ++i__) {
199  if (x[i__] <= x[i__ - 1]) {
200  goto L5003;
201  }
202 /* L1: */
203  }
204 
205 /* FUNCTION DEFINITION IS OK, GO ON. */
206 
207 L5:
208  if (*ne < 1) {
209  goto L5004;
210  }
211  *ierr = 0;
212  *skip = TRUE_;
213 
214 /* LOOP OVER INTERVALS. ( INTERVAL INDEX IS IL = IR-1 . ) */
215 /* ( INTERVAL IS X(IL).LE.X.LT.X(IR) . ) */
216  jfirst = 1;
217  ir = 2;
218 L10:
219 
220 /* SKIP OUT OF LOOP IF HAVE PROCESSED ALL EVALUATION POINTS. */
221 
222  if (jfirst > *ne) {
223  goto L5000;
224  }
225 
226 /* LOCATE ALL POINTS IN INTERVAL. */
227 
228  i__1 = *ne;
229  for (j = jfirst; j <= i__1; ++j) {
230  if (xe[j] >= x[ir]) {
231  goto L30;
232  }
233 /* L20: */
234  }
235  j = *ne + 1;
236  goto L40;
237 
238 /* HAVE LOCATED FIRST POINT BEYOND INTERVAL. */
239 
240 L30:
241  if (ir == *n) {
242  j = *ne + 1;
243  }
244 
245 L40:
246  nj = j - jfirst;
247 
248 /* SKIP EVALUATION IF NO POINTS IN INTERVAL. */
249 
250  if (nj == 0) {
251  goto L50;
252  }
253 
254 /* EVALUATE CUBIC AT XE(I), I = JFIRST (1) J-1 . */
255 
256 /* ---------------------------------------------------------------- */
257  chfev_(&x[ir - 1], &x[ir], &f[(ir - 1) * f_dim1 + 1], &f[ir * f_dim1 + 1],
258  &d__[(ir - 1) * d_dim1 + 1], &d__[ir * d_dim1 + 1], &nj, &xe[
259  jfirst], &fe[jfirst], next, &ierc);
260 /* ---------------------------------------------------------------- */
261  if (ierc < 0) {
262  goto L5005;
263  }
264 
265  if (next[1] == 0) {
266  goto L42;
267  }
268 /* IF (NEXT(2) .GT. 0) THEN */
269 /* IN THE CURRENT SET OF XE-POINTS, THERE ARE NEXT(2) TO THE */
270 /* RIGHT OF X(IR). */
271 
272  if (ir < *n) {
273  goto L41;
274  }
275 /* IF (IR .EQ. N) THEN */
276 /* THESE ARE ACTUALLY EXTRAPOLATION POINTS. */
277  *ierr += next[1];
278  goto L42;
279 L41:
280 /* ELSE */
281 /* WE SHOULD NEVER HAVE GOTTEN HERE. */
282  goto L5005;
283 /* ENDIF */
284 /* ENDIF */
285 L42:
286 
287  if (next[0] == 0) {
288  goto L49;
289  }
290 /* IF (NEXT(1) .GT. 0) THEN */
291 /* IN THE CURRENT SET OF XE-POINTS, THERE ARE NEXT(1) TO THE */
292 /* LEFT OF X(IR-1). */
293 
294  if (ir > 2) {
295  goto L43;
296  }
297 /* IF (IR .EQ. 2) THEN */
298 /* THESE ARE ACTUALLY EXTRAPOLATION POINTS. */
299  *ierr += next[0];
300  goto L49;
301 L43:
302 /* ELSE */
303 /* XE IS NOT ORDERED RELATIVE TO X, SO MUST ADJUST */
304 /* EVALUATION INTERVAL. */
305 
306 /* FIRST, LOCATE FIRST POINT TO LEFT OF X(IR-1). */
307  i__1 = j - 1;
308  for (i__ = jfirst; i__ <= i__1; ++i__) {
309  if (xe[i__] < x[ir - 1]) {
310  goto L45;
311  }
312 /* L44: */
313  }
314 /* NOTE-- CANNOT DROP THROUGH HERE UNLESS THERE IS AN ERROR */
315 /* IN CHFEV. */
316  goto L5005;
317 
318 L45:
319 /* RESET J. (THIS WILL BE THE NEW JFIRST.) */
320  j = i__;
321 
322 /* NOW FIND OUT HOW FAR TO BACK UP IN THE X-ARRAY. */
323  i__1 = ir - 1;
324  for (i__ = 1; i__ <= i__1; ++i__) {
325  if (xe[j] < x[i__]) {
326  goto L47;
327  }
328 /* L46: */
329  }
330 /* NB-- CAN NEVER DROP THROUGH HERE, SINCE XE(J).LT.X(IR-1). */
331 
332 L47:
333 /* AT THIS POINT, EITHER XE(J) .LT. X(1) */
334 /* OR X(I-1) .LE. XE(J) .LT. X(I) . */
335 /* RESET IR, RECOGNIZING THAT IT WILL BE INCREMENTED BEFORE */
336 /* CYCLING. */
337 /* Computing MAX */
338  i__1 = 1, i__2 = i__ - 1;
339  ir = max(i__1,i__2);
340 /* ENDIF */
341 /* ENDIF */
342 L49:
343 
344  jfirst = j;
345 
346 /* END OF IR-LOOP. */
347 
348 L50:
349  ++ir;
350  if (ir <= *n) {
351  goto L10;
352  }
353 
354 /* NORMAL RETURN. */
355 
356 L5000:
357  return 0;
358 
359 /* ERROR returns. */
360 
361 L5001:
362 /* N.LT.2 RETURN. */
363  *ierr = -1;
364  xermsg_("SLATEC", "PCHFE", "NUMBER OF DATA POINTS LESS THAN TWO", ierr, &
365  c__1, (ftnlen)6, (ftnlen)5, (ftnlen)35);
366  return 0;
367 
368 L5002:
369 /* INCFD.LT.1 RETURN. */
370  *ierr = -2;
371  xermsg_("SLATEC", "PCHFE", "INCREMENT LESS THAN ONE", ierr, &c__1, (
372  ftnlen)6, (ftnlen)5, (ftnlen)23);
373  return 0;
374 
375 L5003:
376 /* X-ARRAY NOT STRICTLY INCREASING. */
377  *ierr = -3;
378  xermsg_("SLATEC", "PCHFE", "X-ARRAY NOT STRICTLY INCREASING", ierr, &c__1,
379  (ftnlen)6, (ftnlen)5, (ftnlen)31);
380  return 0;
381 
382 L5004:
383 /* NE.LT.1 RETURN. */
384  *ierr = -4;
385  xermsg_("SLATEC", "PCHFE", "NUMBER OF EVALUATION POINTS LESS THAN ONE",
386  ierr, &c__1, (ftnlen)6, (ftnlen)5, (ftnlen)41);
387  return 0;
388 
389 L5005:
390 /* ERROR RETURN FROM CHFEV. */
391 /* *** THIS CASE SHOULD NEVER OCCUR *** */
392  *ierr = -5;
393  xermsg_("SLATEC", "PCHFE", "ERROR RETURN FROM CHFEV -- FATAL", ierr, &
394  c__2, (ftnlen)6, (ftnlen)5, (ftnlen)32);
395  return 0;
396 /* ------------- LAST LINE OF PCHFE FOLLOWS ------------------------------ */
397 } /* pchfe_ */
398 
float * x
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
int pchfe_(integer *n, real *x, real *f, real *d__, integer *incfd, logical *skip, integer *ne, real *xe, real *fe, integer *ierr)
Definition: pchfe.c:25
static integer c__1
Definition: pchfe.c:17
int chfev_(real *x1, real *x2, real *f1, real *f2, real *d1, real *d2, integer *ne, real *xe, real *fe, integer *next, integer *ierr)
Definition: chfev.c:24
static integer c__2
Definition: pchfe.c:18
gtkIOStream: /tmp/gtkiostream/futureInclusions/cubicInterp/pchfe.c Source File
GTK+ IOStream  Beta