00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016
00017
00018 static integer c__10 = 10;
00019 static integer c__1 = 1;
00020 static integer c__0 = 0;
00021 static doublereal c_b15 = 1.;
00022
00023 doublereal zqrt14_(char *trans, integer *m, integer *n, integer *nrhs,
00024 doublecomplex *a, integer *lda, doublecomplex *x, integer *ldx,
00025 doublecomplex *work, integer *lwork)
00026 {
00027
00028 integer a_dim1, a_offset, x_dim1, x_offset, i__1, i__2, i__3;
00029 doublereal ret_val, d__1, d__2;
00030 doublecomplex z__1;
00031
00032
00033 double z_abs(doublecomplex *);
00034 void d_cnjg(doublecomplex *, doublecomplex *);
00035
00036
00037 integer i__, j;
00038 doublereal err;
00039 integer info;
00040 doublereal anrm;
00041 logical tpsd;
00042 doublereal xnrm;
00043 extern logical lsame_(char *, char *);
00044 doublereal rwork[1];
00045 extern int zgelq2_(integer *, integer *, doublecomplex *,
00046 integer *, doublecomplex *, doublecomplex *, integer *), zgeqr2_(
00047 integer *, integer *, doublecomplex *, integer *, doublecomplex *,
00048 doublecomplex *, integer *);
00049 extern doublereal dlamch_(char *);
00050 extern int xerbla_(char *, integer *);
00051 extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
00052 integer *, doublereal *);
00053 extern int zlascl_(char *, integer *, integer *,
00054 doublereal *, doublereal *, integer *, integer *, doublecomplex *,
00055 integer *, integer *);
00056 integer ldwork;
00057 extern int zlacpy_(char *, integer *, integer *,
00058 doublecomplex *, integer *, doublecomplex *, integer *);
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 a_dim1 = *lda;
00135 a_offset = 1 + a_dim1;
00136 a -= a_offset;
00137 x_dim1 = *ldx;
00138 x_offset = 1 + x_dim1;
00139 x -= x_offset;
00140 --work;
00141
00142
00143 ret_val = 0.;
00144 if (lsame_(trans, "N")) {
00145 ldwork = *m + *nrhs;
00146 tpsd = FALSE_;
00147 if (*lwork < (*m + *nrhs) * (*n + 2)) {
00148 xerbla_("ZQRT14", &c__10);
00149 return ret_val;
00150 } else if (*n <= 0 || *nrhs <= 0) {
00151 return ret_val;
00152 }
00153 } else if (lsame_(trans, "C")) {
00154 ldwork = *m;
00155 tpsd = TRUE_;
00156 if (*lwork < (*n + *nrhs) * (*m + 2)) {
00157 xerbla_("ZQRT14", &c__10);
00158 return ret_val;
00159 } else if (*m <= 0 || *nrhs <= 0) {
00160 return ret_val;
00161 }
00162 } else {
00163 xerbla_("ZQRT14", &c__1);
00164 return ret_val;
00165 }
00166
00167
00168
00169 zlacpy_("All", m, n, &a[a_offset], lda, &work[1], &ldwork);
00170 anrm = zlange_("M", m, n, &work[1], &ldwork, rwork);
00171 if (anrm != 0.) {
00172 zlascl_("G", &c__0, &c__0, &anrm, &c_b15, m, n, &work[1], &ldwork, &
00173 info);
00174 }
00175
00176
00177
00178 if (tpsd) {
00179
00180
00181
00182 zlacpy_("All", m, nrhs, &x[x_offset], ldx, &work[*n * ldwork + 1], &
00183 ldwork);
00184 xnrm = zlange_("M", m, nrhs, &work[*n * ldwork + 1], &ldwork, rwork);
00185 if (xnrm != 0.) {
00186 zlascl_("G", &c__0, &c__0, &xnrm, &c_b15, m, nrhs, &work[*n *
00187 ldwork + 1], &ldwork, &info);
00188 }
00189 i__1 = *n + *nrhs;
00190 anrm = zlange_("One-norm", m, &i__1, &work[1], &ldwork, rwork);
00191
00192
00193
00194 i__1 = *n + *nrhs;
00195
00196 i__2 = *m, i__3 = *n + *nrhs;
00197 zgeqr2_(m, &i__1, &work[1], &ldwork, &work[ldwork * (*n + *nrhs) + 1],
00198 &work[ldwork * (*n + *nrhs) + min(i__2, i__3)+ 1], &info);
00199
00200
00201
00202
00203 err = 0.;
00204 i__1 = *n + *nrhs;
00205 for (j = *n + 1; j <= i__1; ++j) {
00206 i__2 = min(*m,j);
00207 for (i__ = *n + 1; i__ <= i__2; ++i__) {
00208
00209 d__1 = err, d__2 = z_abs(&work[i__ + (j - 1) * *m]);
00210 err = max(d__1,d__2);
00211
00212 }
00213
00214 }
00215
00216 } else {
00217
00218
00219
00220 i__1 = *n;
00221 for (i__ = 1; i__ <= i__1; ++i__) {
00222 i__2 = *nrhs;
00223 for (j = 1; j <= i__2; ++j) {
00224 i__3 = *m + j + (i__ - 1) * ldwork;
00225 d_cnjg(&z__1, &x[i__ + j * x_dim1]);
00226 work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00227
00228 }
00229
00230 }
00231
00232 xnrm = zlange_("M", nrhs, n, &work[*m + 1], &ldwork, rwork)
00233 ;
00234 if (xnrm != 0.) {
00235 zlascl_("G", &c__0, &c__0, &xnrm, &c_b15, nrhs, n, &work[*m + 1],
00236 &ldwork, &info);
00237 }
00238
00239
00240
00241 zgelq2_(&ldwork, n, &work[1], &ldwork, &work[ldwork * *n + 1], &work[
00242 ldwork * (*n + 1) + 1], &info);
00243
00244
00245
00246
00247 err = 0.;
00248 i__1 = *n;
00249 for (j = *m + 1; j <= i__1; ++j) {
00250 i__2 = ldwork;
00251 for (i__ = j; i__ <= i__2; ++i__) {
00252
00253 d__1 = err, d__2 = z_abs(&work[i__ + (j - 1) * ldwork]);
00254 err = max(d__1,d__2);
00255
00256 }
00257
00258 }
00259
00260 }
00261
00262
00263 i__1 = max(*m,*n);
00264 ret_val = err / ((doublereal) max(i__1,*nrhs) * dlamch_("Epsilon"));
00265
00266 return ret_val;
00267
00268
00269
00270 }