AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dchud_c.c
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
6 // Copyright (2003) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 /* translated by f2c from dchud.f and hand modified. */
45 
46 #include "Moocho_Config.h"
47 
48 
49 #if !defined(HAVE_MOOCHO_FORTRAN)
50 
51 
53 #include <math.h>
54 
55 
56 void dchud_c(double r__[], int *ldr, int *p,
57  double x[], double z__[], int *ldz, int *nz,
58  double y[], double *rho, double c__[], double s[]
59  )
60 /*
61 double *r__;
62 int *ldr, *p;
63 double *x, *z__;
64 int *ldz, *nz;
65 double *y, *rho, *c__, *s;
66 */
67 {
68  /* System generated locals */
69  int r_dim1, r_offset, z_dim1, z_offset, i__1, i__2;
70  double d__1, d__2;
71 
72  /* Local variables */
73  double zeta;
74  int i__, j;
75  double t, scale, azeta;
76  double xj;
77  int jm1;
78 
79 /* ***FIRST EXECUTABLE STATEMENT DCHUD */
80  /* Parameter adjustments */
81  r_dim1 = *ldr;
82  r_offset = 1 + r_dim1 * 1;
83  r__ -= r_offset;
84  --x;
85  z_dim1 = *ldz;
86  z_offset = 1 + z_dim1 * 1;
87  z__ -= z_offset;
88  --y;
89  --rho;
90  --c__;
91  --s;
92 
93  /* Function Body */
94  i__1 = *p;
95  for (j = 1; j <= i__1; ++j) {
96  xj = x[j];
97 
98 /* APPLY THE PREVIOUS ROTATIONS. */
99 
100  jm1 = j - 1;
101  if (jm1 < 1) {
102  goto L20;
103  }
104  i__2 = jm1;
105  for (i__ = 1; i__ <= i__2; ++i__) {
106  t = c__[i__] * r__[i__ + j * r_dim1] + s[i__] * xj;
107  xj = c__[i__] * xj - s[i__] * r__[i__ + j * r_dim1];
108  r__[i__ + j * r_dim1] = t;
109 /* L10: */
110  }
111 L20:
112 
113 /* COMPUTE THE NEXT ROTATION. */
114 
115  DROTG_F77(&r__[j + j * r_dim1], &xj, &c__[j], &s[j]);
116 /* L30: */
117  }
118 
119 /* IF REQUIRED, UPDATE Z AND RHO. */
120 
121  if (*nz < 1) {
122  goto L70;
123  }
124  i__1 = *nz;
125  for (j = 1; j <= i__1; ++j) {
126  zeta = y[j];
127  i__2 = *p;
128  for (i__ = 1; i__ <= i__2; ++i__) {
129  t = c__[i__] * z__[i__ + j * z_dim1] + s[i__] * zeta;
130  zeta = c__[i__] * zeta - s[i__] * z__[i__ + j * z_dim1];
131  z__[i__ + j * z_dim1] = t;
132 /* L40: */
133  }
134  azeta = fabs(zeta);
135  if (azeta == 0. || rho[j] < 0.) {
136  goto L50;
137  }
138  scale = azeta + rho[j];
139 /* Computing 2nd power */
140  d__1 = azeta / scale;
141 /* Computing 2nd power */
142  d__2 = rho[j] / scale;
143  rho[j] = scale * sqrt(d__1 * d__1 + d__2 * d__2);
144 L50:
145 /* L60: */
146  ;
147  }
148 L70:
149 
150  return;
151 
152 } /* dchud_ */
153 
154 
155 #endif // !defined(HAVE_MOOCHO_FORTRAN)