dpchid.f 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. *DECK DPCHID
  2. DOUBLE PRECISION FUNCTION DPCHID (N, X, F, D, INCFD, SKIP, IA, IB,
  3. + IERR)
  4. C***BEGIN PROLOGUE DPCHID
  5. C***PURPOSE Evaluate the definite integral of a piecewise cubic
  6. C Hermite function over an interval whose endpoints are data
  7. C points.
  8. C***LIBRARY SLATEC (PCHIP)
  9. C***CATEGORY E3, H2A1B2
  10. C***TYPE DOUBLE PRECISION (PCHID-S, DPCHID-D)
  11. C***KEYWORDS CUBIC HERMITE INTERPOLATION, NUMERICAL INTEGRATION, PCHIP,
  12. C QUADRATURE
  13. C***AUTHOR Fritsch, F. N., (LLNL)
  14. C Lawrence Livermore National Laboratory
  15. C P.O. Box 808 (L-316)
  16. C Livermore, CA 94550
  17. C FTS 532-4275, (510) 422-4275
  18. C***DESCRIPTION
  19. C
  20. C DPCHID: Piecewise Cubic Hermite Integrator, Data limits
  21. C
  22. C Evaluates the definite integral of the cubic Hermite function
  23. C defined by N, X, F, D over the interval [X(IA), X(IB)].
  24. C
  25. C To provide compatibility with DPCHIM and DPCHIC, includes an
  26. C increment between successive values of the F- and D-arrays.
  27. C
  28. C ----------------------------------------------------------------------
  29. C
  30. C Calling sequence:
  31. C
  32. C PARAMETER (INCFD = ...)
  33. C INTEGER N, IA, IB, IERR
  34. C DOUBLE PRECISION X(N), F(INCFD,N), D(INCFD,N)
  35. C LOGICAL SKIP
  36. C
  37. C VALUE = DPCHID (N, X, F, D, INCFD, SKIP, IA, IB, IERR)
  38. C
  39. C Parameters:
  40. C
  41. C VALUE -- (output) value of the requested integral.
  42. C
  43. C N -- (input) number of data points. (Error return if N.LT.2 .)
  44. C
  45. C X -- (input) real*8 array of independent variable values. The
  46. C elements of X must be strictly increasing:
  47. C X(I-1) .LT. X(I), I = 2(1)N.
  48. C (Error return if not.)
  49. C
  50. C F -- (input) real*8 array of function values. F(1+(I-1)*INCFD) is
  51. C the value corresponding to X(I).
  52. C
  53. C D -- (input) real*8 array of derivative values. D(1+(I-1)*INCFD)
  54. C is the value corresponding to X(I).
  55. C
  56. C INCFD -- (input) increment between successive values in F and D.
  57. C (Error return if INCFD.LT.1 .)
  58. C
  59. C SKIP -- (input/output) logical variable which should be set to
  60. C .TRUE. if the user wishes to skip checks for validity of
  61. C preceding parameters, or to .FALSE. otherwise.
  62. C This will save time in case these checks have already
  63. C been performed (say, in DPCHIM or DPCHIC).
  64. C SKIP will be set to .TRUE. on return with IERR = 0 or -4.
  65. C
  66. C IA,IB -- (input) indices in X-array for the limits of integration.
  67. C both must be in the range [1,N]. (Error return if not.)
  68. C No restrictions on their relative values.
  69. C
  70. C IERR -- (output) error flag.
  71. C Normal return:
  72. C IERR = 0 (no errors).
  73. C "Recoverable" errors:
  74. C IERR = -1 if N.LT.2 .
  75. C IERR = -2 if INCFD.LT.1 .
  76. C IERR = -3 if the X-array is not strictly increasing.
  77. C IERR = -4 if IA or IB is out of range.
  78. C (VALUE will be zero in any of these cases.)
  79. C NOTE: The above errors are checked in the order listed,
  80. C and following arguments have **NOT** been validated.
  81. C
  82. C***REFERENCES (NONE)
  83. C***ROUTINES CALLED XERMSG
  84. C***REVISION HISTORY (YYMMDD)
  85. C 820723 DATE WRITTEN
  86. C 820804 Converted to SLATEC library version.
  87. C 870707 Corrected XERROR calls for d.p. name(s).
  88. C 870813 Minor cosmetic changes.
  89. C 890206 Corrected XERROR calls.
  90. C 890411 Added SAVE statements (Vers. 3.2).
  91. C 890531 Changed all specific intrinsics to generic. (WRB)
  92. C 890703 Corrected category record. (WRB)
  93. C 890831 Modified array declarations. (WRB)
  94. C 891006 Cosmetic changes to prologue. (WRB)
  95. C 891006 REVISION DATE from Version 3.2
  96. C 891214 Prologue converted to Version 4.0 format. (BAB)
  97. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  98. C 930504 Corrected to set VALUE=0 when IERR.ne.0. (FNF)
  99. C***END PROLOGUE DPCHID
  100. C
  101. C Programming notes:
  102. C 1. This routine uses a special formula that is valid only for
  103. C integrals whose limits coincide with data values. This is
  104. C mathematically equivalent to, but much more efficient than,
  105. C calls to DCHFIE.
  106. C**End
  107. C
  108. C DECLARE ARGUMENTS.
  109. C
  110. INTEGER N, INCFD, IA, IB, IERR
  111. DOUBLE PRECISION X(*), F(INCFD,*), D(INCFD,*)
  112. LOGICAL SKIP
  113. C
  114. C DECLARE LOCAL VARIABLES.
  115. C
  116. INTEGER I, IUP, LOW
  117. DOUBLE PRECISION H, HALF, SIX, SUM, VALUE, ZERO
  118. SAVE ZERO, HALF, SIX
  119. C
  120. C INITIALIZE.
  121. C
  122. DATA ZERO /0.D0/, HALF/.5D0/, SIX/6.D0/
  123. C***FIRST EXECUTABLE STATEMENT DPCHID
  124. VALUE = ZERO
  125. C
  126. C VALIDITY-CHECK ARGUMENTS.
  127. C
  128. IF (SKIP) GO TO 5
  129. C
  130. IF ( N.LT.2 ) GO TO 5001
  131. IF ( INCFD.LT.1 ) GO TO 5002
  132. DO 1 I = 2, N
  133. IF ( X(I).LE.X(I-1) ) GO TO 5003
  134. 1 CONTINUE
  135. C
  136. C FUNCTION DEFINITION IS OK, GO ON.
  137. C
  138. 5 CONTINUE
  139. SKIP = .TRUE.
  140. IF ((IA.LT.1) .OR. (IA.GT.N)) GO TO 5004
  141. IF ((IB.LT.1) .OR. (IB.GT.N)) GO TO 5004
  142. IERR = 0
  143. C
  144. C COMPUTE INTEGRAL VALUE.
  145. C
  146. IF (IA .NE. IB) THEN
  147. LOW = MIN(IA, IB)
  148. IUP = MAX(IA, IB) - 1
  149. SUM = ZERO
  150. DO 10 I = LOW, IUP
  151. H = X(I+1) - X(I)
  152. SUM = SUM + H*( (F(1,I) + F(1,I+1)) +
  153. * (D(1,I) - D(1,I+1))*(H/SIX) )
  154. 10 CONTINUE
  155. VALUE = HALF * SUM
  156. IF (IA .GT. IB) VALUE = -VALUE
  157. ENDIF
  158. C
  159. C NORMAL RETURN.
  160. C
  161. 5000 CONTINUE
  162. DPCHID = VALUE
  163. RETURN
  164. C
  165. C ERROR RETURNS.
  166. C
  167. 5001 CONTINUE
  168. C N.LT.2 RETURN.
  169. IERR = -1
  170. CALL XERMSG ('SLATEC', 'DPCHID',
  171. + 'NUMBER OF DATA POINTS LESS THAN TWO', IERR, 1)
  172. GO TO 5000
  173. C
  174. 5002 CONTINUE
  175. C INCFD.LT.1 RETURN.
  176. IERR = -2
  177. CALL XERMSG ('SLATEC', 'DPCHID', 'INCREMENT LESS THAN ONE', IERR,
  178. + 1)
  179. GO TO 5000
  180. C
  181. 5003 CONTINUE
  182. C X-ARRAY NOT STRICTLY INCREASING.
  183. IERR = -3
  184. CALL XERMSG ('SLATEC', 'DPCHID',
  185. + 'X-ARRAY NOT STRICTLY INCREASING', IERR, 1)
  186. GO TO 5000
  187. C
  188. 5004 CONTINUE
  189. C IA OR IB OUT OF RANGE RETURN.
  190. IERR = -4
  191. CALL XERMSG ('SLATEC', 'DPCHID', 'IA OR IB OUT OF RANGE', IERR,
  192. + 1)
  193. GO TO 5000
  194. C------------- LAST LINE OF DPCHID FOLLOWS -----------------------------
  195. END