home *** CD-ROM | disk | FTP | other *** search
- /*
- * This file is part of the Livermore Loops transliteration into C.
- * Copyright (C) 1991 by Martin Fouts
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 1, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- #include "types.h"
-
- Void sordid();
- Float sqrt();
-
- Void statw(result,ox,ix,x,w,n)
- Float result[], ox[], x[], w[];
- Int ix[], n;
- {
- Int k;
- Float a, r, s, t;
- Float d, u, v, h;
- for (k = 0; k < 9; k++)
- result[k] = 0.0;
- if (n <= 0) return;
- a = 0.0; s = 0.0; t = 0.0;
- for (k = 0; k < n; k++) {
- s += w[k] * x[k];
- t += w[k];
- }
- if (t != 0.0) a = s / t;
- result[0] = a;
- d = 0.0; u = 0.0;
- for (k = 0; k < n; k++)
- d += w[k] * (x[k]-a) * (x[k] - a);
- if (t != 0.0) d = d/t;
- if (d >= 0.0) u = sqrt(d);
- result[1] = u;
- u = x[0]; v = x[0];
- for (k = 1; k < n; k++) {
- if (u > x[k]) u = x[k];
- if (v < x[k]) v = x[k];
- }
- result[2] = u;
- result[3] = v;
- h = 0.0;
- for (k = 0; k < n; k++)
- if (x[k] != 0.0)
- h += w[k]/x[k];
- if (h != 0.0) h = t / h;
- result[4] = h;
- result[5] = t;
- sordid( ix, ox, x, n, (Int)1);
- r = 0.0;
- for (k = 0; k < n; k++) {
- r += w[ix[k]];
- if (r > 0.5 * t) break;
- }
- result[6] = ox[k];
- result[7] = (Float)k;
- for (k = 0; k < n; k++) {
- Float temp;
- temp = x[k] - result[6];
- if (temp < 0.0) temp = -temp;
- ox[k] = temp;
- }
- sordid(ix, ox, ox, n, (Int)1);
- r = 0.0;
- for (k = 0; k < n; k++) {
- r += w[ix[k]];
- if (r > 0.7 * t) break;
- }
- result[8] = ox[k];
- sordid(ix, ox, x, n, (Int)2);
- return;
- }
-
-