2
SUBROUTINE PCHCI (N, H, SLOPE, D, INCFD)
3
C***BEGIN PROLOGUE PCHCI
5
C***PURPOSE Set interior derivatives for PCHIC
6
C***LIBRARY SLATEC (PCHIP)
7
C***TYPE SINGLE PRECISION (PCHCI-S, DPCHCI-D)
8
C***AUTHOR Fritsch, F. N., (LLNL)
11
C PCHCI: PCHIC Initial Derivative Setter.
13
C Called by PCHIC to set derivatives needed to determine a monotone
14
C piecewise cubic Hermite interpolant to the data.
16
C Default boundary conditions are provided which are compatible
17
C with monotonicity. If the data are only piecewise monotonic, the
18
C interpolant will have an extremum at each point where monotonicity
21
C To facilitate two-dimensional applications, includes an increment
22
C between successive values of the D-array.
24
C The resulting piecewise cubic Hermite function should be identical
25
C (within roundoff error) to that produced by PCHIM.
27
C ----------------------------------------------------------------------
31
C PARAMETER (INCFD = ...)
33
C REAL H(N), SLOPE(N), D(INCFD,N)
35
C CALL PCHCI (N, H, SLOPE, D, INCFD)
39
C N -- (input) number of data points.
40
C If N=2, simply does linear interpolation.
42
C H -- (input) real array of interval lengths.
43
C SLOPE -- (input) real array of data slopes.
44
C If the data are (X(I),Y(I)), I=1(1)N, then these inputs are:
46
C SLOPE(I) = (Y(I+1)-Y(I))/H(I), I=1(1)N-1.
48
C D -- (output) real array of derivative values at the data points.
49
C If the data are monotonic, these values will determine a
50
C a monotone cubic Hermite function.
51
C The value corresponding to X(I) is stored in
52
C D(1+(I-1)*INCFD), I=1(1)N.
53
C No other entries in D are changed.
55
C INCFD -- (input) increment between successive values in D.
56
C This argument is provided primarily for 2-D applications.
59
C WARNING: This routine does no validity-checking of arguments.
62
C Fortran intrinsics used: ABS, MAX, MIN.
65
C***ROUTINES CALLED PCHST
66
C***REVISION HISTORY (YYMMDD)
68
C 820601 Modified end conditions to be continuous functions of
69
C data when monotonicity switches in next interval.
70
C 820602 1. Modified formulas so end conditions are less prone
71
C to over/underflow problems.
72
C 2. Minor modification to HSUM calculation.
73
C 820805 Converted to SLATEC library version.
74
C 890411 Added SAVE statements (Vers. 3.2).
75
C 890531 Changed all specific intrinsics to generic. (WRB)
76
C 890831 Modified array declarations. (WRB)
77
C 890831 REVISION DATE from Version 3.2
78
C 891214 Prologue converted to Version 4.0 format. (BAB)
79
C 900328 Added TYPE section. (WRB)
80
C 910408 Updated AUTHOR section in prologue. (WRB)
81
C 930503 Improved purpose. (FNF)
82
C***END PROLOGUE PCHCI
85
C 1. The function PCHST(ARG1,ARG2) is assumed to return zero if
86
C either argument is zero, +1 if they are of the same sign, and
87
C -1 if they are of opposite sign.
93
REAL H(*), SLOPE(*), D(INCFD,*)
95
C DECLARE LOCAL VARIABLES.
98
REAL DEL1, DEL2, DMAX, DMIN, DRAT1, DRAT2, HSUM, HSUMT3, THREE,
105
DATA ZERO /0./, THREE /3./
106
C***FIRST EXECUTABLE STATEMENT PCHCI
110
C SPECIAL CASE N=2 -- USE LINEAR INTERPOLATION.
112
IF (NLESS1 .GT. 1) GO TO 10
117
C NORMAL CASE (N .GE. 3).
122
C SET D(1) VIA NON-CENTERED THREE-POINT FORMULA, ADJUSTED TO BE
126
W1 = (H(1) + HSUM)/HSUM
128
D(1,1) = W1*DEL1 + W2*DEL2
129
IF ( PCHST(D(1,1),DEL1) .LE. ZERO) THEN
131
ELSE IF ( PCHST(DEL1,DEL2) .LT. ZERO) THEN
132
C NEED DO THIS CHECK ONLY IF MONOTONICITY SWITCHES.
134
IF (ABS(D(1,1)) .GT. ABS(DMAX)) D(1,1) = DMAX
137
C LOOP THROUGH INTERIOR POINTS.
140
IF (I .EQ. 2) GO TO 40
147
C SET D(I)=0 UNLESS DATA ARE STRICTLY MONOTONIC.
150
IF ( PCHST(DEL1,DEL2) .LE. ZERO) GO TO 50
152
C USE BRODLIE MODIFICATION OF BUTLAND FORMULA.
154
HSUMT3 = HSUM+HSUM+HSUM
155
W1 = (HSUM + H(I-1))/HSUMT3
156
W2 = (HSUM + H(I) )/HSUMT3
157
DMAX = MAX( ABS(DEL1), ABS(DEL2) )
158
DMIN = MIN( ABS(DEL1), ABS(DEL2) )
161
D(1,I) = DMIN/(W1*DRAT1 + W2*DRAT2)
165
C SET D(N) VIA NON-CENTERED THREE-POINT FORMULA, ADJUSTED TO BE
169
W2 = (H(N-1) + HSUM)/HSUM
170
D(1,N) = W1*DEL1 + W2*DEL2
171
IF ( PCHST(D(1,N),DEL2) .LE. ZERO) THEN
173
ELSE IF ( PCHST(DEL1,DEL2) .LT. ZERO) THEN
174
C NEED DO THIS CHECK ONLY IF MONOTONICITY SWITCHES.
176
IF (ABS(D(1,N)) .GT. ABS(DMAX)) D(1,N) = DMAX
183
C------------- LAST LINE OF PCHCI FOLLOWS ------------------------------