1*> \brief \b SGEQLS
2*
3*  =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6*            http://www.netlib.org/lapack/explore-html/
7*
8*  Definition:
9*  ===========
10*
11*       SUBROUTINE SGEQLS( M, N, NRHS, A, LDA, TAU, B, LDB, WORK, LWORK,
12*                          INFO )
13*
14*       .. Scalar Arguments ..
15*       INTEGER            INFO, LDA, LDB, LWORK, M, N, NRHS
16*       ..
17*       .. Array Arguments ..
18*       REAL               A( LDA, * ), B( LDB, * ), TAU( * ),
19*      $                   WORK( LWORK )
20*       ..
21*
22*
23*> \par Purpose:
24*  =============
25*>
26*> \verbatim
27*>
28*> Solve the least squares problem
29*>     min || A*X - B ||
30*> using the QL factorization
31*>     A = Q*L
32*> computed by SGEQLF.
33*> \endverbatim
34*
35*  Arguments:
36*  ==========
37*
38*> \param[in] M
39*> \verbatim
40*>          M is INTEGER
41*>          The number of rows of the matrix A.  M >= 0.
42*> \endverbatim
43*>
44*> \param[in] N
45*> \verbatim
46*>          N is INTEGER
47*>          The number of columns of the matrix A.  M >= N >= 0.
48*> \endverbatim
49*>
50*> \param[in] NRHS
51*> \verbatim
52*>          NRHS is INTEGER
53*>          The number of columns of B.  NRHS >= 0.
54*> \endverbatim
55*>
56*> \param[in] A
57*> \verbatim
58*>          A is REAL array, dimension (LDA,N)
59*>          Details of the QL factorization of the original matrix A as
60*>          returned by SGEQLF.
61*> \endverbatim
62*>
63*> \param[in] LDA
64*> \verbatim
65*>          LDA is INTEGER
66*>          The leading dimension of the array A.  LDA >= M.
67*> \endverbatim
68*>
69*> \param[in] TAU
70*> \verbatim
71*>          TAU is REAL array, dimension (N)
72*>          Details of the orthogonal matrix Q.
73*> \endverbatim
74*>
75*> \param[in,out] B
76*> \verbatim
77*>          B is REAL array, dimension (LDB,NRHS)
78*>          On entry, the m-by-nrhs right hand side matrix B.
79*>          On exit, the n-by-nrhs solution matrix X, stored in rows
80*>          m-n+1:m.
81*> \endverbatim
82*>
83*> \param[in] LDB
84*> \verbatim
85*>          LDB is INTEGER
86*>          The leading dimension of the array B. LDB >= M.
87*> \endverbatim
88*>
89*> \param[out] WORK
90*> \verbatim
91*>          WORK is REAL array, dimension (LWORK)
92*> \endverbatim
93*>
94*> \param[in] LWORK
95*> \verbatim
96*>          LWORK is INTEGER
97*>          The length of the array WORK.  LWORK must be at least NRHS,
98*>          and should be at least NRHS*NB, where NB is the block size
99*>          for this environment.
100*> \endverbatim
101*>
102*> \param[out] INFO
103*> \verbatim
104*>          INFO is INTEGER
105*>          = 0: successful exit
106*>          < 0: if INFO = -i, the i-th argument had an illegal value
107*> \endverbatim
108*
109*  Authors:
110*  ========
111*
112*> \author Univ. of Tennessee
113*> \author Univ. of California Berkeley
114*> \author Univ. of Colorado Denver
115*> \author NAG Ltd.
116*
117*> \ingroup single_lin
118*
119*  =====================================================================
120      SUBROUTINE SGEQLS( M, N, NRHS, A, LDA, TAU, B, LDB, WORK, LWORK,
121     $                   INFO )
122*
123*  -- LAPACK test routine --
124*  -- LAPACK is a software package provided by Univ. of Tennessee,    --
125*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
126*
127*     .. Scalar Arguments ..
128      INTEGER            INFO, LDA, LDB, LWORK, M, N, NRHS
129*     ..
130*     .. Array Arguments ..
131      REAL               A( LDA, * ), B( LDB, * ), TAU( * ),
132     $                   WORK( LWORK )
133*     ..
134*
135*  =====================================================================
136*
137*     .. Parameters ..
138      REAL               ONE
139      PARAMETER          ( ONE = 1.0E+0 )
140*     ..
141*     .. External Subroutines ..
142      EXTERNAL           SORMQL, STRSM, XERBLA
143*     ..
144*     .. Intrinsic Functions ..
145      INTRINSIC          MAX
146*     ..
147*     .. Executable Statements ..
148*
149*     Test the input arguments.
150*
151      INFO = 0
152      IF( M.LT.0 ) THEN
153         INFO = -1
154      ELSE IF( N.LT.0 .OR. N.GT.M ) THEN
155         INFO = -2
156      ELSE IF( NRHS.LT.0 ) THEN
157         INFO = -3
158      ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
159         INFO = -5
160      ELSE IF( LDB.LT.MAX( 1, M ) ) THEN
161         INFO = -8
162      ELSE IF( LWORK.LT.1 .OR. LWORK.LT.NRHS .AND. M.GT.0 .AND. N.GT.0 )
163     $          THEN
164         INFO = -10
165      END IF
166      IF( INFO.NE.0 ) THEN
167         CALL XERBLA( 'SGEQLS', -INFO )
168         RETURN
169      END IF
170*
171*     Quick return if possible
172*
173      IF( N.EQ.0 .OR. NRHS.EQ.0 .OR. M.EQ.0 )
174     $   RETURN
175*
176*     B := Q' * B
177*
178      CALL SORMQL( 'Left', 'Transpose', M, NRHS, N, A, LDA, TAU, B, LDB,
179     $             WORK, LWORK, INFO )
180*
181*     Solve L*X = B(m-n+1:m,:)
182*
183      CALL STRSM( 'Left', 'Lower', 'No transpose', 'Non-unit', N, NRHS,
184     $            ONE, A( M-N+1, 1 ), LDA, B( M-N+1, 1 ), LDB )
185*
186      RETURN
187*
188*     End of SGEQLS
189*
190      END
191