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:      /// DLAMRG will create a permutation list which will merge the elements
  27:      /// of A (which is composed of two independently sorted sets) into a
  28:      /// single set which is sorted in ascending order.
  29:      /// 
  30:      ///</summary>
  31:      public class DLAMRG
  32:      {
  33:      
  34:   
  35:          #region Fields
  36:          
  37:          int I = 0; int IND1 = 0; int IND2 = 0; int N1SV = 0; int N2SV = 0; 
  38:   
  39:          #endregion
  40:   
  41:          public DLAMRG()
  42:          {
  43:      
  44:          }
  45:      
  46:          /// <summary>
  47:          /// Purpose
  48:          /// =======
  49:          /// 
  50:          /// DLAMRG will create a permutation list which will merge the elements
  51:          /// of A (which is composed of two independently sorted sets) into a
  52:          /// single set which is sorted in ascending order.
  53:          /// 
  54:          ///</summary>
  55:          /// <param name="N1">
  56:          /// (input) INTEGER
  57:          ///</param>
  58:          /// <param name="N2">
  59:          /// (input) INTEGER
  60:          /// These arguements contain the respective lengths of the two
  61:          /// sorted lists to be merged.
  62:          ///</param>
  63:          /// <param name="A">
  64:          /// (input) DOUBLE PRECISION array, dimension (N1+N2)
  65:          /// The first N1 elements of A contain a list of numbers which
  66:          /// are sorted in either ascending or descending order.  Likewise
  67:          /// for the final N2 elements.
  68:          ///</param>
  69:          /// <param name="DTRD1">
  70:          /// (input) INTEGER
  71:          ///</param>
  72:          /// <param name="DTRD2">
  73:          /// (input) INTEGER
  74:          /// These are the strides to be taken through the array A.
  75:          /// Allowable strides are 1 and -1.  They indicate whether a
  76:          /// subset of A is sorted in ascending (DTRDx = 1) or descending
  77:          /// (DTRDx = -1) order.
  78:          ///</param>
  79:          /// <param name="INDEX">
  80:          /// (output) INTEGER array, dimension (N1+N2)
  81:          /// On exit this array will contain a permutation such that
  82:          /// if B( I ) = A( INDEX( I ) ) for I=1,N1+N2, then B will be
  83:          /// sorted in ascending order.
  84:          ///</param>
  85:          public void Run(int N1, int N2, double[] A, int offset_a, int DTRD1, int DTRD2, ref int[] INDEX, int offset_index)
  86:          {
  87:   
  88:              #region Array Index Correction
  89:              
  90:               int o_a = -1 + offset_a;  int o_index = -1 + offset_index; 
  91:   
  92:              #endregion
  93:   
  94:   
  95:              #region Prolog
  96:              
  97:              // *
  98:              // *  -- LAPACK routine (version 3.1) --
  99:              // *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
 100:              // *     November 2006
 101:              // *
 102:              // *     .. Scalar Arguments ..
 103:              // *     ..
 104:              // *     .. Array Arguments ..
 105:              // *     ..
 106:              // *
 107:              // *  Purpose
 108:              // *  =======
 109:              // *
 110:              // *  DLAMRG will create a permutation list which will merge the elements
 111:              // *  of A (which is composed of two independently sorted sets) into a
 112:              // *  single set which is sorted in ascending order.
 113:              // *
 114:              // *  Arguments
 115:              // *  =========
 116:              // *
 117:              // *  N1     (input) INTEGER
 118:              // *  N2     (input) INTEGER
 119:              // *         These arguements contain the respective lengths of the two
 120:              // *         sorted lists to be merged.
 121:              // *
 122:              // *  A      (input) DOUBLE PRECISION array, dimension (N1+N2)
 123:              // *         The first N1 elements of A contain a list of numbers which
 124:              // *         are sorted in either ascending or descending order.  Likewise
 125:              // *         for the final N2 elements.
 126:              // *
 127:              // *  DTRD1  (input) INTEGER
 128:              // *  DTRD2  (input) INTEGER
 129:              // *         These are the strides to be taken through the array A.
 130:              // *         Allowable strides are 1 and -1.  They indicate whether a
 131:              // *         subset of A is sorted in ascending (DTRDx = 1) or descending
 132:              // *         (DTRDx = -1) order.
 133:              // *
 134:              // *  INDEX  (output) INTEGER array, dimension (N1+N2)
 135:              // *         On exit this array will contain a permutation such that
 136:              // *         if B( I ) = A( INDEX( I ) ) for I=1,N1+N2, then B will be
 137:              // *         sorted in ascending order.
 138:              // *
 139:              // *  =====================================================================
 140:              // *
 141:              // *     .. Local Scalars ..
 142:              // *     ..
 143:              // *     .. Executable Statements ..
 144:              // *
 145:   
 146:              #endregion
 147:   
 148:   
 149:              #region Body
 150:              
 151:              N1SV = N1;
 152:              N2SV = N2;
 153:              if (DTRD1 > 0)
 154:              {
 155:                  IND1 = 1;
 156:              }
 157:              else
 158:              {
 159:                  IND1 = N1;
 160:              }
 161:              if (DTRD2 > 0)
 162:              {
 163:                  IND2 = 1 + N1;
 164:              }
 165:              else
 166:              {
 167:                  IND2 = N1 + N2;
 168:              }
 169:              I = 1;
 170:              // *     while ( (N1SV > 0) & (N2SV > 0) )
 171:          LABEL10:;
 172:              if (N1SV > 0 && N2SV > 0)
 173:              {
 174:                  if (A[IND1 + o_a] <= A[IND2 + o_a])
 175:                  {
 176:                      INDEX[I + o_index] = IND1;
 177:                      I = I + 1;
 178:                      IND1 = IND1 + DTRD1;
 179:                      N1SV = N1SV - 1;
 180:                  }
 181:                  else
 182:                  {
 183:                      INDEX[I + o_index] = IND2;
 184:                      I = I + 1;
 185:                      IND2 = IND2 + DTRD2;
 186:                      N2SV = N2SV - 1;
 187:                  }
 188:                  goto LABEL10;
 189:              }
 190:              // *     end while
 191:              if (N1SV == 0)
 192:              {
 193:                  for (N1SV = 1; N1SV <= N2SV; N1SV++)
 194:                  {
 195:                      INDEX[I + o_index] = IND2;
 196:                      I = I + 1;
 197:                      IND2 = IND2 + DTRD2;
 198:                  }
 199:              }
 200:              else
 201:              {
 202:                  // *     N2SV .EQ. 0
 203:                  for (N2SV = 1; N2SV <= N1SV; N2SV++)
 204:                  {
 205:                      INDEX[I + o_index] = IND1;
 206:                      I = I + 1;
 207:                      IND1 = IND1 + DTRD1;
 208:                  }
 209:              }
 210:              // *
 211:              return;
 212:              // *
 213:              // *     End of DLAMRG
 214:              // *
 215:   
 216:              #endregion
 217:   
 218:          }
 219:      }
 220:  }