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 auxiliary routine (version 3.1) --
  21:      /// Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  22:      /// November 2006
  23:      /// Purpose
  24:      /// =======
  25:      /// 
  26:      /// DLAPMT rearranges the columns of the M by N matrix X as specified
  27:      /// by the permutation K(1),K(2),...,K(N) of the integers 1,...,N.
  28:      /// If FORWRD = .TRUE.,  forward permutation:
  29:      /// 
  30:      /// X(*,K(J)) is moved X(*,J) for J = 1,2,...,N.
  31:      /// 
  32:      /// If FORWRD = .FALSE., backward permutation:
  33:      /// 
  34:      /// X(*,J) is moved to X(*,K(J)) for J = 1,2,...,N.
  35:      /// 
  36:      ///</summary>
  37:      public class DLAPMT
  38:      {
  39:      
  40:   
  41:          #region Fields
  42:          
  43:          int I = 0; int II = 0; int IN = 0; int J = 0; double TEMP = 0; 
  44:   
  45:          #endregion
  46:   
  47:          public DLAPMT()
  48:          {
  49:      
  50:          }
  51:      
  52:          /// <summary>
  53:          /// Purpose
  54:          /// =======
  55:          /// 
  56:          /// DLAPMT rearranges the columns of the M by N matrix X as specified
  57:          /// by the permutation K(1),K(2),...,K(N) of the integers 1,...,N.
  58:          /// If FORWRD = .TRUE.,  forward permutation:
  59:          /// 
  60:          /// X(*,K(J)) is moved X(*,J) for J = 1,2,...,N.
  61:          /// 
  62:          /// If FORWRD = .FALSE., backward permutation:
  63:          /// 
  64:          /// X(*,J) is moved to X(*,K(J)) for J = 1,2,...,N.
  65:          /// 
  66:          ///</summary>
  67:          /// <param name="FORWRD">
  68:          /// (input) LOGICAL
  69:          /// = .TRUE., forward permutation
  70:          /// = .FALSE., backward permutation
  71:          ///</param>
  72:          /// <param name="M">
  73:          /// (input) INTEGER
  74:          /// The number of rows of the matrix X. M .GE. 0.
  75:          ///</param>
  76:          /// <param name="N">
  77:          /// (input) INTEGER
  78:          /// The number of columns of the matrix X. N .GE. 0.
  79:          ///</param>
  80:          /// <param name="X">
  81:          /// (input/output) DOUBLE PRECISION array, dimension (LDX,N)
  82:          /// On entry, the M by N matrix X.
  83:          /// On exit, X contains the permuted matrix X.
  84:          ///</param>
  85:          /// <param name="LDX">
  86:          /// (input) INTEGER
  87:          /// The leading dimension of the array X, LDX .GE. MAX(1,M).
  88:          ///</param>
  89:          /// <param name="K">
  90:          /// (input/output) INTEGER array, dimension (N)
  91:          /// On entry, K contains the permutation vector. K is used as
  92:          /// internal workspace, but reset to its original value on
  93:          /// output.
  94:          ///</param>
  95:          public void Run(bool FORWRD, int M, int N, ref double[] X, int offset_x, int LDX, ref int[] K, int offset_k)
  96:          {
  97:   
  98:              #region Array Index Correction
  99:              
 100:               int o_x = -1 - LDX + offset_x;  int o_k = -1 + offset_k; 
 101:   
 102:              #endregion
 103:   
 104:   
 105:              #region Prolog
 106:              
 107:              // *
 108:              // *  -- LAPACK auxiliary routine (version 3.1) --
 109:              // *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
 110:              // *     November 2006
 111:              // *
 112:              // *     .. Scalar Arguments ..
 113:              // *     ..
 114:              // *     .. Array Arguments ..
 115:              // *     ..
 116:              // *
 117:              // *  Purpose
 118:              // *  =======
 119:              // *
 120:              // *  DLAPMT rearranges the columns of the M by N matrix X as specified
 121:              // *  by the permutation K(1),K(2),...,K(N) of the integers 1,...,N.
 122:              // *  If FORWRD = .TRUE.,  forward permutation:
 123:              // *
 124:              // *       X(*,K(J)) is moved X(*,J) for J = 1,2,...,N.
 125:              // *
 126:              // *  If FORWRD = .FALSE., backward permutation:
 127:              // *
 128:              // *       X(*,J) is moved to X(*,K(J)) for J = 1,2,...,N.
 129:              // *
 130:              // *  Arguments
 131:              // *  =========
 132:              // *
 133:              // *  FORWRD  (input) LOGICAL
 134:              // *          = .TRUE., forward permutation
 135:              // *          = .FALSE., backward permutation
 136:              // *
 137:              // *  M       (input) INTEGER
 138:              // *          The number of rows of the matrix X. M >= 0.
 139:              // *
 140:              // *  N       (input) INTEGER
 141:              // *          The number of columns of the matrix X. N >= 0.
 142:              // *
 143:              // *  X       (input/output) DOUBLE PRECISION array, dimension (LDX,N)
 144:              // *          On entry, the M by N matrix X.
 145:              // *          On exit, X contains the permuted matrix X.
 146:              // *
 147:              // *  LDX     (input) INTEGER
 148:              // *          The leading dimension of the array X, LDX >= MAX(1,M).
 149:              // *
 150:              // *  K       (input/output) INTEGER array, dimension (N)
 151:              // *          On entry, K contains the permutation vector. K is used as
 152:              // *          internal workspace, but reset to its original value on
 153:              // *          output.
 154:              // *
 155:              // *  =====================================================================
 156:              // *
 157:              // *     .. Local Scalars ..
 158:              // *     ..
 159:              // *     .. Executable Statements ..
 160:              // *
 161:   
 162:              #endregion
 163:   
 164:   
 165:              #region Body
 166:              
 167:              if (N <= 1) return;
 168:              // *
 169:              for (I = 1; I <= N; I++)
 170:              {
 171:                  K[I + o_k] =  - K[I + o_k];
 172:              }
 173:              // *
 174:              if (FORWRD)
 175:              {
 176:                  // *
 177:                  // *        Forward permutation
 178:                  // *
 179:                  for (I = 1; I <= N; I++)
 180:                  {
 181:                      // *
 182:                      if (K[I + o_k] > 0) goto LABEL40;
 183:                      // *
 184:                      J = I;
 185:                      K[J + o_k] =  - K[J + o_k];
 186:                      IN = K[J + o_k];
 187:                      // *
 188:                  LABEL20:;
 189:                      if (K[IN + o_k] > 0) goto LABEL40;
 190:                      // *
 191:                      for (II = 1; II <= M; II++)
 192:                      {
 193:                          TEMP = X[II+J * LDX + o_x];
 194:                          X[II+J * LDX + o_x] = X[II+IN * LDX + o_x];
 195:                          X[II+IN * LDX + o_x] = TEMP;
 196:                      }
 197:                      // *
 198:                      K[IN + o_k] =  - K[IN + o_k];
 199:                      J = IN;
 200:                      IN = K[IN + o_k];
 201:                      goto LABEL20;
 202:                      // *
 203:                  LABEL40:;
 204:                      // *
 205:                  }
 206:                  // *
 207:              }
 208:              else
 209:              {
 210:                  // *
 211:                  // *        Backward permutation
 212:                  // *
 213:                  for (I = 1; I <= N; I++)
 214:                  {
 215:                      // *
 216:                      if (K[I + o_k] > 0) goto LABEL80;
 217:                      // *
 218:                      K[I + o_k] =  - K[I + o_k];
 219:                      J = K[I + o_k];
 220:                  LABEL60:;
 221:                      if (J == I) goto LABEL80;
 222:                      // *
 223:                      for (II = 1; II <= M; II++)
 224:                      {
 225:                          TEMP = X[II+I * LDX + o_x];
 226:                          X[II+I * LDX + o_x] = X[II+J * LDX + o_x];
 227:                          X[II+J * LDX + o_x] = TEMP;
 228:                      }
 229:                      // *
 230:                      K[J + o_k] =  - K[J + o_k];
 231:                      J = K[J + o_k];
 232:                      goto LABEL60;
 233:                      // *
 234:                  LABEL80:;
 235:                      // *
 236:                  }
 237:                  // *
 238:              }
 239:              // *
 240:              return;
 241:              // *
 242:              // *     End of DLAPMT
 243:              // *
 244:   
 245:              #endregion
 246:   
 247:          }
 248:      }
 249:  }