dchfcm.f 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. *DECK DCHFCM
  2. INTEGER FUNCTION DCHFCM (D1, D2, DELTA)
  3. C***BEGIN PROLOGUE DCHFCM
  4. C***SUBSIDIARY
  5. C***PURPOSE Check a single cubic for monotonicity.
  6. C***LIBRARY SLATEC (PCHIP)
  7. C***TYPE DOUBLE PRECISION (CHFCM-S, DCHFCM-D)
  8. C***AUTHOR Fritsch, F. N., (LLNL)
  9. C***DESCRIPTION
  10. C
  11. C *Usage:
  12. C
  13. C DOUBLE PRECISION D1, D2, DELTA
  14. C INTEGER ISMON, DCHFCM
  15. C
  16. C ISMON = DCHFCM (D1, D2, DELTA)
  17. C
  18. C *Arguments:
  19. C
  20. C D1,D2:IN are the derivative values at the ends of an interval.
  21. C
  22. C DELTA:IN is the data slope over that interval.
  23. C
  24. C *Function Return Values:
  25. C ISMON : indicates the monotonicity of the cubic segment:
  26. C ISMON = -3 if function is probably decreasing;
  27. C ISMON = -1 if function is strictly decreasing;
  28. C ISMON = 0 if function is constant;
  29. C ISMON = 1 if function is strictly increasing;
  30. C ISMON = 2 if function is non-monotonic;
  31. C ISMON = 3 if function is probably increasing.
  32. C If ABS(ISMON)=3, the derivative values are too close to the
  33. C boundary of the monotonicity region to declare monotonicity
  34. C in the presence of roundoff error.
  35. C
  36. C *Description:
  37. C
  38. C DCHFCM: Cubic Hermite Function -- Check Monotonicity.
  39. C
  40. C Called by DPCHCM to determine the monotonicity properties of the
  41. C cubic with boundary derivative values D1,D2 and chord slope DELTA.
  42. C
  43. C *Cautions:
  44. C This is essentially the same as old DCHFMC, except that a
  45. C new output value, -3, was added February 1989. (Formerly, -3
  46. C and +3 were lumped together in the single value 3.) Codes that
  47. C flag nonmonotonicity by "IF (ISMON.EQ.2)" need not be changed.
  48. C Codes that check via "IF (ISMON.GE.3)" should change the test to
  49. C "IF (IABS(ISMON).GE.3)". Codes that declare monotonicity via
  50. C "IF (ISMON.LE.1)" should change to "IF (IABS(ISMON).LE.1)".
  51. C
  52. C REFER TO DPCHCM
  53. C
  54. C***ROUTINES CALLED D1MACH
  55. C***REVISION HISTORY (YYMMDD)
  56. C 820518 DATE WRITTEN
  57. C 820805 Converted to SLATEC library version.
  58. C 831201 Changed from ISIGN to SIGN to correct bug that
  59. C produced wrong sign when -1 .LT. DELTA .LT. 0 .
  60. C 890206 Added SAVE statements.
  61. C 890209 Added sign to returned value ISMON=3 and corrected
  62. C argument description accordingly.
  63. C 890306 Added caution about changed output.
  64. C 890407 Changed name from DCHFMC to DCHFCM, as requested at the
  65. C March 1989 SLATEC CML meeting, and made a few other
  66. C minor modifications necessitated by this change.
  67. C 890407 Converted to new SLATEC format.
  68. C 890407 Modified DESCRIPTION to LDOC format.
  69. C 891214 Moved SAVE statements. (WRB)
  70. C***END PROLOGUE DCHFCM
  71. C
  72. C Fortran intrinsics used: DSIGN.
  73. C Other routines used: D1MACH.
  74. C
  75. C ----------------------------------------------------------------------
  76. C
  77. C Programming notes:
  78. C
  79. C TEN is actually a tuning parameter, which determines the width of
  80. C the fuzz around the elliptical boundary.
  81. C
  82. C To produce a single precision version, simply:
  83. C a. Change DCHFCM to CHFCM wherever it occurs,
  84. C b. Change the double precision declarations to real, and
  85. C c. Change the constants ZERO, ONE, ... to single precision.
  86. C
  87. C DECLARE ARGUMENTS.
  88. C
  89. DOUBLE PRECISION D1, D2, DELTA, D1MACH
  90. C
  91. C DECLARE LOCAL VARIABLES.
  92. C
  93. INTEGER ISMON, ITRUE
  94. DOUBLE PRECISION A, B, EPS, FOUR, ONE, PHI, TEN, THREE, TWO,
  95. * ZERO
  96. SAVE ZERO, ONE, TWO, THREE, FOUR
  97. SAVE TEN
  98. C
  99. C INITIALIZE.
  100. C
  101. DATA ZERO /0.D0/, ONE/1.D0/, TWO/2.D0/, THREE/3.D0/, FOUR/4.D0/,
  102. 1 TEN /10.D0/
  103. C
  104. C MACHINE-DEPENDENT PARAMETER -- SHOULD BE ABOUT 10*UROUND.
  105. C***FIRST EXECUTABLE STATEMENT DCHFCM
  106. EPS = TEN*D1MACH(4)
  107. C
  108. C MAKE THE CHECK.
  109. C
  110. IF (DELTA .EQ. ZERO) THEN
  111. C CASE OF CONSTANT DATA.
  112. IF ((D1.EQ.ZERO) .AND. (D2.EQ.ZERO)) THEN
  113. ISMON = 0
  114. ELSE
  115. ISMON = 2
  116. ENDIF
  117. ELSE
  118. C DATA IS NOT CONSTANT -- PICK UP SIGN.
  119. ITRUE = DSIGN (ONE, DELTA)
  120. A = D1/DELTA
  121. B = D2/DELTA
  122. IF ((A.LT.ZERO) .OR. (B.LT.ZERO)) THEN
  123. ISMON = 2
  124. ELSE IF ((A.LE.THREE-EPS) .AND. (B.LE.THREE-EPS)) THEN
  125. C INSIDE SQUARE (0,3)X(0,3) IMPLIES OK.
  126. ISMON = ITRUE
  127. ELSE IF ((A.GT.FOUR+EPS) .AND. (B.GT.FOUR+EPS)) THEN
  128. C OUTSIDE SQUARE (0,4)X(0,4) IMPLIES NONMONOTONIC.
  129. ISMON = 2
  130. ELSE
  131. C MUST CHECK AGAINST BOUNDARY OF ELLIPSE.
  132. A = A - TWO
  133. B = B - TWO
  134. PHI = ((A*A + B*B) + A*B) - THREE
  135. IF (PHI .LT. -EPS) THEN
  136. ISMON = ITRUE
  137. ELSE IF (PHI .GT. EPS) THEN
  138. ISMON = 2
  139. ELSE
  140. C TO CLOSE TO BOUNDARY TO TELL,
  141. C IN THE PRESENCE OF ROUND-OFF ERRORS.
  142. ISMON = 3*ITRUE
  143. ENDIF
  144. ENDIF
  145. ENDIF
  146. C
  147. C RETURN VALUE.
  148. C
  149. DCHFCM = ISMON
  150. RETURN
  151. C------------- LAST LINE OF DCHFCM FOLLOWS -----------------------------
  152. END