pchid.f 5.9 KB

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