NeoPZ
isorti.cpp
Go to the documentation of this file.
1 #include <stdint.h>
2 
3 /* Subroutine */
4 int isorti_ (int64_t *nl, int64_t *list, int64_t *, int64_t *key)
5 //nl, list, nk, key
6 {
7  static int64_t i, j, k, l, m;
8  static double r, t;
9  static int64_t ij, il[21], iu[21];
10  static double tt;
11  static int64_t itt;
12 
13 /* SPECIFICATIONS FOR ARGUMENTS */
14 /* SPECIFICATIONS FOR LOCAL VARIABLES */
15 /* FIRST EXECUTABLE STATEMENT */
16 /* FIND ABSOLUTE VALUES OF ARRAY A */
17 
18 /* Parameter adjustments */
19  --list;
20  --key;
21 
22 /* Function Body */
23  if (*nl <= 0)
24  {
25  return 0;
26  }
27  m = 1;
28  i = 1;
29  j = *nl;
30  r = (float) .375;
31 L10:
32  if (i == j)
33  {
34  goto L55;
35  }
36 /* L15: */
37  if (r > (float) .5898437)
38  {
39  r += (float) -.21875;
40  } else
41  {
42  r += (float) .0390625;
43  }
44 L25:
45  k = i;
46 /* SELECT A CENTRAL ELEMENT OF THE */
47 /* ARRAY AND SAVE IT IN LOCATION T */
48  ij = i + (int)((j - i) * r);
49  t = (double) key[list[ij]];
50 
51 /* IF FIRST ELEMENT OF ARRAY IS GREATER */
52 /* THAN T, INTERCHANGE WITH T */
53  if ((double) key[list[i]] > t)
54  {
55  tt = (double) list[ij];
56  list[ij] = list[i];
57  list[i] = (int)tt;
58  t = (double) key[list[ij]];
59 /* IR(IJ)=IR(I) */
60 /* IR(I)=IT */
61 /* IT=IR(IJ) */
62  }
63  l = j;
64 /* IF LAST ELEMENT OF ARRAY IS LESS THAN */
65 /* T, INTERCHANGE WITH T */
66  if ((double) key[list[j]] < t)
67  {
68  tt = (double) list[ij];
69  list[ij] = list[j];
70  list[j] = (int)tt;
71  t = (double) key[list[ij]];
72 /* IF FIRST ELEMENT OF ARRAY IS GREATER */
73 /* THAN T, INTERCHANGE WITH T */
74  if ((double) key[list[i]] > t)
75  {
76  tt = (double) list[ij];
77  list[ij] = list[i];
78  list[i] = (int)tt;
79  t = (double) key[list[ij]];
80  }
81  }
82 /* FIND AN ELEMENT IN THE SECOND HALF OF */
83 /* THE ARRAY WHICH IS SMALLER THAN T */
84 L40:
85  --l;
86  if ((double) key[list[l]] > t)
87  {
88  goto L40;
89  }
90 /* FIND AN ELEMENT IN THE FIRST HALF OF */
91 /* THE ARRAY WHICH IS GREATER THAN T */
92 L45:
93  ++k;
94  if ((double) key[list[k]] < t)
95  {
96  goto L45;
97  }
98 /* INTERCHANGE THESE ELEMENTS */
99  if (k <= l)
100  {
101  if (key[list[l]] != key[list[k]])
102  {
103  tt = (double) list[l];
104  list[l] = list[k];
105  list[k] = (int)tt;
106  }
107  goto L40;
108  }
109 /* SAVE UPPER AND LOWER SUBSCRIPTS OF */
110 /* THE ARRAY YET TO BE SORTED */
111  if (l - i > j - k)
112  {
113  il[m - 1] = i;
114  iu[m - 1] = l;
115  i = k;
116  ++m;
117  } else
118  {
119  il[m - 1] = k;
120  iu[m - 1] = j;
121  j = l;
122  ++m;
123  }
124  goto L60;
125 /* BEGIN AGAIN ON ANOTHER PORTION OF */
126 /* THE UNSORTED ARRAY */
127 L55:
128  --m;
129  if (m == 0)
130  {
131  return 0;
132  }
133  i = il[m - 1];
134  j = iu[m - 1];
135 L60:
136  if (j - i >= 11)
137  {
138  goto L25;
139  }
140  if (i == 1)
141  {
142  goto L10;
143  }
144  --i;
145 L65:
146  ++i;
147  if (i == j)
148  {
149  goto L55;
150  }
151  t = (double) key[list[i + 1]];
152  itt = list[i + 1];
153  if ((double) key[list[i]] <= t)
154  {
155  goto L65;
156  }
157  k = i;
158 L70:
159  list[k + 1] = list[k];
160  --k;
161  if (t < (double) key[list[k]])
162  {
163  goto L70;
164  }
165  list[k + 1] = itt;
166  goto L65;
167 } /* isorti_ */
int isorti_(int64_t *nl, int64_t *list, int64_t *, int64_t *key)
Definition: isorti.cpp:4
clarg::argString m("-m", "input matrix file name (text format)", "matrix.txt")