gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
pchim.f
Go to the documentation of this file.
1 C $Author: ulammers $
2 C $Date: 1997/02/14 14:13:13 $
3 C $Id: pchim.f,v 1.1 1997/02/14 14:13:13 ulammers Exp $
4 C $Source: /usr4/users/aparmar/SAXDAS/pipeline/LE_lemat/RCS/pchim.f,v $
5 c
6 c --- SLATEC ROUTINES ---------------------------------------------
7 c
8 c PCHIM
9 c PCHFE
10 c PCHST
11 c CHFEV
12 c
13 c XERMSG - this is a subsidiary routine used by all the above to
14 c output error messages. Here it simply calls FTOOL's
15 c FCERR.
16 c -----------------------------------------------------------------
17 c
18 *DECK PCHIM
19  SUBROUTINE pchim (N, X, F, D, INCFD, IERR)
20 C***BEGIN PROLOGUE PCHIM
21 C***PURPOSE Set derivatives needed to determine a monotone piecewise
22 C cubic Hermite interpolant to given data. Boundary values
23 C are provided which are compatible with monotonicity. The
24 C interpolant will have an extremum at each point where mono-
25 C tonicity switches direction. (See PCHIC if user control is
26 C desired over boundary or switch conditions.)
27 C***LIBRARY SLATEC (PCHIP)
28 C***CATEGORY E1A
29 C***TYPE SINGLE PRECISION (PCHIM-S, DPCHIM-D)
30 C***KEYWORDS CUBIC HERMITE INTERPOLATION, MONOTONE INTERPOLATION,
31 C PCHIP, PIECEWISE CUBIC INTERPOLATION
32 C***AUTHOR Fritsch, F. N., (LLNL)
33 C Lawrence Livermore National Laboratory
34 C P.O. Box 808 (L-316)
35 C Livermore, CA 94550
36 C FTS 532-4275, (510) 422-4275
37 C***DESCRIPTION
38 C
39 C PCHIM: Piecewise Cubic Hermite Interpolation to
40 C Monotone data.
41 C
42 C Sets derivatives needed to determine a monotone piecewise cubic
43 C Hermite interpolant to the data given in X and F.
44 C
45 C Default boundary conditions are provided which are compatible
46 C with monotonicity. (See PCHIC if user control of boundary con-
47 C ditions is desired.)
48 C
49 C If the data are only piecewise monotonic, the interpolant will
50 C have an extremum at each point where monotonicity switches direc-
51 C tion. (See PCHIC if user control is desired in such cases.)
52 C
53 C To facilitate two-dimensional applications, includes an increment
54 C between successive values of the F- and D-arrays.
55 C
56 C The resulting piecewise cubic Hermite function may be evaluated
57 C by PCHFE or PCHFD.
58 C
59 C ----------------------------------------------------------------------
60 C
61 C Calling sequence:
62 C
63 C PARAMETER (INCFD = ...)
64 C INTEGER N, IERR
65 C REAL X(N), F(INCFD,N), D(INCFD,N)
66 C
67 C CALL PCHIM (N, X, F, D, INCFD, IERR)
68 C
69 C Parameters:
70 C
71 C N -- (input) number of data points. (Error RETURN if N.LT.2 .)
72 C If N=2, simply does linear interpolation.
73 C
74 C X -- (input) real array of independent variable values. The
75 C elements of X must be strictly increasing:
76 C X(I-1) .LT. X(I), I = 2(1)N.
77 C (Error RETURN if not.)
78 C
79 C F -- (input) real array of dependent variable values to be inter-
80 C polated. F(1+(I-1)*INCFD) is value corresponding to X(I).
81 C PCHIM is designed for monotonic data, but it will work for
82 C any F-array. It will force extrema at points where mono-
83 C tonicity switches direction. If some other treatment of
84 C switch points is desired, PCHIC should be used instead.
85 C -----
86 C D -- (output) real array of derivative values at the data points.
87 C If the data are monotonic, these values will determine a
88 C a monotone cubic Hermite function.
89 C The value corresponding to X(I) is stored in
90 C D(1+(I-1)*INCFD), I=1(1)N.
91 C No other entries in D are changed.
92 C
93 C INCFD -- (input) increment between successive values in F and D.
94 C This argument is provided primarily for 2-D applications.
95 C (Error RETURN if INCFD.LT.1 .)
96 C
97 C IERR -- (output) error flag.
98 C Normal RETURN:
99 C IERR = 0 (no errors).
100 C Warning error:
101 C IERR.GT.0 means that IERR switches in the direction
102 C of monotonicity were detected.
103 C "Recoverable" errors:
104 C IERR = -1 if N.LT.2 .
105 C IERR = -2 if INCFD.LT.1 .
106 C IERR = -3 if the X-array is not strictly increasing.
107 C (The D-array has not been changed in any of these cases.)
108 C NOTE: The above errors are checked in the order listed,
109 C and following arguments have **NOT** been validated.
110 C
111 C***REFERENCES 1. F. N. Fritsch and J. Butland, A method for construc-
112 C ting local monotone piecewise cubic interpolants, SIAM
113 C Journal on Scientific and Statistical Computing 5, 2
114 C (June 1984), pp. 300-304.
115 C 2. F. N. Fritsch and R. E. Carlson, Monotone piecewise
116 C cubic interpolation, SIAM Journal on Numerical Ana-
117 C lysis 17, 2 (April 1980), pp. 238-246.
118 C***ROUTINES CALLED PCHST, XERMSG
119 C***REVISION HISTORY (YYMMDD)
120 C 811103 DATE WRITTEN
121 C 820201 1. Introduced PCHST to reduce possible over/under-
122 C flow problems.
123 C 2. Rearranged derivative formula for same reason.
124 C 820602 1. Modified end conditions to be continuous functions
125 C of data when monotonicity switches in next interval.
126 C 2. Modified formulas so end conditions are less prone
127 C of over/underflow problems.
128 C 820803 Minor cosmetic changes for release 1.
129 C 870813 Updated Reference 1.
130 C 890411 Added SAVE statements (Vers. 3.2).
131 C 890531 Changed all specific intrinsics to generic. (WRB)
132 C 890703 Corrected category record. (WRB)
133 C 890831 Modified array declarations. (WRB)
134 C 890831 REVISION DATE from Version 3.2
135 C 891214 Prologue converted to Version 4.0 format. (BAB)
136 C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
137 C 920429 Revised format and order of references. (WRB,FNF)
138 C***END PROLOGUE PCHIM
139 C Programming notes:
140 C
141 C 1. The function PCHST(ARG1,ARG2) is assumed to RETURN zero if
142 C either argument is zero, +1 if they are of the same sign, and
143 C -1 if they are of opposite sign.
144 C 2. To produce a double precision version, simply:
145 C a. Change PCHIM to DPCHIM wherever it occurs,
146 C b. Change PCHST to DPCHST wherever it occurs,
147 C c. Change all references to the Fortran intrinsics to their
148 C double precision equivalents,
149 C d. Change the real declarations to double precision, and
150 C e. Change the constants ZERO and THREE to double precision.
151 C
152 C DECLARE ARGUMENTS.
153 C
154  INTEGER N, INCFD, IERR
155  REAL X(*), F(incfd,*), D(incfd,*)
156 C
157 C DECLARE LOCAL VARIABLES.
158 C
159  INTEGER I, NLESS1
160  REAL DEL1, DEL2, DMAX, DMIN, DRAT1, DRAT2, DSAVE,
161  * h1, h2, hsum, hsumt3, three, w1, w2, zero
162  SAVE zero, three
163  REAL PCHST
164  DATA zero /0./, three /3./
165 C
166 C VALIDITY-CHECK ARGUMENTS.
167 C
168 C***FIRST EXECUTABLE STATEMENT PCHIM
169  IF ( n .LT. 2 ) GO TO 5001
170  IF ( incfd .LT. 1 ) GO TO 5002
171  DO 1 i = 2, n
172  IF ( x(i).LE.x(i-1) ) GO TO 5003
173  1 CONTINUE
174 C
175 C FUNCTION DEFINITION IS OK, GO ON.
176 C
177  ierr = 0
178  nless1 = n - 1
179  h1 = x(2) - x(1)
180  del1 = (f(1,2) - f(1,1))/h1
181  dsave = del1
182 C
183 C SPECIAL CASE N=2 -- USE LINEAR INTERPOLATION.
184 C
185  IF (nless1 .GT. 1) GO TO 10
186  d(1,1) = del1
187  d(1,n) = del1
188  GO TO 5000
189 C
190 C NORMAL CASE (N .GE. 3).
191 C
192  10 CONTINUE
193  h2 = x(3) - x(2)
194  del2 = (f(1,3) - f(1,2))/h2
195 C
196 C SET D(1) VIA NON-CENTERED THREE-POINT FORMULA, ADJUSTED TO BE
197 C SHAPE-PRESERVING.
198 C
199  hsum = h1 + h2
200  w1 = (h1 + hsum)/hsum
201  w2 = -h1/hsum
202  d(1,1) = w1*del1 + w2*del2
203  IF ( pchst(d(1,1),del1) .LE. zero) THEN
204  d(1,1) = zero
205  ELSE IF ( pchst(del1,del2) .LT. zero) THEN
206 C NEED DO THIS CHECK ONLY IF MONOTONICITY SWITCHES.
207  dmax = three*del1
208  IF (abs(d(1,1)) .GT. abs(dmax)) d(1,1) = dmax
209  ENDIF
210 C
211 C LOOP THROUGH INTERIOR POINTS.
212 C
213  DO 50 i = 2, nless1
214  IF (i .EQ. 2) GO TO 40
215 C
216  h1 = h2
217  h2 = x(i+1) - x(i)
218  hsum = h1 + h2
219  del1 = del2
220  del2 = (f(1,i+1) - f(1,i))/h2
221  40 CONTINUE
222 C
223 C SET D(I)=0 UNLESS DATA ARE STRICTLY MONOTONIC.
224 C
225  d(1,i) = zero
226  IF ( pchst(del1,del2) ) 42, 41, 45
227 C
228 C COUNT NUMBER OF CHANGES IN DIRECTION OF MONOTONICITY.
229 C
230  41 CONTINUE
231  IF (del2 .EQ. zero) GO TO 50
232  IF ( pchst(dsave,del2) .LT. zero) ierr = ierr + 1
233  dsave = del2
234  GO TO 50
235 C
236  42 CONTINUE
237  ierr = ierr + 1
238  dsave = del2
239  GO TO 50
240 C
241 C USE BRODLIE MODIFICATION OF BUTLAND FORMULA.
242 C
243  45 CONTINUE
244  hsumt3 = hsum+hsum+hsum
245  w1 = (hsum + h1)/hsumt3
246  w2 = (hsum + h2)/hsumt3
247  dmax = max( abs(del1), abs(del2) )
248  dmin = min( abs(del1), abs(del2) )
249  drat1 = del1/dmax
250  drat2 = del2/dmax
251  d(1,i) = dmin/(w1*drat1 + w2*drat2)
252 C
253  50 CONTINUE
254 C
255 C SET D(N) VIA NON-CENTERED THREE-POINT FORMULA, ADJUSTED TO BE
256 C SHAPE-PRESERVING.
257 C
258  w1 = -h2/hsum
259  w2 = (h2 + hsum)/hsum
260  d(1,n) = w1*del1 + w2*del2
261  IF ( pchst(d(1,n),del2) .LE. zero) THEN
262  d(1,n) = zero
263  ELSE IF ( pchst(del1,del2) .LT. zero) THEN
264 C NEED DO THIS CHECK ONLY IF MONOTONICITY SWITCHES.
265  dmax = three*del2
266  IF (abs(d(1,n)) .GT. abs(dmax)) d(1,n) = dmax
267  ENDIF
268 C
269 C NORMAL RETURN.
270 C
271  5000 CONTINUE
272  RETURN
273 C
274 C ERROR returns.
275 C
276  5001 CONTINUE
277 C N.LT.2 RETURN.
278  ierr = -1
279  CALL xermsg ('SLATEC', 'PCHIM',
280  + 'NUMBER OF DATA POINTS LESS THAN TWO', ierr, 1)
281  RETURN
282 C
283  5002 CONTINUE
284 C INCFD.LT.1 RETURN.
285  ierr = -2
286  CALL xermsg ('SLATEC', 'PCHIM', 'INCREMENT LESS THAN ONE', ierr,
287  + 1)
288  RETURN
289 C
290  5003 CONTINUE
291 C X-ARRAY NOT STRICTLY INCREASING.
292  ierr = -3
293  CALL xermsg ('SLATEC', 'PCHIM', 'X-ARRAY NOT STRICTLY INCREASING'
294  + , ierr, 1)
295  RETURN
296 C------------- LAST LINE OF PCHIM FOLLOWS ------------------------------
297  END
298 
subroutine xermsg(LIBNAME, SUBNAME, ERRMSG, ERRCODE, RETCODE)
Definition: xermsg.f:2
subroutine pchim(N, X, F, D, INCFD, IERR)
Definition: pchim.f:20
gtkIOStream: /tmp/gtkiostream/futureInclusions/cubicInterp/pchim.f Source File
GTK+ IOStream  Beta