1:  #region Translated by Jose Antonio De Santiago-Castillo.
2:
3:  //Translated by Jose Antonio De Santiago-Castillo.
4:  //E-mail:JAntonioDeSantiago@gmail.com
5:  //Web: www.DotNumerics.com
6:  //
7:  //Fortran to C# Translation.
8:  //Translated by:
9:  //F2CSharp Version 0.71 (November 10, 2009)
10:  //Code Optimizations: None
11:  //
12:  #endregion
13:
14:  using System;
15:  using DotNumerics.FortranLibrary;
16:
17:  namespace DotNumerics.CSLapack
18:  {
19:      /// <summary>
20:      /// -- LAPACK auxiliary routine (version 3.1) --
21:      /// Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
22:      /// November 2006
23:      /// Purpose
24:      /// =======
25:      ///
26:      /// DLARGV generates a vector of real plane rotations, determined by
27:      /// elements of the real vectors x and y. For i = 1,2,...,n
28:      ///
29:      /// (  c(i)  s(i) ) ( x(i) ) = ( a(i) )
30:      /// ( -s(i)  c(i) ) ( y(i) ) = (   0  )
31:      ///
32:      ///</summary>
33:      public class DLARGV
34:      {
35:
36:
37:          #region Fields
38:
39:          const double ZERO = 0.0E+0; const double ONE = 1.0E+0; int I = 0; int IC = 0; int IX = 0; int IY = 0; double F = 0;
40:          double G = 0;double T = 0; double TT = 0;
41:
42:          #endregion
43:
44:          public DLARGV()
45:          {
46:
47:          }
48:
49:          /// <summary>
50:          /// Purpose
51:          /// =======
52:          ///
53:          /// DLARGV generates a vector of real plane rotations, determined by
54:          /// elements of the real vectors x and y. For i = 1,2,...,n
55:          ///
56:          /// (  c(i)  s(i) ) ( x(i) ) = ( a(i) )
57:          /// ( -s(i)  c(i) ) ( y(i) ) = (   0  )
58:          ///
59:          ///</summary>
60:          /// <param name="N">
61:          /// (input) INTEGER
62:          /// The number of plane rotations to be generated.
63:          ///</param>
64:          /// <param name="X">
65:          /// (input/output) DOUBLE PRECISION array,
66:          /// dimension (1+(N-1)*INCX)
67:          /// On entry, the vector x.
68:          /// On exit, x(i) is overwritten by a(i), for i = 1,...,n.
69:          ///</param>
70:          /// <param name="INCX">
71:          /// (input) INTEGER
72:          /// The increment between elements of X. INCX .GT. 0.
73:          ///</param>
74:          /// <param name="Y">
75:          /// (input/output) DOUBLE PRECISION array,
76:          /// dimension (1+(N-1)*INCY)
77:          /// On entry, the vector y.
78:          /// On exit, the sines of the plane rotations.
79:          ///</param>
80:          /// <param name="INCY">
81:          /// (input) INTEGER
82:          /// The increment between elements of Y. INCY .GT. 0.
83:          ///</param>
84:          /// <param name="C">
85:          /// (output) DOUBLE PRECISION array, dimension (1+(N-1)*INCC)
86:          /// The cosines of the plane rotations.
87:          ///</param>
88:          /// <param name="INCC">
89:          /// (input) INTEGER
90:          /// The increment between elements of C. INCC .GT. 0.
91:          ///</param>
92:          public void Run(int N, ref double[] X, int offset_x, int INCX, ref double[] Y, int offset_y, int INCY, ref double[] C, int offset_c
93:                           , int INCC)
94:          {
95:
96:              #region Array Index Correction
97:
98:               int o_x = -1 + offset_x;  int o_y = -1 + offset_y;  int o_c = -1 + offset_c;
99:
100:              #endregion
101:
102:
103:              #region Prolog
104:
105:              // *
106:              // *  -- LAPACK auxiliary routine (version 3.1) --
107:              // *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
108:              // *     November 2006
109:              // *
110:              // *     .. Scalar Arguments ..
111:              // *     ..
112:              // *     .. Array Arguments ..
113:              // *     ..
114:              // *
115:              // *  Purpose
116:              // *  =======
117:              // *
118:              // *  DLARGV generates a vector of real plane rotations, determined by
119:              // *  elements of the real vectors x and y. For i = 1,2,...,n
120:              // *
121:              // *     (  c(i)  s(i) ) ( x(i) ) = ( a(i) )
122:              // *     ( -s(i)  c(i) ) ( y(i) ) = (   0  )
123:              // *
124:              // *  Arguments
125:              // *  =========
126:              // *
127:              // *  N       (input) INTEGER
128:              // *          The number of plane rotations to be generated.
129:              // *
130:              // *  X       (input/output) DOUBLE PRECISION array,
131:              // *                         dimension (1+(N-1)*INCX)
132:              // *          On entry, the vector x.
133:              // *          On exit, x(i) is overwritten by a(i), for i = 1,...,n.
134:              // *
135:              // *  INCX    (input) INTEGER
136:              // *          The increment between elements of X. INCX > 0.
137:              // *
138:              // *  Y       (input/output) DOUBLE PRECISION array,
139:              // *                         dimension (1+(N-1)*INCY)
140:              // *          On entry, the vector y.
141:              // *          On exit, the sines of the plane rotations.
142:              // *
143:              // *  INCY    (input) INTEGER
144:              // *          The increment between elements of Y. INCY > 0.
145:              // *
146:              // *  C       (output) DOUBLE PRECISION array, dimension (1+(N-1)*INCC)
147:              // *          The cosines of the plane rotations.
148:              // *
149:              // *  INCC    (input) INTEGER
150:              // *          The increment between elements of C. INCC > 0.
151:              // *
152:              // *  =====================================================================
153:              // *
154:              // *     .. Parameters ..
155:              // *     ..
156:              // *     .. Local Scalars ..
157:              // *     ..
158:              // *     .. Intrinsic Functions ..
159:              //      INTRINSIC          ABS, SQRT;
160:              // *     ..
161:              // *     .. Executable Statements ..
162:              // *
163:
164:              #endregion
165:
166:
167:              #region Body
168:
169:              IX = 1;
170:              IY = 1;
171:              IC = 1;
172:              for (I = 1; I <= N; I++)
173:              {
174:                  F = X[IX + o_x];
175:                  G = Y[IY + o_y];
176:                  if (G == ZERO)
177:                  {
178:                      C[IC + o_c] = ONE;
179:                  }
180:                  else
181:                  {
182:                      if (F == ZERO)
183:                      {
184:                          C[IC + o_c] = ZERO;
185:                          Y[IY + o_y] = ONE;
186:                          X[IX + o_x] = G;
187:                      }
188:                      else
189:                      {
190:                          if (Math.Abs(F) > Math.Abs(G))
191:                          {
192:                              T = G / F;
193:                              TT = Math.Sqrt(ONE + T * T);
194:                              C[IC + o_c] = ONE / TT;
195:                              Y[IY + o_y] = T * C[IC + o_c];
196:                              X[IX + o_x] = F * TT;
197:                          }
198:                          else
199:                          {
200:                              T = F / G;
201:                              TT = Math.Sqrt(ONE + T * T);
202:                              Y[IY + o_y] = ONE / TT;
203:                              C[IC + o_c] = T * Y[IY + o_y];
204:                              X[IX + o_x] = G * TT;
205:                          }
206:                      }
207:                  }
208:                  IC = IC + INCC;
209:                  IY = IY + INCY;
210:                  IX = IX + INCX;
211:              }
212:              return;
213:              // *
214:              // *     End of DLARGV
215:              // *
216:
217:              #endregion
218:
219:          }
220:      }
221:  }