chfcm.f 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. *DECK CHFCM
  2. INTEGER FUNCTION CHFCM (D1, D2, DELTA)
  3. C***BEGIN PROLOGUE CHFCM
  4. C***SUBSIDIARY
  5. C***PURPOSE Check a single cubic for monotonicity.
  6. C***LIBRARY SLATEC (PCHIP)
  7. C***TYPE SINGLE PRECISION (CHFCM-S, DCHFCM-D)
  8. C***AUTHOR Fritsch, F. N., (LLNL)
  9. C***DESCRIPTION
  10. C
  11. C *Usage:
  12. C
  13. C REAL D1, D2, DELTA
  14. C INTEGER ISMON, CHFCM
  15. C
  16. C ISMON = CHFCM (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 CHFCM: Cubic Hermite Function -- Check Monotonicity.
  39. C
  40. C Called by PCHCM 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 CHFMC, 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 PCHCM
  53. C
  54. C***ROUTINES CALLED R1MACH
  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 890207 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 CHFMC to CHFCM, 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 CHFCM
  71. C
  72. C Fortran intrinsics used: SIGN.
  73. C Other routines used: R1MACH.
  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 double precision version, simply:
  83. C a. Change CHFCM to DCHFCM wherever it occurs,
  84. C b. Change the real declarations to double precision, and
  85. C c. Change the constants ZERO, ONE, ... to double precision.
  86. C
  87. C DECLARE ARGUMENTS.
  88. C
  89. REAL D1, D2, DELTA
  90. C
  91. C DECLARE LOCAL VARIABLES.
  92. C
  93. INTEGER ISMON, ITRUE
  94. REAL A, B, EPS, FOUR, ONE, PHI, TEN, THREE, TWO, ZERO
  95. SAVE ZERO, ONE, TWO, THREE, FOUR
  96. SAVE TEN
  97. C
  98. C INITIALIZE.
  99. C
  100. DATA ZERO /0./, ONE /1.0/, TWO /2./, THREE /3./, FOUR /4./,
  101. 1 TEN /10./
  102. C
  103. C MACHINE-DEPENDENT PARAMETER -- SHOULD BE ABOUT 10*UROUND.
  104. C***FIRST EXECUTABLE STATEMENT CHFCM
  105. EPS = TEN*R1MACH(4)
  106. C
  107. C MAKE THE CHECK.
  108. C
  109. IF (DELTA .EQ. ZERO) THEN
  110. C CASE OF CONSTANT DATA.
  111. IF ((D1.EQ.ZERO) .AND. (D2.EQ.ZERO)) THEN
  112. ISMON = 0
  113. ELSE
  114. ISMON = 2
  115. ENDIF
  116. ELSE
  117. C DATA IS NOT CONSTANT -- PICK UP SIGN.
  118. ITRUE = SIGN (ONE, DELTA)
  119. A = D1/DELTA
  120. B = D2/DELTA
  121. IF ((A.LT.ZERO) .OR. (B.LT.ZERO)) THEN
  122. ISMON = 2
  123. ELSE IF ((A.LE.THREE-EPS) .AND. (B.LE.THREE-EPS)) THEN
  124. C INSIDE SQUARE (0,3)X(0,3) IMPLIES OK.
  125. ISMON = ITRUE
  126. ELSE IF ((A.GT.FOUR+EPS) .AND. (B.GT.FOUR+EPS)) THEN
  127. C OUTSIDE SQUARE (0,4)X(0,4) IMPLIES NONMONOTONIC.
  128. ISMON = 2
  129. ELSE
  130. C MUST CHECK AGAINST BOUNDARY OF ELLIPSE.
  131. A = A - TWO
  132. B = B - TWO
  133. PHI = ((A*A + B*B) + A*B) - THREE
  134. IF (PHI .LT. -EPS) THEN
  135. ISMON = ITRUE
  136. ELSE IF (PHI .GT. EPS) THEN
  137. ISMON = 2
  138. ELSE
  139. C TO CLOSE TO BOUNDARY TO TELL,
  140. C IN THE PRESENCE OF ROUND-OFF ERRORS.
  141. ISMON = 3*ITRUE
  142. ENDIF
  143. ENDIF
  144. ENDIF
  145. C
  146. C RETURN VALUE.
  147. C
  148. CHFCM = ISMON
  149. RETURN
  150. C------------- LAST LINE OF CHFCM FOLLOWS ------------------------------
  151. END