You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

slartgp.f 5.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. *> \brief \b SLARTGP generates a plane rotation so that the diagonal is nonnegative.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SLARTGP + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slartgp.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slartgp.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slartgp.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SLARTGP( F, G, CS, SN, R )
  22. *
  23. * .. Scalar Arguments ..
  24. * REAL CS, F, G, R, SN
  25. * ..
  26. *
  27. *
  28. *> \par Purpose:
  29. * =============
  30. *>
  31. *> \verbatim
  32. *>
  33. *> SLARTGP generates a plane rotation so that
  34. *>
  35. *> [ CS SN ] . [ F ] = [ R ] where CS**2 + SN**2 = 1.
  36. *> [ -SN CS ] [ G ] [ 0 ]
  37. *>
  38. *> This is a slower, more accurate version of the Level 1 BLAS routine SROTG,
  39. *> with the following other differences:
  40. *> F and G are unchanged on return.
  41. *> If G=0, then CS=(+/-)1 and SN=0.
  42. *> If F=0 and (G .ne. 0), then CS=0 and SN=(+/-)1.
  43. *>
  44. *> The sign is chosen so that R >= 0.
  45. *> \endverbatim
  46. *
  47. * Arguments:
  48. * ==========
  49. *
  50. *> \param[in] F
  51. *> \verbatim
  52. *> F is REAL
  53. *> The first component of vector to be rotated.
  54. *> \endverbatim
  55. *>
  56. *> \param[in] G
  57. *> \verbatim
  58. *> G is REAL
  59. *> The second component of vector to be rotated.
  60. *> \endverbatim
  61. *>
  62. *> \param[out] CS
  63. *> \verbatim
  64. *> CS is REAL
  65. *> The cosine of the rotation.
  66. *> \endverbatim
  67. *>
  68. *> \param[out] SN
  69. *> \verbatim
  70. *> SN is REAL
  71. *> The sine of the rotation.
  72. *> \endverbatim
  73. *>
  74. *> \param[out] R
  75. *> \verbatim
  76. *> R is REAL
  77. *> The nonzero component of the rotated vector.
  78. *>
  79. *> This version has a few statements commented out for thread safety
  80. *> (machine parameters are computed on each entry). 10 feb 03, SJH.
  81. *> \endverbatim
  82. *
  83. * Authors:
  84. * ========
  85. *
  86. *> \author Univ. of Tennessee
  87. *> \author Univ. of California Berkeley
  88. *> \author Univ. of Colorado Denver
  89. *> \author NAG Ltd.
  90. *
  91. *> \ingroup OTHERauxiliary
  92. *
  93. * =====================================================================
  94. SUBROUTINE SLARTGP( F, G, CS, SN, R )
  95. *
  96. * -- LAPACK auxiliary routine --
  97. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  98. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  99. *
  100. * .. Scalar Arguments ..
  101. REAL CS, F, G, R, SN
  102. * ..
  103. *
  104. * =====================================================================
  105. *
  106. * .. Parameters ..
  107. REAL ZERO
  108. PARAMETER ( ZERO = 0.0E0 )
  109. REAL ONE
  110. PARAMETER ( ONE = 1.0E0 )
  111. REAL TWO
  112. PARAMETER ( TWO = 2.0E0 )
  113. * ..
  114. * .. Local Scalars ..
  115. * LOGICAL FIRST
  116. INTEGER COUNT, I
  117. REAL EPS, F1, G1, SAFMIN, SAFMN2, SAFMX2, SCALE
  118. * ..
  119. * .. External Functions ..
  120. REAL SLAMCH
  121. EXTERNAL SLAMCH
  122. * ..
  123. * .. Intrinsic Functions ..
  124. INTRINSIC ABS, INT, LOG, MAX, SIGN, SQRT
  125. * ..
  126. * .. Save statement ..
  127. * SAVE FIRST, SAFMX2, SAFMIN, SAFMN2
  128. * ..
  129. * .. Data statements ..
  130. * DATA FIRST / .TRUE. /
  131. * ..
  132. * .. Executable Statements ..
  133. *
  134. * IF( FIRST ) THEN
  135. SAFMIN = SLAMCH( 'S' )
  136. EPS = SLAMCH( 'E' )
  137. SAFMN2 = SLAMCH( 'B' )**INT( LOG( SAFMIN / EPS ) /
  138. $ LOG( SLAMCH( 'B' ) ) / TWO )
  139. SAFMX2 = ONE / SAFMN2
  140. * FIRST = .FALSE.
  141. * END IF
  142. IF( G.EQ.ZERO ) THEN
  143. CS = SIGN( ONE, F )
  144. SN = ZERO
  145. R = ABS( F )
  146. ELSE IF( F.EQ.ZERO ) THEN
  147. CS = ZERO
  148. SN = SIGN( ONE, G )
  149. R = ABS( G )
  150. ELSE
  151. F1 = F
  152. G1 = G
  153. SCALE = MAX( ABS( F1 ), ABS( G1 ) )
  154. IF( SCALE.GE.SAFMX2 ) THEN
  155. COUNT = 0
  156. 10 CONTINUE
  157. COUNT = COUNT + 1
  158. F1 = F1*SAFMN2
  159. G1 = G1*SAFMN2
  160. SCALE = MAX( ABS( F1 ), ABS( G1 ) )
  161. IF( SCALE.GE.SAFMX2 .AND. COUNT .LT. 20)
  162. $ GO TO 10
  163. R = SQRT( F1**2+G1**2 )
  164. CS = F1 / R
  165. SN = G1 / R
  166. DO 20 I = 1, COUNT
  167. R = R*SAFMX2
  168. 20 CONTINUE
  169. ELSE IF( SCALE.LE.SAFMN2 ) THEN
  170. COUNT = 0
  171. 30 CONTINUE
  172. COUNT = COUNT + 1
  173. F1 = F1*SAFMX2
  174. G1 = G1*SAFMX2
  175. SCALE = MAX( ABS( F1 ), ABS( G1 ) )
  176. IF( SCALE.LE.SAFMN2 )
  177. $ GO TO 30
  178. R = SQRT( F1**2+G1**2 )
  179. CS = F1 / R
  180. SN = G1 / R
  181. DO 40 I = 1, COUNT
  182. R = R*SAFMN2
  183. 40 CONTINUE
  184. ELSE
  185. R = SQRT( F1**2+G1**2 )
  186. CS = F1 / R
  187. SN = G1 / R
  188. END IF
  189. IF( R.LT.ZERO ) THEN
  190. CS = -CS
  191. SN = -SN
  192. R = -R
  193. END IF
  194. END IF
  195. RETURN
  196. *
  197. * End of SLARTGP
  198. *
  199. END