| 1 | /* minpack/qrsolv.f -- translated by f2c (version 20050501). |
| 2 | You must link the resulting object file with libf2c: |
| 3 | on Microsoft Windows system, link with libf2c.lib; |
| 4 | on Linux or Unix systems, link with .../path/to/libf2c.a -lm |
| 5 | or, if you install libf2c.a in a standard place, with -lf2c -lm |
| 6 | -- in that order, at the end of the command line, as in |
| 7 | cc *.o -lf2c -lm |
| 8 | Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., |
| 9 | |
| 10 | http://www.netlib.org/f2c/libf2c.zip |
| 11 | */ |
| 12 | |
| 13 | #ifdef __cplusplus |
| 14 | extern "C" { |
| 15 | #endif |
| 16 | #include "v3p_netlib.h"cxx . . $ `<file>/Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_netlib.h`/ |
| 17 | |
| 18 | /*< subroutine qrsolv(n,r,ldr,ipvt,diag,qtb,x,sdiag,wa) >*/ |
| 19 | /* Subroutine */ int qrsolv_cxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_netlib_mangle.h:209:9`!(integercxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:63:9`! *n, doublerealcxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:57:9`! *r__, integercxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:63:9`! *ldr, |
| 20 | integercxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:63:9`! *ipvt, doublerealcxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:57:9`! *diag, doublerealcxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:57:9`! *qtb, doublerealcxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:57:9`! *x, |
| 21 | doublerealcxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:57:9`! *sdiag, doublerealcxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:57:9`! *wa) |
| 22 | { |
| 23 | /* Initialized data */ |
| 24 | |
| 25 | static doublerealcxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:57:9`! p5 = .5; /* constant */ |
| 26 | static doublerealcxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:57:9`! p25 = .25; /* constant */ |
| 27 | static doublerealcxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:57:9`! zero = 0.; /* constant */ |
| 28 | |
| 29 | /* System generated locals */ |
| 30 | integercxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:63:9`! r_dim1, r_offset, i__1, i__2, i__3; |
| 31 | doublerealcxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:57:9`! d__1, d__2; |
| 32 | |
| 33 | /* Builtin functions */ |
| 34 | double sqrtcxx . . $ sqrt(447c67c6676f75c3).(doublerealcxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:57:9`!); |
| 35 | |
| 36 | /* Local variables */ |
| 37 | integercxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:63:9`! i__, j, k, l, jp1, kp1; |
| 38 | doublerealcxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:57:9`! tan__, cos__, sin__, sum, temp, cotan; |
| 39 | integercxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:63:9`! nsing; |
| 40 | doublerealcxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_mangle.h:57:9`! qtbpj; |
| 41 | |
| 42 | /*< integer n,ldr >*/ |
| 43 | /*< integer ipvt(n) >*/ |
| 44 | /*< double precision r(ldr,n),diag(n),qtb(n),x(n),sdiag(n),wa(n) >*/ |
| 45 | /* ********** */ |
| 46 | |
| 47 | /* subroutine qrsolv */ |
| 48 | |
| 49 | /* given an m by n matrix a, an n by n diagonal matrix d, */ |
| 50 | /* and an m-vector b, the problem is to determine an x which */ |
| 51 | /* solves the system */ |
| 52 | |
| 53 | /* a*x = b , d*x = 0 , */ |
| 54 | |
| 55 | /* in the least squares sense. */ |
| 56 | |
| 57 | /* this subroutine completes the solution of the problem */ |
| 58 | /* if it is provided with the necessary information from the */ |
| 59 | /* qr factorization, with column pivoting, of a. that is, if */ |
| 60 | /* a*p = q*r, where p is a permutation matrix, q has orthogonal */ |
| 61 | /* columns, and r is an upper triangular matrix with diagonal */ |
| 62 | /* elements of nonincreasing magnitude, then qrsolv expects */ |
| 63 | /* the full upper triangle of r, the permutation matrix p, */ |
| 64 | /* and the first n components of (q transpose)*b. the system */ |
| 65 | /* a*x = b, d*x = 0, is then equivalent to */ |
| 66 | |
| 67 | /* t t */ |
| 68 | /* r*z = q *b , p *d*p*z = 0 , */ |
| 69 | |
| 70 | /* where x = p*z. if this system does not have full rank, */ |
| 71 | /* then a least squares solution is obtained. on output qrsolv */ |
| 72 | /* also provides an upper triangular matrix s such that */ |
| 73 | |
| 74 | /* t t t */ |
| 75 | /* p *(a *a + d*d)*p = s *s . */ |
| 76 | |
| 77 | /* s is computed within qrsolv and may be of separate interest. */ |
| 78 | |
| 79 | /* the subroutine statement is */ |
| 80 | |
| 81 | /* subroutine qrsolv(n,r,ldr,ipvt,diag,qtb,x,sdiag,wa) */ |
| 82 | |
| 83 | /* where */ |
| 84 | |
| 85 | /* n is a positive integer input variable set to the order of r. */ |
| 86 | |
| 87 | /* r is an n by n array. on input the full upper triangle */ |
| 88 | /* must contain the full upper triangle of the matrix r. */ |
| 89 | /* on output the full upper triangle is unaltered, and the */ |
| 90 | /* strict lower triangle contains the strict upper triangle */ |
| 91 | /* (transposed) of the upper triangular matrix s. */ |
| 92 | |
| 93 | /* ldr is a positive integer input variable not less than n */ |
| 94 | /* which specifies the leading dimension of the array r. */ |
| 95 | |
| 96 | /* ipvt is an integer input array of length n which defines the */ |
| 97 | /* permutation matrix p such that a*p = q*r. column j of p */ |
| 98 | /* is column ipvt(j) of the identity matrix. */ |
| 99 | |
| 100 | /* diag is an input array of length n which must contain the */ |
| 101 | /* diagonal elements of the matrix d. */ |
| 102 | |
| 103 | /* qtb is an input array of length n which must contain the first */ |
| 104 | /* n elements of the vector (q transpose)*b. */ |
| 105 | |
| 106 | /* x is an output array of length n which contains the least */ |
| 107 | /* squares solution of the system a*x = b, d*x = 0. */ |
| 108 | |
| 109 | /* sdiag is an output array of length n which contains the */ |
| 110 | /* diagonal elements of the upper triangular matrix s. */ |
| 111 | |
| 112 | /* wa is a work array of length n. */ |
| 113 | |
| 114 | /* subprograms called */ |
| 115 | |
| 116 | /* fortran-supplied ... dabs,dsqrt */ |
| 117 | |
| 118 | /* argonne national laboratory. minpack project. march 1980. */ |
| 119 | /* burton s. garbow, kenneth e. hillstrom, jorge j. more */ |
| 120 | |
| 121 | /* ********** */ |
| 122 | /*< integer i,j,jp1,k,kp1,l,nsing >*/ |
| 123 | /*< double precision cos,cotan,p5,p25,qtbpj,sin,sum,tan,temp,zero >*/ |
| 124 | /*< data p5,p25,zero /5.0d-1,2.5d-1,0.0d0/ >*/ |
| 125 | /* Parameter adjustments */ |
| 126 | --wa; |
| 127 | --sdiag; |
| 128 | --x; |
| 129 | --qtb; |
| 130 | --diag; |
| 131 | --ipvt; |
| 132 | r_dim1 = *ldr; |
| 133 | r_offset = 1 + r_dim1; |
| 134 | r__ -= r_offset; |
| 135 | |
| 136 | /* Function Body */ |
| 137 | |
| 138 | /* copy r and (q transpose)*b to preserve input and initialize s. */ |
| 139 | /* in particular, save the diagonal elements of r in x. */ |
| 140 | |
| 141 | /*< do 20 j = 1, n >*/ |
| 142 | i__1 = *n; |
| 143 | for (j = 1; j <= i__1; ++j) { |
| 144 | /*< do 10 i = j, n >*/ |
| 145 | i__2 = *n; |
| 146 | for (i__ = j; i__ <= i__2; ++i__) { |
| 147 | /*< r(i,j) = r(j,i) >*/ |
| 148 | r__[i__ + j * r_dim1] = r__[j + i__ * r_dim1]; |
| 149 | /*< 10 continue >*/ |
| 150 | /* L10: */ |
| 151 | } |
| 152 | /*< x(j) = r(j,j) >*/ |
| 153 | x[j] = r__[j + j * r_dim1]; |
| 154 | /*< wa(j) = qtb(j) >*/ |
| 155 | wa[j] = qtb[j]; |
| 156 | /*< 20 continue >*/ |
| 157 | /* L20: */ |
| 158 | } |
| 159 | |
| 160 | /* eliminate the diagonal matrix d using a givens rotation. */ |
| 161 | |
| 162 | /*< do 100 j = 1, n >*/ |
| 163 | i__1 = *n; |
| 164 | for (j = 1; j <= i__1; ++j) { |
| 165 | |
| 166 | /* prepare the row of d to be eliminated, locating the */ |
| 167 | /* diagonal element using p from the qr factorization. */ |
| 168 | |
| 169 | /*< l = ipvt(j) >*/ |
| 170 | l = ipvt[j]; |
| 171 | /*< if (diag(l) .eq. zero) go to 90 >*/ |
| 172 | if (diag[l] == zero) { |
| 173 | goto L90; |
| 174 | } |
| 175 | /*< do 30 k = j, n >*/ |
| 176 | i__2 = *n; |
| 177 | for (k = j; k <= i__2; ++k) { |
| 178 | /*< sdiag(k) = zero >*/ |
| 179 | sdiag[k] = zero; |
| 180 | /*< 30 continue >*/ |
| 181 | /* L30: */ |
| 182 | } |
| 183 | /*< sdiag(j) = diag(l) >*/ |
| 184 | sdiag[j] = diag[l]; |
| 185 | |
| 186 | /* the transformations to eliminate the row of d */ |
| 187 | /* modify only a single element of (q transpose)*b */ |
| 188 | /* beyond the first n, which is initially zero. */ |
| 189 | |
| 190 | /*< qtbpj = zero >*/ |
| 191 | qtbpj = zero; |
| 192 | /*< do 80 k = j, n >*/ |
| 193 | i__2 = *n; |
| 194 | for (k = j; k <= i__2; ++k) { |
| 195 | |
| 196 | /* determine a givens rotation which eliminates the */ |
| 197 | /* appropriate element in the current row of d. */ |
| 198 | |
| 199 | /*< if (sdiag(k) .eq. zero) go to 70 >*/ |
| 200 | if (sdiag[k] == zero) { |
| 201 | goto L70; |
| 202 | } |
| 203 | /*< if (dabs(r(k,k)) .ge. dabs(sdiag(k))) go to 40 >*/ |
| 204 | if ((d__1 = r__[k + k * r_dim1], abscxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_original.h:157:9`!(d__1)) >= (d__2 = sdiag[k], |
| 205 | abscxx . . $ `Modules/ThirdParty/VNL/src/vxl/v3p/netlib/v3p_f2c_original.h:157:9`!(d__2))) { |
| 206 | goto L40; |
| 207 | } |
| 208 | /*< cotan = r(k,k)/sdiag(k) >*/ |
| 209 | cotan = r__[k + k * r_dim1] / sdiag[k]; |
| 210 | /*< sin = p5/dsqrt(p25+p25*cotan**2) >*/ |
| 211 | /* Computing 2nd power */ |
| 212 | d__1 = cotan; |
| 213 | sin__ = p5 / sqrtcxx . . $ sqrt(447c67c6676f75c3).(p25 + p25 * (d__1 * d__1)); |
| 214 | /*< cos = sin*cotan >*/ |
| 215 | cos__ = sin__ * cotan; |
| 216 | /*< go to 50 >*/ |
| 217 | goto L50; |
| 218 | /*< 40 continue >*/ |
| 219 | L40: |
| 220 | /*< tan = sdiag(k)/r(k,k) >*/ |
| 221 | tan__ = sdiag[k] / r__[k + k * r_dim1]; |
| 222 | /*< cos = p5/dsqrt(p25+p25*tan**2) >*/ |
| 223 | /* Computing 2nd power */ |
| 224 | d__1 = tan__; |
| 225 | cos__ = p5 / sqrtcxx . . $ sqrt(447c67c6676f75c3).(p25 + p25 * (d__1 * d__1)); |
| 226 | /*< sin = cos*tan >*/ |
| 227 | sin__ = cos__ * tan__; |
| 228 | /*< 50 continue >*/ |
| 229 | L50: |
| 230 | |
| 231 | /* compute the modified diagonal element of r and */ |
| 232 | /* the modified element of ((q transpose)*b,0). */ |
| 233 | |
| 234 | /*< r(k,k) = cos*r(k,k) + sin*sdiag(k) >*/ |
| 235 | r__[k + k * r_dim1] = cos__ * r__[k + k * r_dim1] + sin__ * sdiag[ |
| 236 | k]; |
| 237 | /*< temp = cos*wa(k) + sin*qtbpj >*/ |
| 238 | temp = cos__ * wa[k] + sin__ * qtbpj; |
| 239 | /*< qtbpj = -sin*wa(k) + cos*qtbpj >*/ |
| 240 | qtbpj = -sin__ * wa[k] + cos__ * qtbpj; |
| 241 | /*< wa(k) = temp >*/ |
| 242 | wa[k] = temp; |
| 243 | |
| 244 | /* accumulate the transformation in the row of s. */ |
| 245 | |
| 246 | /*< kp1 = k + 1 >*/ |
| 247 | kp1 = k + 1; |
| 248 | /*< if (n .lt. kp1) go to 70 >*/ |
| 249 | if (*n < kp1) { |
| 250 | goto L70; |
| 251 | } |
| 252 | /*< do 60 i = kp1, n >*/ |
| 253 | i__3 = *n; |
| 254 | for (i__ = kp1; i__ <= i__3; ++i__) { |
| 255 | /*< temp = cos*r(i,k) + sin*sdiag(i) >*/ |
| 256 | temp = cos__ * r__[i__ + k * r_dim1] + sin__ * sdiag[i__]; |
| 257 | /*< sdiag(i) = -sin*r(i,k) + cos*sdiag(i) >*/ |
| 258 | sdiag[i__] = -sin__ * r__[i__ + k * r_dim1] + cos__ * sdiag[ |
| 259 | i__]; |
| 260 | /*< r(i,k) = temp >*/ |
| 261 | r__[i__ + k * r_dim1] = temp; |
| 262 | /*< 60 continue >*/ |
| 263 | /* L60: */ |
| 264 | } |
| 265 | /*< 70 continue >*/ |
| 266 | L70: |
| 267 | /*< 80 continue >*/ |
| 268 | /* L80: */ |
| 269 | ; |
| 270 | } |
| 271 | /*< 90 continue >*/ |
| 272 | L90: |
| 273 | |
| 274 | /* store the diagonal element of s and restore */ |
| 275 | /* the corresponding diagonal element of r. */ |
| 276 | |
| 277 | /*< sdiag(j) = r(j,j) >*/ |
| 278 | sdiag[j] = r__[j + j * r_dim1]; |
| 279 | /*< r(j,j) = x(j) >*/ |
| 280 | r__[j + j * r_dim1] = x[j]; |
| 281 | /*< 100 continue >*/ |
| 282 | /* L100: */ |
| 283 | } |
| 284 | |
| 285 | /* solve the triangular system for z. if the system is */ |
| 286 | /* singular, then obtain a least squares solution. */ |
| 287 | |
| 288 | /*< nsing = n >*/ |
| 289 | nsing = *n; |
| 290 | /*< do 110 j = 1, n >*/ |
| 291 | i__1 = *n; |
| 292 | for (j = 1; j <= i__1; ++j) { |
| 293 | /*< if (sdiag(j) .eq. zero .and. nsing .eq. n) nsing = j - 1 >*/ |
| 294 | if (sdiag[j] == zero && nsing == *n) { |
| 295 | nsing = j - 1; |
| 296 | } |
| 297 | /*< if (nsing .lt. n) wa(j) = zero >*/ |
| 298 | if (nsing < *n) { |
| 299 | wa[j] = zero; |
| 300 | } |
| 301 | /*< 110 continue >*/ |
| 302 | /* L110: */ |
| 303 | } |
| 304 | /*< if (nsing .lt. 1) go to 150 >*/ |
| 305 | if (nsing < 1) { |
| 306 | goto L150; |
| 307 | } |
| 308 | /*< do 140 k = 1, nsing >*/ |
| 309 | i__1 = nsing; |
| 310 | for (k = 1; k <= i__1; ++k) { |
| 311 | /*< j = nsing - k + 1 >*/ |
| 312 | j = nsing - k + 1; |
| 313 | /*< sum = zero >*/ |
| 314 | sum = zero; |
| 315 | /*< jp1 = j + 1 >*/ |
| 316 | jp1 = j + 1; |
| 317 | /*< if (nsing .lt. jp1) go to 130 >*/ |
| 318 | if (nsing < jp1) { |
| 319 | goto L130; |
| 320 | } |
| 321 | /*< do 120 i = jp1, nsing >*/ |
| 322 | i__2 = nsing; |
| 323 | for (i__ = jp1; i__ <= i__2; ++i__) { |
| 324 | /*< sum = sum + r(i,j)*wa(i) >*/ |
| 325 | sum += r__[i__ + j * r_dim1] * wa[i__]; |
| 326 | /*< 120 continue >*/ |
| 327 | /* L120: */ |
| 328 | } |
| 329 | /*< 130 continue >*/ |
| 330 | L130: |
| 331 | /*< wa(j) = (wa(j) - sum)/sdiag(j) >*/ |
| 332 | wa[j] = (wa[j] - sum) / sdiag[j]; |
| 333 | /*< 140 continue >*/ |
| 334 | /* L140: */ |
| 335 | } |
| 336 | /*< 150 continue >*/ |
| 337 | L150: |
| 338 | |
| 339 | /* permute the components of z back to components of x. */ |
| 340 | |
| 341 | /*< do 160 j = 1, n >*/ |
| 342 | i__1 = *n; |
| 343 | for (j = 1; j <= i__1; ++j) { |
| 344 | /*< l = ipvt(j) >*/ |
| 345 | l = ipvt[j]; |
| 346 | /*< x(l) = wa(j) >*/ |
| 347 | x[l] = wa[j]; |
| 348 | /*< 160 continue >*/ |
| 349 | /* L160: */ |
| 350 | } |
| 351 | /*< return >*/ |
| 352 | return 0; |
| 353 | |
| 354 | /* last card of subroutine qrsolv. */ |
| 355 | |
| 356 | /*< end >*/ |
| 357 | } /* qrsolv_ */ |
| 358 | |
| 359 | #ifdef __cplusplus |
| 360 | } |
| 361 | #endif |