summaryrefslogtreecommitdiff
path: root/utils/hp2ps/Deviation.c
diff options
context:
space:
mode:
authorSimon Marlow <simonmar@microsoft.com>2006-04-07 02:05:11 +0000
committerSimon Marlow <simonmar@microsoft.com>2006-04-07 02:05:11 +0000
commit0065d5ab628975892cea1ec7303f968c3338cbe1 (patch)
tree8e2afe0ab48ee33cf95009809d67c9649573ef92 /utils/hp2ps/Deviation.c
parent28a464a75e14cece5db40f2765a29348273ff2d2 (diff)
downloadhaskell-0065d5ab628975892cea1ec7303f968c3338cbe1.tar.gz
Reorganisation of the source tree
Most of the other users of the fptools build system have migrated to Cabal, and with the move to darcs we can now flatten the source tree without losing history, so here goes. The main change is that the ghc/ subdir is gone, and most of what it contained is now at the top level. The build system now makes no pretense at being multi-project, it is just the GHC build system. No doubt this will break many things, and there will be a period of instability while we fix the dependencies. A straightforward build should work, but I haven't yet fixed binary/source distributions. Changes to the Building Guide will follow, too.
Diffstat (limited to 'utils/hp2ps/Deviation.c')
-rw-r--r--utils/hp2ps/Deviation.c139
1 files changed, 139 insertions, 0 deletions
diff --git a/utils/hp2ps/Deviation.c b/utils/hp2ps/Deviation.c
new file mode 100644
index 0000000000..ecf7faba16
--- /dev/null
+++ b/utils/hp2ps/Deviation.c
@@ -0,0 +1,139 @@
+#include "Main.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "Defines.h"
+#include "Error.h"
+#include "HpFile.h"
+#include "Utilities.h"
+
+/* own stuff */
+#include "Deviation.h"
+
+/*
+ * Reorder the identifiers in the identifier table so that the
+ * ones whose data points exhibit the mininal standard deviation
+ * come first.
+ */
+
+void
+Deviation()
+{
+ intish i;
+ intish j;
+ floatish dev;
+ struct chunk* ch;
+ int min;
+ floatish t;
+ struct entry* e;
+ floatish *averages;
+ floatish *deviations;
+
+ averages = (floatish*) xmalloc(nidents * sizeof(floatish));
+ deviations = (floatish*) xmalloc(nidents * sizeof(floatish));
+
+ /* find averages */
+
+ for (i = 0; i < nidents; i++) {
+ averages[i] = 0.0;
+ }
+
+ for (i = 0; i < nidents; i++) {
+ for (ch = identtable[i]->chk; ch; ch = ch->next) {
+ for (j = 0; j < ch->nd; j++) {
+ averages[i] += ch->d[j].value;
+ }
+ }
+ }
+
+ for (i = 0; i < nidents; i++) {
+ averages[i] /= (floatish) nsamples;
+ }
+
+ /* calculate standard deviation */
+
+ for (i = 0; i < nidents; i++) {
+ deviations[i] = 0.0;
+ }
+
+ for (i = 0; i < nidents; i++) {
+ for (ch = identtable[i]->chk; ch; ch = ch->next) {
+ for (j = 0; j < ch->nd; j++) {
+ dev = ch->d[j].value - averages[i];
+ deviations[i] += dev * dev;
+ }
+ }
+ }
+
+ for (i = 0; i < nidents; i++) {
+ deviations[i] = (floatish) sqrt ((doublish) (deviations[i] /
+ (floatish) (nsamples - 1)));
+ }
+
+
+ /* sort on basis of standard deviation */
+
+ for (i = 0; i < nidents-1; i++) {
+ min = i;
+ for (j = i+1; j < nidents; j++) {
+ if (deviations[ j ] < deviations[min]) {
+ min = j;
+ }
+ }
+
+ t = deviations[min];
+ deviations[min] = deviations[i];
+ deviations[i] = t;
+
+ e = identtable[min];
+ identtable[min] = identtable[i];
+ identtable[i] = e;
+ }
+
+ free(averages);
+ free(deviations);
+}
+
+void
+Identorder(iflag)
+ int iflag; /* a funny three-way flag ? WDP 95/03 */
+{
+ int i;
+ int j;
+ int min;
+ struct entry* e;
+
+ /* sort on basis of ident string */
+ if (iflag > 0) {
+ /* greatest at top i.e. smallest at start */
+
+ for (i = 0; i < nidents-1; i++) {
+ min = i;
+ for (j = i+1; j < nidents; j++) {
+ if (strcmp(identtable[j]->name, identtable[min]->name) < 0) {
+ min = j;
+ }
+ }
+
+ e = identtable[min];
+ identtable[min] = identtable[i];
+ identtable[i] = e;
+ }
+ } else {
+ /* smallest at top i.e. greatest at start */
+
+ for (i = 0; i < nidents-1; i++) {
+ min = i;
+ for (j = i+1; j < nidents; j++) {
+ if (strcmp(identtable[j]->name, identtable[min]->name) > 0) {
+ min = j;
+ }
+ }
+
+ e = identtable[min];
+ identtable[min] = identtable[i];
+ identtable[i] = e;
+ }
+ }
+}