denorm.f 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. *DECK DENORM
  2. DOUBLE PRECISION FUNCTION DENORM (N, X)
  3. C***BEGIN PROLOGUE DENORM
  4. C***SUBSIDIARY
  5. C***PURPOSE Subsidiary to DNSQ and DNSQE
  6. C***LIBRARY SLATEC
  7. C***TYPE DOUBLE PRECISION (ENORM-S, DENORM-D)
  8. C***AUTHOR (UNKNOWN)
  9. C***DESCRIPTION
  10. C
  11. C Given an N-vector X, this function calculates the
  12. C Euclidean norm of X.
  13. C
  14. C The Euclidean norm is computed by accumulating the sum of
  15. C squares in three different sums. The sums of squares for the
  16. C small and large components are scaled so that no overflows
  17. C occur. Non-destructive underflows are permitted. Underflows
  18. C and overflows do not occur in the computation of the unscaled
  19. C sum of squares for the intermediate components.
  20. C The definitions of small, intermediate and large components
  21. C depend on two constants, RDWARF and RGIANT. The main
  22. C restrictions on these constants are that RDWARF**2 not
  23. C underflow and RGIANT**2 not overflow. The constants
  24. C given here are suitable for every known computer.
  25. C
  26. C The function statement is
  27. C
  28. C DOUBLE PRECISION FUNCTION DENORM(N,X)
  29. C
  30. C where
  31. C
  32. C N is a positive integer input variable.
  33. C
  34. C X is an input array of length N.
  35. C
  36. C***SEE ALSO DNSQ, DNSQE
  37. C***ROUTINES CALLED (NONE)
  38. C***REVISION HISTORY (YYMMDD)
  39. C 800301 DATE WRITTEN
  40. C 890531 Changed all specific intrinsics to generic. (WRB)
  41. C 890831 Modified array declarations. (WRB)
  42. C 891214 Prologue converted to Version 4.0 format. (BAB)
  43. C 900326 Removed duplicate information from DESCRIPTION section.
  44. C (WRB)
  45. C 900328 Added TYPE section. (WRB)
  46. C***END PROLOGUE DENORM
  47. INTEGER I, N
  48. DOUBLE PRECISION AGIANT, FLOATN, ONE, RDWARF, RGIANT, S1, S2, S3,
  49. 1 X(*), X1MAX, X3MAX, XABS, ZERO
  50. SAVE ONE, ZERO, RDWARF, RGIANT
  51. DATA ONE,ZERO,RDWARF,RGIANT /1.0D0,0.0D0,3.834D-20,1.304D19/
  52. C***FIRST EXECUTABLE STATEMENT DENORM
  53. S1 = ZERO
  54. S2 = ZERO
  55. S3 = ZERO
  56. X1MAX = ZERO
  57. X3MAX = ZERO
  58. FLOATN = N
  59. AGIANT = RGIANT/FLOATN
  60. DO 90 I = 1, N
  61. XABS = ABS(X(I))
  62. IF (XABS .GT. RDWARF .AND. XABS .LT. AGIANT) GO TO 70
  63. IF (XABS .LE. RDWARF) GO TO 30
  64. C
  65. C SUM FOR LARGE COMPONENTS.
  66. C
  67. IF (XABS .LE. X1MAX) GO TO 10
  68. S1 = ONE + S1*(X1MAX/XABS)**2
  69. X1MAX = XABS
  70. GO TO 20
  71. 10 CONTINUE
  72. S1 = S1 + (XABS/X1MAX)**2
  73. 20 CONTINUE
  74. GO TO 60
  75. 30 CONTINUE
  76. C
  77. C SUM FOR SMALL COMPONENTS.
  78. C
  79. IF (XABS .LE. X3MAX) GO TO 40
  80. S3 = ONE + S3*(X3MAX/XABS)**2
  81. X3MAX = XABS
  82. GO TO 50
  83. 40 CONTINUE
  84. IF (XABS .NE. ZERO) S3 = S3 + (XABS/X3MAX)**2
  85. 50 CONTINUE
  86. 60 CONTINUE
  87. GO TO 80
  88. 70 CONTINUE
  89. C
  90. C SUM FOR INTERMEDIATE COMPONENTS.
  91. C
  92. S2 = S2 + XABS**2
  93. 80 CONTINUE
  94. 90 CONTINUE
  95. C
  96. C CALCULATION OF NORM.
  97. C
  98. IF (S1 .EQ. ZERO) GO TO 100
  99. DENORM = X1MAX*SQRT(S1+(S2/X1MAX)/X1MAX)
  100. GO TO 130
  101. 100 CONTINUE
  102. IF (S2 .EQ. ZERO) GO TO 110
  103. IF (S2 .GE. X3MAX)
  104. 1 DENORM = SQRT(S2*(ONE+(X3MAX/S2)*(X3MAX*S3)))
  105. IF (S2 .LT. X3MAX)
  106. 1 DENORM = SQRT(X3MAX*((S2/X3MAX)+(X3MAX*S3)))
  107. GO TO 120
  108. 110 CONTINUE
  109. DENORM = X3MAX*SQRT(S3)
  110. 120 CONTINUE
  111. 130 CONTINUE
  112. RETURN
  113. C
  114. C LAST CARD OF FUNCTION DENORM.
  115. C
  116. END