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.

cungtr.f 7.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. *> \brief \b CUNGTR
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CUNGTR + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cungtr.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cungtr.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cungtr.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CUNGTR( UPLO, N, A, LDA, TAU, WORK, LWORK, INFO )
  22. *
  23. * .. Scalar Arguments ..
  24. * CHARACTER UPLO
  25. * INTEGER INFO, LDA, LWORK, N
  26. * ..
  27. * .. Array Arguments ..
  28. * COMPLEX A( LDA, * ), TAU( * ), WORK( * )
  29. * ..
  30. *
  31. *
  32. *> \par Purpose:
  33. * =============
  34. *>
  35. *> \verbatim
  36. *>
  37. *> CUNGTR generates a complex unitary matrix Q which is defined as the
  38. *> product of n-1 elementary reflectors of order N, as returned by
  39. *> CHETRD:
  40. *>
  41. *> if UPLO = 'U', Q = H(n-1) . . . H(2) H(1),
  42. *>
  43. *> if UPLO = 'L', Q = H(1) H(2) . . . H(n-1).
  44. *> \endverbatim
  45. *
  46. * Arguments:
  47. * ==========
  48. *
  49. *> \param[in] UPLO
  50. *> \verbatim
  51. *> UPLO is CHARACTER*1
  52. *> = 'U': Upper triangle of A contains elementary reflectors
  53. *> from CHETRD;
  54. *> = 'L': Lower triangle of A contains elementary reflectors
  55. *> from CHETRD.
  56. *> \endverbatim
  57. *>
  58. *> \param[in] N
  59. *> \verbatim
  60. *> N is INTEGER
  61. *> The order of the matrix Q. N >= 0.
  62. *> \endverbatim
  63. *>
  64. *> \param[in,out] A
  65. *> \verbatim
  66. *> A is COMPLEX array, dimension (LDA,N)
  67. *> On entry, the vectors which define the elementary reflectors,
  68. *> as returned by CHETRD.
  69. *> On exit, the N-by-N unitary matrix Q.
  70. *> \endverbatim
  71. *>
  72. *> \param[in] LDA
  73. *> \verbatim
  74. *> LDA is INTEGER
  75. *> The leading dimension of the array A. LDA >= N.
  76. *> \endverbatim
  77. *>
  78. *> \param[in] TAU
  79. *> \verbatim
  80. *> TAU is COMPLEX array, dimension (N-1)
  81. *> TAU(i) must contain the scalar factor of the elementary
  82. *> reflector H(i), as returned by CHETRD.
  83. *> \endverbatim
  84. *>
  85. *> \param[out] WORK
  86. *> \verbatim
  87. *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
  88. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  89. *> \endverbatim
  90. *>
  91. *> \param[in] LWORK
  92. *> \verbatim
  93. *> LWORK is INTEGER
  94. *> The dimension of the array WORK. LWORK >= N-1.
  95. *> For optimum performance LWORK >= (N-1)*NB, where NB is
  96. *> the optimal blocksize.
  97. *>
  98. *> If LWORK = -1, then a workspace query is assumed; the routine
  99. *> only calculates the optimal size of the WORK array, returns
  100. *> this value as the first entry of the WORK array, and no error
  101. *> message related to LWORK is issued by XERBLA.
  102. *> \endverbatim
  103. *>
  104. *> \param[out] INFO
  105. *> \verbatim
  106. *> INFO is INTEGER
  107. *> = 0: successful exit
  108. *> < 0: if INFO = -i, the i-th argument had an illegal value
  109. *> \endverbatim
  110. *
  111. * Authors:
  112. * ========
  113. *
  114. *> \author Univ. of Tennessee
  115. *> \author Univ. of California Berkeley
  116. *> \author Univ. of Colorado Denver
  117. *> \author NAG Ltd.
  118. *
  119. *> \ingroup ungtr
  120. *
  121. * =====================================================================
  122. SUBROUTINE CUNGTR( UPLO, N, A, LDA, TAU, WORK, LWORK, INFO )
  123. *
  124. * -- LAPACK computational routine --
  125. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  126. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  127. *
  128. * .. Scalar Arguments ..
  129. CHARACTER UPLO
  130. INTEGER INFO, LDA, LWORK, N
  131. * ..
  132. * .. Array Arguments ..
  133. COMPLEX A( LDA, * ), TAU( * ), WORK( * )
  134. * ..
  135. *
  136. * =====================================================================
  137. *
  138. * .. Parameters ..
  139. COMPLEX ZERO, ONE
  140. PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ),
  141. $ ONE = ( 1.0E+0, 0.0E+0 ) )
  142. * ..
  143. * .. Local Scalars ..
  144. LOGICAL LQUERY, UPPER
  145. INTEGER I, IINFO, J, LWKOPT, NB
  146. * ..
  147. * .. External Functions ..
  148. LOGICAL LSAME
  149. INTEGER ILAENV
  150. REAL SROUNDUP_LWORK
  151. EXTERNAL ILAENV, LSAME, SROUNDUP_LWORK
  152. * ..
  153. * .. External Subroutines ..
  154. EXTERNAL CUNGQL, CUNGQR, XERBLA
  155. * ..
  156. * .. Intrinsic Functions ..
  157. INTRINSIC MAX
  158. * ..
  159. * .. Executable Statements ..
  160. *
  161. * Test the input arguments
  162. *
  163. INFO = 0
  164. LQUERY = ( LWORK.EQ.-1 )
  165. UPPER = LSAME( UPLO, 'U' )
  166. IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  167. INFO = -1
  168. ELSE IF( N.LT.0 ) THEN
  169. INFO = -2
  170. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  171. INFO = -4
  172. ELSE IF( LWORK.LT.MAX( 1, N-1 ) .AND. .NOT.LQUERY ) THEN
  173. INFO = -7
  174. END IF
  175. *
  176. IF( INFO.EQ.0 ) THEN
  177. IF ( UPPER ) THEN
  178. NB = ILAENV( 1, 'CUNGQL', ' ', N-1, N-1, N-1, -1 )
  179. ELSE
  180. NB = ILAENV( 1, 'CUNGQR', ' ', N-1, N-1, N-1, -1 )
  181. END IF
  182. LWKOPT = MAX( 1, N-1 )*NB
  183. WORK( 1 ) = SROUNDUP_LWORK(LWKOPT)
  184. END IF
  185. *
  186. IF( INFO.NE.0 ) THEN
  187. CALL XERBLA( 'CUNGTR', -INFO )
  188. RETURN
  189. ELSE IF( LQUERY ) THEN
  190. RETURN
  191. END IF
  192. *
  193. * Quick return if possible
  194. *
  195. IF( N.EQ.0 ) THEN
  196. WORK( 1 ) = 1
  197. RETURN
  198. END IF
  199. *
  200. IF( UPPER ) THEN
  201. *
  202. * Q was determined by a call to CHETRD with UPLO = 'U'
  203. *
  204. * Shift the vectors which define the elementary reflectors one
  205. * column to the left, and set the last row and column of Q to
  206. * those of the unit matrix
  207. *
  208. DO 20 J = 1, N - 1
  209. DO 10 I = 1, J - 1
  210. A( I, J ) = A( I, J+1 )
  211. 10 CONTINUE
  212. A( N, J ) = ZERO
  213. 20 CONTINUE
  214. DO 30 I = 1, N - 1
  215. A( I, N ) = ZERO
  216. 30 CONTINUE
  217. A( N, N ) = ONE
  218. *
  219. * Generate Q(1:n-1,1:n-1)
  220. *
  221. CALL CUNGQL( N-1, N-1, N-1, A, LDA, TAU, WORK, LWORK, IINFO )
  222. *
  223. ELSE
  224. *
  225. * Q was determined by a call to CHETRD with UPLO = 'L'.
  226. *
  227. * Shift the vectors which define the elementary reflectors one
  228. * column to the right, and set the first row and column of Q to
  229. * those of the unit matrix
  230. *
  231. DO 50 J = N, 2, -1
  232. A( 1, J ) = ZERO
  233. DO 40 I = J + 1, N
  234. A( I, J ) = A( I, J-1 )
  235. 40 CONTINUE
  236. 50 CONTINUE
  237. A( 1, 1 ) = ONE
  238. DO 60 I = 2, N
  239. A( I, 1 ) = ZERO
  240. 60 CONTINUE
  241. IF( N.GT.1 ) THEN
  242. *
  243. * Generate Q(2:n,2:n)
  244. *
  245. CALL CUNGQR( N-1, N-1, N-1, A( 2, 2 ), LDA, TAU, WORK,
  246. $ LWORK, IINFO )
  247. END IF
  248. END IF
  249. WORK( 1 ) = SROUNDUP_LWORK(LWKOPT)
  250. RETURN
  251. *
  252. * End of CUNGTR
  253. *
  254. END