  `   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:      /// DLANSY  returns the value of the one norm,  or the Frobenius norm, or`
`  27:      /// the  infinity norm,  or the  element of  largest absolute value  of a`
`  28:      /// real symmetric matrix A.`
`  29:      /// `
`  30:      /// Description`
`  31:      /// ===========`
`  32:      /// `
`  33:      /// DLANSY returns the value`
`  34:      /// `
`  35:      /// DLANSY = ( max(abs(A(i,j))), NORM = 'M' or 'm'`
`  36:      /// (`
`  37:      /// ( norm1(A),         NORM = '1', 'O' or 'o'`
`  38:      /// (`
`  39:      /// ( normI(A),         NORM = 'I' or 'i'`
`  40:      /// (`
`  41:      /// ( normF(A),         NORM = 'F', 'f', 'E' or 'e'`
`  42:      /// `
`  43:      /// where  norm1  denotes the  one norm of a matrix (maximum column sum),`
`  44:      /// normI  denotes the  infinity norm  of a matrix  (maximum row sum) and`
`  45:      /// normF  denotes the  Frobenius norm of a matrix (square root of sum of`
`  46:      /// squares).  Note that  max(abs(A(i,j)))  is not a consistent matrix norm.`
`  47:      /// `
`  48:      ///</summary>`
`  49:      public class DLANSY`
`  50:      {`
`  51:      `
`  52:   `
`  53:          #region Dependencies`
`  54:          `
`  55:          DLASSQ _dlassq; LSAME _lsame; `
`  56:   `
`  57:          #endregion`
`  58:   `
`  59:   `
`  60:          #region Fields`
`  61:          `
`  62:          const double ONE = 1.0E+0; const double ZERO = 0.0E+0; int I = 0; int J = 0; double ABSA = 0; double SCALE = 0; `
`  63:          double SUM = 0;double VALUE = 0; `
`  64:   `
`  65:          #endregion`
`  66:   `
`  67:          public DLANSY(DLASSQ dlassq, LSAME lsame)`
`  68:          {`
`  69:      `
`  70:   `
`  71:              #region Set Dependencies`
`  72:              `
`  73:              this._dlassq = dlassq; this._lsame = lsame; `
`  74:   `
`  75:              #endregion`
`  76:   `
`  77:          }`
`  78:      `
`  79:          public DLANSY()`
`  80:          {`
`  81:      `
`  82:   `
`  83:              #region Dependencies (Initialization)`
`  84:              `
`  85:              DLASSQ dlassq = new DLASSQ();`
`  86:              LSAME lsame = new LSAME();`
`  87:   `
`  88:              #endregion`
`  89:   `
`  90:   `
`  91:              #region Set Dependencies`
`  92:              `
`  93:              this._dlassq = dlassq; this._lsame = lsame; `
`  94:   `
`  95:              #endregion`
`  96:   `
`  97:          }`
`  98:          /// <summary>`
`  99:          /// Purpose`
` 100:          /// =======`
` 101:          /// `
` 102:          /// DLANSY  returns the value of the one norm,  or the Frobenius norm, or`
` 103:          /// the  infinity norm,  or the  element of  largest absolute value  of a`
` 104:          /// real symmetric matrix A.`
` 105:          /// `
` 106:          /// Description`
` 107:          /// ===========`
` 108:          /// `
` 109:          /// DLANSY returns the value`
` 110:          /// `
` 111:          /// DLANSY = ( max(abs(A(i,j))), NORM = 'M' or 'm'`
` 112:          /// (`
` 113:          /// ( norm1(A),         NORM = '1', 'O' or 'o'`
` 114:          /// (`
` 115:          /// ( normI(A),         NORM = 'I' or 'i'`
` 116:          /// (`
` 117:          /// ( normF(A),         NORM = 'F', 'f', 'E' or 'e'`
` 118:          /// `
` 119:          /// where  norm1  denotes the  one norm of a matrix (maximum column sum),`
` 120:          /// normI  denotes the  infinity norm  of a matrix  (maximum row sum) and`
` 121:          /// normF  denotes the  Frobenius norm of a matrix (square root of sum of`
` 122:          /// squares).  Note that  max(abs(A(i,j)))  is not a consistent matrix norm.`
` 123:          /// `
` 124:          ///</summary>`
` 125:          /// <param name="NORM">`
` 126:          /// (input) CHARACTER*1`
` 127:          /// Specifies the value to be returned in DLANSY as described`
` 128:          /// above.`
` 129:          ///</param>`
` 130:          /// <param name="UPLO">`
` 131:          /// (input) CHARACTER*1`
` 132:          /// Specifies whether the upper or lower triangular part of the`
` 133:          /// symmetric matrix A is to be referenced.`
` 134:          /// = 'U':  Upper triangular part of A is referenced`
` 135:          /// = 'L':  Lower triangular part of A is referenced`
` 136:          ///</param>`
` 137:          /// <param name="N">`
` 138:          /// (input) INTEGER`
` 139:          /// The order of the matrix A.  N .GE. 0.  When N = 0, DLANSY is`
` 140:          /// set to zero.`
` 141:          ///</param>`
` 142:          /// <param name="A">`
` 143:          /// (input) DOUBLE PRECISION array, dimension (LDA,N)`
` 144:          /// The symmetric matrix A.  If UPLO = 'U', the leading n by n`
` 145:          /// upper triangular part of A contains the upper triangular part`
` 146:          /// of the matrix A, and the strictly lower triangular part of A`
` 147:          /// is not referenced.  If UPLO = 'L', the leading n by n lower`
` 148:          /// triangular part of A contains the lower triangular part of`
` 149:          /// the matrix A, and the strictly upper triangular part of A is`
` 150:          /// not referenced.`
` 151:          ///</param>`
` 152:          /// <param name="LDA">`
` 153:          /// (input) INTEGER`
` 154:          /// The leading dimension of the array A.  LDA .GE. max(N,1).`
` 155:          ///</param>`
` 156:          /// <param name="WORK">`
` 157:          /// (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)),`
` 158:          /// where LWORK .GE. N when NORM = 'I' or '1' or 'O'; otherwise,`
` 159:          /// WORK is not referenced.`
` 160:          ///</param>`
` 161:          public double Run(string NORM, string UPLO, int N, double[] A, int offset_a, int LDA, ref double[] WORK, int offset_work)`
` 162:          {`
` 163:          double dlansy = 0;`
` 164:   `
` 165:              #region Array Index Correction`
` 166:              `
` 167:               int o_a = -1 - LDA + offset_a;  int o_work = -1 + offset_work; `
` 168:   `
` 169:              #endregion`
` 170:   `
` 171:   `
` 172:              #region Strings`
` 173:              `
` 174:              NORM = NORM.Substring(0, 1);  UPLO = UPLO.Substring(0, 1);  `
` 175:   `
` 176:              #endregion`
` 177:   `
` 178:   `
` 179:              #region Prolog`
` 180:              `
` 181:              // *`
` 182:              // *  -- LAPACK auxiliary routine (version 3.1) --`
` 183:              // *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..`
` 184:              // *     November 2006`
` 185:              // *`
` 186:              // *     .. Scalar Arguments ..`
` 187:              // *     ..`
` 188:              // *     .. Array Arguments ..`
` 189:              // *     ..`
` 190:              // *`
` 191:              // *  Purpose`
` 192:              // *  =======`
` 193:              // *`
` 194:              // *  DLANSY  returns the value of the one norm,  or the Frobenius norm, or`
` 195:              // *  the  infinity norm,  or the  element of  largest absolute value  of a`
` 196:              // *  real symmetric matrix A.`
` 197:              // *`
` 198:              // *  Description`
` 199:              // *  ===========`
` 200:              // *`
` 201:              // *  DLANSY returns the value`
` 202:              // *`
` 203:              // *     DLANSY = ( max(abs(A(i,j))), NORM = 'M' or 'm'`
` 204:              // *              (`
` 205:              // *              ( norm1(A),         NORM = '1', 'O' or 'o'`
` 206:              // *              (`
` 207:              // *              ( normI(A),         NORM = 'I' or 'i'`
` 208:              // *              (`
` 209:              // *              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'`
` 210:              // *`
` 211:              // *  where  norm1  denotes the  one norm of a matrix (maximum column sum),`
` 212:              // *  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and`
` 213:              // *  normF  denotes the  Frobenius norm of a matrix (square root of sum of`
` 214:              // *  squares).  Note that  max(abs(A(i,j)))  is not a consistent matrix norm.`
` 215:              // *`
` 216:              // *  Arguments`
` 217:              // *  =========`
` 218:              // *`
` 219:              // *  NORM    (input) CHARACTER*1`
` 220:              // *          Specifies the value to be returned in DLANSY as described`
` 221:              // *          above.`
` 222:              // *`
` 223:              // *  UPLO    (input) CHARACTER*1`
` 224:              // *          Specifies whether the upper or lower triangular part of the`
` 225:              // *          symmetric matrix A is to be referenced.`
` 226:              // *          = 'U':  Upper triangular part of A is referenced`
` 227:              // *          = 'L':  Lower triangular part of A is referenced`
` 228:              // *`
` 229:              // *  N       (input) INTEGER`
` 230:              // *          The order of the matrix A.  N >= 0.  When N = 0, DLANSY is`
` 231:              // *          set to zero.`
` 232:              // *`
` 233:              // *  A       (input) DOUBLE PRECISION array, dimension (LDA,N)`
` 234:              // *          The symmetric matrix A.  If UPLO = 'U', the leading n by n`
` 235:              // *          upper triangular part of A contains the upper triangular part`
` 236:              // *          of the matrix A, and the strictly lower triangular part of A`
` 237:              // *          is not referenced.  If UPLO = 'L', the leading n by n lower`
` 238:              // *          triangular part of A contains the lower triangular part of`
` 239:              // *          the matrix A, and the strictly upper triangular part of A is`
` 240:              // *          not referenced.`
` 241:              // *`
` 242:              // *  LDA     (input) INTEGER`
` 243:              // *          The leading dimension of the array A.  LDA >= max(N,1).`
` 244:              // *`
` 245:              // *  WORK    (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)),`
` 246:              // *          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,`
` 247:              // *          WORK is not referenced.`
` 248:              // *`
` 249:              // * =====================================================================`
` 250:              // *`
` 251:              // *     .. Parameters ..`
` 252:              // *     ..`
` 253:              // *     .. Local Scalars ..`
` 254:              // *     ..`
` 255:              // *     .. External Subroutines ..`
` 256:              // *     ..`
` 257:              // *     .. External Functions ..`
` 258:              // *     ..`
` 259:              // *     .. Intrinsic Functions ..`
` 260:              //      INTRINSIC          ABS, MAX, SQRT;`
` 261:              // *     ..`
` 262:              // *     .. Executable Statements ..`
` 263:              // *`
` 264:   `
` 265:              #endregion`
` 266:   `
` 267:   `
` 268:              #region Body`
` 269:              `
` 270:              if (N == 0)`
` 271:              {`
` 272:                  VALUE = ZERO;`
` 273:              }`
` 274:              else`
` 275:              {`
` 276:                  if (this._lsame.Run(NORM, "M"))`
` 277:                  {`
` 278:                      // *`
` 279:                      // *        Find max(abs(A(i,j))).`
` 280:                      // *`
` 281:                      VALUE = ZERO;`
` 282:                      if (this._lsame.Run(UPLO, "U"))`
` 283:                      {`
` 284:                          for (J = 1; J <= N; J++)`
` 285:                          {`
` 286:                              for (I = 1; I <= J; I++)`
` 287:                              {`
` 288:                                  VALUE = Math.Max(VALUE, Math.Abs(A[I+J * LDA + o_a]));`
` 289:                              }`
` 290:                          }`
` 291:                      }`
` 292:                      else`
` 293:                      {`
` 294:                          for (J = 1; J <= N; J++)`
` 295:                          {`
` 296:                              for (I = J; I <= N; I++)`
` 297:                              {`
` 298:                                  VALUE = Math.Max(VALUE, Math.Abs(A[I+J * LDA + o_a]));`
` 299:                              }`
` 300:                          }`
` 301:                      }`
` 302:                  }`
` 303:                  else`
` 304:                  {`
` 305:                      if ((this._lsame.Run(NORM, "I")) || (this._lsame.Run(NORM, "O")) || (NORM == "1"))`
` 306:                      {`
` 307:                          // *`
` 308:                          // *        Find normI(A) ( = norm1(A), since A is symmetric).`
` 309:                          // *`
` 310:                          VALUE = ZERO;`
` 311:                          if (this._lsame.Run(UPLO, "U"))`
` 312:                          {`
` 313:                              for (J = 1; J <= N; J++)`
` 314:                              {`
` 315:                                  SUM = ZERO;`
` 316:                                  for (I = 1; I <= J - 1; I++)`
` 317:                                  {`
` 318:                                      ABSA = Math.Abs(A[I+J * LDA + o_a]);`
` 319:                                      SUM = SUM + ABSA;`
` 320:                                      WORK[I + o_work] = WORK[I + o_work] + ABSA;`
` 321:                                  }`
` 322:                                  WORK[J + o_work] = SUM + Math.Abs(A[J+J * LDA + o_a]);`
` 323:                              }`
` 324:                              for (I = 1; I <= N; I++)`
` 325:                              {`
` 326:                                  VALUE = Math.Max(VALUE, WORK[I + o_work]);`
` 327:                              }`
` 328:                          }`
` 329:                          else`
` 330:                          {`
` 331:                              for (I = 1; I <= N; I++)`
` 332:                              {`
` 333:                                  WORK[I + o_work] = ZERO;`
` 334:                              }`
` 335:                              for (J = 1; J <= N; J++)`
` 336:                              {`
` 337:                                  SUM = WORK[J + o_work] + Math.Abs(A[J+J * LDA + o_a]);`
` 338:                                  for (I = J + 1; I <= N; I++)`
` 339:                                  {`
` 340:                                      ABSA = Math.Abs(A[I+J * LDA + o_a]);`
` 341:                                      SUM = SUM + ABSA;`
` 342:                                      WORK[I + o_work] = WORK[I + o_work] + ABSA;`
` 343:                                  }`
` 344:                                  VALUE = Math.Max(VALUE, SUM);`
` 345:                              }`
` 346:                          }`
` 347:                      }`
` 348:                      else`
` 349:                      {`
` 350:                          if ((this._lsame.Run(NORM, "F")) || (this._lsame.Run(NORM, "E")))`
` 351:                          {`
` 352:                              // *`
` 353:                              // *        Find normF(A).`
` 354:                              // *`
` 355:                              SCALE = ZERO;`
` 356:                              SUM = ONE;`
` 357:                              if (this._lsame.Run(UPLO, "U"))`
` 358:                              {`
` 359:                                  for (J = 2; J <= N; J++)`
` 360:                                  {`
` 361:                                      this._dlassq.Run(J - 1, A, 1+J * LDA + o_a, 1, ref SCALE, ref SUM);`
` 362:                                  }`
` 363:                              }`
` 364:                              else`
` 365:                              {`
` 366:                                  for (J = 1; J <= N - 1; J++)`
` 367:                                  {`
` 368:                                      this._dlassq.Run(N - J, A, J + 1+J * LDA + o_a, 1, ref SCALE, ref SUM);`
` 369:                                  }`
` 370:                              }`
` 371:                              SUM = 2 * SUM;`
` 372:                              this._dlassq.Run(N, A, offset_a, LDA + 1, ref SCALE, ref SUM);`
` 373:                              VALUE = SCALE * Math.Sqrt(SUM);`
` 374:                          }`
` 375:                      }`
` 376:                  }`
` 377:              }`
` 378:              // *`
` 379:              dlansy = VALUE;`
` 380:              return dlansy;`
` 381:              // *`
` 382:              // *     End of DLANSY`
` 383:              // *`
` 384:   `
` 385:              #endregion`
` 386:   `
` 387:          }`
` 388:      }`
` 389:  }`