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: /// Purpose
21: /// =======
22: ///
23: /// finds the index of element having max. absolute value.
24: /// jack dongarra, linpack, 3/11/78.
25: /// modified 3/93 to return if incx .le. 0.
26: /// modified 12/3/93, array(1) declarations changed to array(*)
27: ///</summary>
28: public class IDAMAX
29: {
30:
31:
32: #region Fields
33:
34: double DMAX = 0; int I = 0; int IX = 0;
35:
36: #endregion
37:
38: public IDAMAX()
39: {
40:
41: }
42:
43: /// <summary>
44: /// Purpose
45: /// =======
46: ///
47: /// finds the index of element having max. absolute value.
48: /// jack dongarra, linpack, 3/11/78.
49: /// modified 3/93 to return if incx .le. 0.
50: /// modified 12/3/93, array(1) declarations changed to array(*)
51: ///</summary>
52: public int Run(int N, double[] DX, int offset_dx, int INCX)
53: {
54: int idamax = 0;
55:
56: #region Array Index Correction
57:
58: int o_dx = -1 + offset_dx;
59:
60: #endregion
61:
62:
63: #region Prolog
64:
65: // * .. Scalar Arguments ..
66: // * ..
67: // * .. Array Arguments ..
68: // * ..
69: // *
70: // * Purpose
71: // * =======
72: // *
73: // * finds the index of element having max. absolute value.
74: // * jack dongarra, linpack, 3/11/78.
75: // * modified 3/93 to return if incx .le. 0.
76: // * modified 12/3/93, array(1) declarations changed to array(*)
77: // *
78: // *
79: // * .. Local Scalars ..
80: // * ..
81: // * .. Intrinsic Functions ..
82: // INTRINSIC DABS;
83: // * ..
84:
85: #endregion
86:
87:
88: #region Body
89:
90: idamax = 0;
91: if (N < 1 || INCX <= 0) return idamax;
92: idamax = 1;
93: if (N == 1) return idamax;
94: if (INCX == 1) goto LABEL20;
95: // *
96: // * code for increment not equal to 1
97: // *
98: IX = 1;
99: DMAX = Math.Abs(DX[1 + o_dx]);
100: IX = IX + INCX;
101: for (I = 2; I <= N; I++)
102: {
103: if (Math.Abs(DX[IX + o_dx]) <= DMAX) goto LABEL5;
104: idamax = I;
105: DMAX = Math.Abs(DX[IX + o_dx]);
106: LABEL5: IX = IX + INCX;
107: }
108: return idamax;
109: // *
110: // * code for increment equal to 1
111: // *
112: LABEL20: DMAX = Math.Abs(DX[1 + o_dx]);
113: for (I = 2; I <= N; I++)
114: {
115: if (Math.Abs(DX[I + o_dx]) <= DMAX) goto LABEL30;
116: idamax = I;
117: DMAX = Math.Abs(DX[I + o_dx]);
118: LABEL30:;
119: }
120: return idamax;
121:
122: #endregion
123:
124: }
125: }
126: }