190190* > The dimension of the array WORK.
191191* >
192192* > If LWORK = -1, then a workspace query is assumed; the routine
193- * > only calculates the optimal size of the WORK array, returns
194- * > this value as the first entry of the work array, and no error
195- * > message related to LWORK is issued by XERBLA.
193+ * > only calculates the optimal size of the WORK and RWORK
194+ * > arrays, returns this value as the first entry of the WORK
195+ * > and RWORK array, respectively, and no error message related
196+ * > to LWORK or LRWORK is issued by XERBLA.
196197* > \endverbatim
197198* >
198199* > \param[out] RWORK
211212* > LRWORK is INTEGER
212213* > The dimension of the array RWORK.
213214* >
214- * > If LRWORK = -1, then a workspace query is assumed; the routine
215- * > only calculates the optimal size of the RWORK array, returns
216- * > this value as the first entry of the work array, and no error
217- * > message related to LRWORK is issued by XERBLA.
215+ * > If LRWORK=-1, then a workspace query is assumed; the routine
216+ * > only calculates the optimal size of the WORK and RWORK
217+ * > arrays, returns this value as the first entry of the WORK
218+ * > and RWORK array, respectively, and no error message related
219+ * > to LWORK or LRWORK is issued by XERBLA.
218220* > \endverbatim
219221*
220222* > \param[out] IWORK
@@ -313,7 +315,7 @@ SUBROUTINE CUNCSD2BY1( JOBU1, JOBU2, JOBV1T, M, P, Q, X11, LDX11,
313315 WANTU1 = LSAME( JOBU1, ' Y' )
314316 WANTU2 = LSAME( JOBU2, ' Y' )
315317 WANTV1T = LSAME( JOBV1T, ' Y' )
316- LQUERY = LWORK .EQ. - 1
318+ LQUERY = ( LWORK .EQ. - 1 ) .OR. ( LRWORK .EQ. - 1 )
317319*
318320 IF ( M .LT. 0 ) THEN
319321 INFO = - 4
@@ -513,6 +515,9 @@ SUBROUTINE CUNCSD2BY1( JOBU1, JOBU2, JOBV1T, M, P, Q, X11, LDX11,
513515 IF ( LWORK .LT. LWORKMIN .AND. .NOT. LQUERY ) THEN
514516 INFO = - 19
515517 END IF
518+ IF ( LRWORK .LT. LRWORKMIN .AND. .NOT. LQUERY ) THEN
519+ INFO = - 21
520+ END IF
516521 END IF
517522 IF ( INFO .NE. 0 ) THEN
518523 CALL XERBLA( ' CUNCSD2BY1' , - INFO )
@@ -566,8 +571,8 @@ SUBROUTINE CUNCSD2BY1( JOBU1, JOBU2, JOBV1T, M, P, Q, X11, LDX11,
566571 $ RWORK(IPHI), U1, LDU1, U2, LDU2, V1T, LDV1T, CDUM,
567572 $ 1 , RWORK(IB11D), RWORK(IB11E), RWORK(IB12D),
568573 $ RWORK(IB12E), RWORK(IB21D), RWORK(IB21E),
569- $ RWORK(IB22D), RWORK(IB22E), RWORK(IBBCSD), LBBCSD,
570- $ CHILDINFO )
574+ $ RWORK(IB22D), RWORK(IB22E), RWORK(IBBCSD),
575+ $ LRWORK - IBBCSD +1 , CHILDINFO )
571576*
572577* Permute rows and columns to place zero submatrices in
573578* preferred positions
@@ -708,6 +713,10 @@ SUBROUTINE CUNCSD2BY1( JOBU1, JOBU2, JOBV1T, M, P, Q, X11, LDX11,
708713*
709714* Accumulate Householder reflectors
710715*
716+
717+ IF ( WANTU2 .AND. M- P .GT. 0 ) THEN
718+ CALL CCOPY( M- P, WORK(IORBDB+ P), 1 , U2, 1 )
719+ END IF
711720 IF ( WANTU1 .AND. P .GT. 0 ) THEN
712721 CALL CCOPY( P, WORK(IORBDB), 1 , U1, 1 )
713722 DO J = 2 , P
@@ -719,7 +728,6 @@ SUBROUTINE CUNCSD2BY1( JOBU1, JOBU2, JOBV1T, M, P, Q, X11, LDX11,
719728 $ WORK(IORGQR), LORGQR, CHILDINFO )
720729 END IF
721730 IF ( WANTU2 .AND. M- P .GT. 0 ) THEN
722- CALL CCOPY( M- P, WORK(IORBDB+ P), 1 , U2, 1 )
723731 DO J = 2 , M- P
724732 U2(1 ,J) = ZERO
725733 END DO
0 commit comments