Skip Navigation Links
Numerical Libraries
Linear Algebra
Differential Equations
Optimization
Samples
Skip Navigation Links
Linear Algebra
CSLapack
CSBlas
   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 routine (version 3.1) --
  21:      /// Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  22:      /// November 2006
  23:      /// Purpose
  24:      /// =======
  25:      /// 
  26:      /// DGEBAK forms the right or left eigenvectors of a real general matrix
  27:      /// by backward transformation on the computed eigenvectors of the
  28:      /// balanced matrix output by DGEBAL.
  29:      /// 
  30:      ///</summary>
  31:      public class DGEBAK
  32:      {
  33:      
  34:   
  35:          #region Dependencies
  36:          
  37:          LSAME _lsame; DSCAL _dscal; DSWAP _dswap; XERBLA _xerbla; 
  38:   
  39:          #endregion
  40:   
  41:   
  42:          #region Fields
  43:          
  44:          const double ONE = 1.0E+0; bool LEFTV = false; bool RIGHTV = false; int I = 0; int II = 0; int K = 0; double S = 0; 
  45:   
  46:          #endregion
  47:   
  48:          public DGEBAK(LSAME lsame, DSCAL dscal, DSWAP dswap, XERBLA xerbla)
  49:          {
  50:      
  51:   
  52:              #region Set Dependencies
  53:              
  54:              this._lsame = lsame; this._dscal = dscal; this._dswap = dswap; this._xerbla = xerbla; 
  55:   
  56:              #endregion
  57:   
  58:          }
  59:      
  60:          public DGEBAK()
  61:          {
  62:      
  63:   
  64:              #region Dependencies (Initialization)
  65:              
  66:              LSAME lsame = new LSAME();
  67:              DSCAL dscal = new DSCAL();
  68:              DSWAP dswap = new DSWAP();
  69:              XERBLA xerbla = new XERBLA();
  70:   
  71:              #endregion
  72:   
  73:   
  74:              #region Set Dependencies
  75:              
  76:              this._lsame = lsame; this._dscal = dscal; this._dswap = dswap; this._xerbla = xerbla; 
  77:   
  78:              #endregion
  79:   
  80:          }
  81:          /// <summary>
  82:          /// Purpose
  83:          /// =======
  84:          /// 
  85:          /// DGEBAK forms the right or left eigenvectors of a real general matrix
  86:          /// by backward transformation on the computed eigenvectors of the
  87:          /// balanced matrix output by DGEBAL.
  88:          /// 
  89:          ///</summary>
  90:          /// <param name="JOB">
  91:          /// (input) CHARACTER*1
  92:          /// Specifies the type of backward transformation required:
  93:          /// = 'N', do nothing, return immediately;
  94:          /// = 'P', do backward transformation for permutation only;
  95:          /// = 'S', do backward transformation for scaling only;
  96:          /// = 'B', do backward transformations for both permutation and
  97:          /// scaling.
  98:          /// JOB must be the same as the argument JOB supplied to DGEBAL.
  99:          ///</param>
 100:          /// <param name="SIDE">
 101:          /// (input) CHARACTER*1
 102:          /// = 'R':  V contains right eigenvectors;
 103:          /// = 'L':  V contains left eigenvectors.
 104:          ///</param>
 105:          /// <param name="N">
 106:          /// (input) INTEGER
 107:          /// The number of rows of the matrix V.  N .GE. 0.
 108:          ///</param>
 109:          /// <param name="ILO">
 110:          /// (input) INTEGER
 111:          ///</param>
 112:          /// <param name="IHI">
 113:          /// (input) INTEGER
 114:          /// The integers ILO and IHI determined by DGEBAL.
 115:          /// 1 .LE. ILO .LE. IHI .LE. N, if N .GT. 0; ILO=1 and IHI=0, if N=0.
 116:          ///</param>
 117:          /// <param name="SCALE">
 118:          /// (input) DOUBLE PRECISION array, dimension (N)
 119:          /// Details of the permutation and scaling factors, as returned
 120:          /// by DGEBAL.
 121:          ///</param>
 122:          /// <param name="M">
 123:          /// (input) INTEGER
 124:          /// The number of columns of the matrix V.  M .GE. 0.
 125:          ///</param>
 126:          /// <param name="V">
 127:          /// (input/output) DOUBLE PRECISION array, dimension (LDV,M)
 128:          /// On entry, the matrix of right or left eigenvectors to be
 129:          /// transformed, as returned by DHSEIN or DTREVC.
 130:          /// On exit, V is overwritten by the transformed eigenvectors.
 131:          ///</param>
 132:          /// <param name="LDV">
 133:          /// (input) INTEGER
 134:          /// The leading dimension of the array V. LDV .GE. max(1,N).
 135:          ///</param>
 136:          /// <param name="INFO">
 137:          /// (output) INTEGER
 138:          /// = 0:  successful exit
 139:          /// .LT. 0:  if INFO = -i, the i-th argument had an illegal value.
 140:          ///</param>
 141:          public void Run(string JOB, string SIDE, int N, int ILO, int IHI, double[] SCALE, int offset_scale
 142:                           , int M, ref double[] V, int offset_v, int LDV, ref int INFO)
 143:          {
 144:   
 145:              #region Array Index Correction
 146:              
 147:               int o_scale = -1 + offset_scale;  int o_v = -1 - LDV + offset_v; 
 148:   
 149:              #endregion
 150:   
 151:   
 152:              #region Strings
 153:              
 154:              JOB = JOB.Substring(0, 1);  SIDE = SIDE.Substring(0, 1);  
 155:   
 156:              #endregion
 157:   
 158:   
 159:              #region Prolog
 160:              
 161:              // *
 162:              // *  -- LAPACK routine (version 3.1) --
 163:              // *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
 164:              // *     November 2006
 165:              // *
 166:              // *     .. Scalar Arguments ..
 167:              // *     ..
 168:              // *     .. Array Arguments ..
 169:              // *     ..
 170:              // *
 171:              // *  Purpose
 172:              // *  =======
 173:              // *
 174:              // *  DGEBAK forms the right or left eigenvectors of a real general matrix
 175:              // *  by backward transformation on the computed eigenvectors of the
 176:              // *  balanced matrix output by DGEBAL.
 177:              // *
 178:              // *  Arguments
 179:              // *  =========
 180:              // *
 181:              // *  JOB     (input) CHARACTER*1
 182:              // *          Specifies the type of backward transformation required:
 183:              // *          = 'N', do nothing, return immediately;
 184:              // *          = 'P', do backward transformation for permutation only;
 185:              // *          = 'S', do backward transformation for scaling only;
 186:              // *          = 'B', do backward transformations for both permutation and
 187:              // *                 scaling.
 188:              // *          JOB must be the same as the argument JOB supplied to DGEBAL.
 189:              // *
 190:              // *  SIDE    (input) CHARACTER*1
 191:              // *          = 'R':  V contains right eigenvectors;
 192:              // *          = 'L':  V contains left eigenvectors.
 193:              // *
 194:              // *  N       (input) INTEGER
 195:              // *          The number of rows of the matrix V.  N >= 0.
 196:              // *
 197:              // *  ILO     (input) INTEGER
 198:              // *  IHI     (input) INTEGER
 199:              // *          The integers ILO and IHI determined by DGEBAL.
 200:              // *          1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
 201:              // *
 202:              // *  SCALE   (input) DOUBLE PRECISION array, dimension (N)
 203:              // *          Details of the permutation and scaling factors, as returned
 204:              // *          by DGEBAL.
 205:              // *
 206:              // *  M       (input) INTEGER
 207:              // *          The number of columns of the matrix V.  M >= 0.
 208:              // *
 209:              // *  V       (input/output) DOUBLE PRECISION array, dimension (LDV,M)
 210:              // *          On entry, the matrix of right or left eigenvectors to be
 211:              // *          transformed, as returned by DHSEIN or DTREVC.
 212:              // *          On exit, V is overwritten by the transformed eigenvectors.
 213:              // *
 214:              // *  LDV     (input) INTEGER
 215:              // *          The leading dimension of the array V. LDV >= max(1,N).
 216:              // *
 217:              // *  INFO    (output) INTEGER
 218:              // *          = 0:  successful exit
 219:              // *          < 0:  if INFO = -i, the i-th argument had an illegal value.
 220:              // *
 221:              // *  =====================================================================
 222:              // *
 223:              // *     .. Parameters ..
 224:              // *     ..
 225:              // *     .. Local Scalars ..
 226:              // *     ..
 227:              // *     .. External Functions ..
 228:              // *     ..
 229:              // *     .. External Subroutines ..
 230:              // *     ..
 231:              // *     .. Intrinsic Functions ..
 232:              //      INTRINSIC          MAX, MIN;
 233:              // *     ..
 234:              // *     .. Executable Statements ..
 235:              // *
 236:              // *     Decode and Test the input parameters
 237:              // *
 238:   
 239:              #endregion
 240:   
 241:   
 242:              #region Body
 243:              
 244:              RIGHTV = this._lsame.Run(SIDE, "R");
 245:              LEFTV = this._lsame.Run(SIDE, "L");
 246:              // *
 247:              INFO = 0;
 248:              if (!this._lsame.Run(JOB, "N") && !this._lsame.Run(JOB, "P") && !this._lsame.Run(JOB, "S") && !this._lsame.Run(JOB, "B"))
 249:              {
 250:                  INFO =  - 1;
 251:              }
 252:              else
 253:              {
 254:                  if (!RIGHTV && !LEFTV)
 255:                  {
 256:                      INFO =  - 2;
 257:                  }
 258:                  else
 259:                  {
 260:                      if (N < 0)
 261:                      {
 262:                          INFO =  - 3;
 263:                      }
 264:                      else
 265:                      {
 266:                          if (ILO < 1 || ILO > Math.Max(1, N))
 267:                          {
 268:                              INFO =  - 4;
 269:                          }
 270:                          else
 271:                          {
 272:                              if (IHI < Math.Min(ILO, N) || IHI > N)
 273:                              {
 274:                                  INFO =  - 5;
 275:                              }
 276:                              else
 277:                              {
 278:                                  if (M < 0)
 279:                                  {
 280:                                      INFO =  - 7;
 281:                                  }
 282:                                  else
 283:                                  {
 284:                                      if (LDV < Math.Max(1, N))
 285:                                      {
 286:                                          INFO =  - 9;
 287:                                      }
 288:                                  }
 289:                              }
 290:                          }
 291:                      }
 292:                  }
 293:              }
 294:              if (INFO != 0)
 295:              {
 296:                  this._xerbla.Run("DGEBAK",  - INFO);
 297:                  return;
 298:              }
 299:              // *
 300:              // *     Quick return if possible
 301:              // *
 302:              if (N == 0) return;
 303:              if (M == 0) return;
 304:              if (this._lsame.Run(JOB, "N")) return;
 305:              // *
 306:              if (ILO == IHI) goto LABEL30;
 307:              // *
 308:              // *     Backward balance
 309:              // *
 310:              if (this._lsame.Run(JOB, "S") || this._lsame.Run(JOB, "B"))
 311:              {
 312:                  // *
 313:                  if (RIGHTV)
 314:                  {
 315:                      for (I = ILO; I <= IHI; I++)
 316:                      {
 317:                          S = SCALE[I + o_scale];
 318:                          this._dscal.Run(M, S, ref V, I+1 * LDV + o_v, LDV);
 319:                      }
 320:                  }
 321:                  // *
 322:                  if (LEFTV)
 323:                  {
 324:                      for (I = ILO; I <= IHI; I++)
 325:                      {
 326:                          S = ONE / SCALE[I + o_scale];
 327:                          this._dscal.Run(M, S, ref V, I+1 * LDV + o_v, LDV);
 328:                      }
 329:                  }
 330:                  // *
 331:              }
 332:              // *
 333:              // *     Backward permutation
 334:              // *
 335:              // *     For  I = ILO-1 step -1 until 1,
 336:              // *              IHI+1 step 1 until N do --
 337:              // *
 338:          LABEL30:;
 339:              if (this._lsame.Run(JOB, "P") || this._lsame.Run(JOB, "B"))
 340:              {
 341:                  if (RIGHTV)
 342:                  {
 343:                      for (II = 1; II <= N; II++)
 344:                      {
 345:                          I = II;
 346:                          if (I >= ILO && I <= IHI) goto LABEL40;
 347:                          if (I < ILO) I = ILO - II;
 348:                          K = (int)SCALE[I + o_scale];
 349:                          if (K == I) goto LABEL40;
 350:                          this._dswap.Run(M, ref V, I+1 * LDV + o_v, LDV, ref V, K+1 * LDV + o_v, LDV);
 351:                      LABEL40:;
 352:                      }
 353:                  }
 354:                  // *
 355:                  if (LEFTV)
 356:                  {
 357:                      for (II = 1; II <= N; II++)
 358:                      {
 359:                          I = II;
 360:                          if (I >= ILO && I <= IHI) goto LABEL50;
 361:                          if (I < ILO) I = ILO - II;
 362:                          K = (int)SCALE[I + o_scale];
 363:                          if (K == I) goto LABEL50;
 364:                          this._dswap.Run(M, ref V, I+1 * LDV + o_v, LDV, ref V, K+1 * LDV + o_v, LDV);
 365:                      LABEL50:;
 366:                      }
 367:                  }
 368:              }
 369:              // *
 370:              return;
 371:              // *
 372:              // *     End of DGEBAK
 373:              // *
 374:   
 375:              #endregion
 376:   
 377:          }
 378:      }
 379:  }