private static void sort(double[] d, double[][] z) {
        int l;
        int k;
        int j;
        int i;
        int ip1;
        double p;
        int ii;
        int n = d.length;
/* Sort by eigenvalues (descending) */
        for (l = 1; l <= n; l = 3 * l + 1) ;
        while (l > 2) {
            l = l / 3;
            k = n - l;
            for (j = 0; j < k; j++) {
                i = j;
                while (i >= 0) {
                    ip1 = i + l;
                    if (d[i] < d[ip1] || Double.isNaN(d[i])) {
                        p = d[i];
                        d[i] = d[ip1];
                        d[ip1] = p;
                        for (ii = 0; ii < n; ii++) {
                            p = z[ii][i];
                            z[ii][i] = z[ii][ip1];
                            z[ii][ip1] = p;
                        }
                        i = i - l;
                    } else
                        break;
                }
            }
        }
    }